@unified-latex/unified-latex-cli 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -137,6 +137,13 @@ var schema = [
137
137
  type: "string",
138
138
  value: "<rule>"
139
139
  },
140
+ {
141
+ long: "expand-document-macro",
142
+ description: "Expand the specified macro which is defined in the document. You can use --stats to list all macros defined in the document.",
143
+ short: "d",
144
+ type: "string",
145
+ value: "<name>"
146
+ },
140
147
  {
141
148
  long: "frail",
142
149
  description: "Exit with 1 on warnings",
@@ -314,7 +321,9 @@ function options(flags, configuration) {
314
321
  ].join("\n");
315
322
  const settings = parseSettings(config.setting);
316
323
  if (config.html && config.statsJson) {
317
- throw new Error("Both --html and --stats-json were specified; only one may be used at a time.");
324
+ throw new Error(
325
+ "Both --html and --stats-json were specified; only one may be used at a time."
326
+ );
318
327
  }
319
328
  return {
320
329
  helpMessage: help,
@@ -357,6 +366,9 @@ function options(flags, configuration) {
357
366
  expandMacro: normalizeToArray(config.expandMacro).map(
358
367
  parseMacroExpansion
359
368
  ),
369
+ expandDocumentMacro: normalizeToArray(
370
+ config.expandDocumentMacro
371
+ ),
360
372
  macro: normalizeToArray(config.macro).map(
361
373
  parseMacroExpansion
362
374
  ),
@@ -620,6 +632,23 @@ var prettyPrintHtmlPlugin = function() {
620
632
  };
621
633
  };
622
634
 
635
+ // libs/macros/expand-document-macros-plugin.ts
636
+ var import_unified_latex_util_macros4 = require("@unified-latex/unified-latex-util-macros");
637
+ var import_unified_latex_util_arguments3 = require("@unified-latex/unified-latex-util-arguments");
638
+ var expandDocumentMacrosPlugin = function(options2) {
639
+ const { macros = [] } = options2 || {};
640
+ const macrosSet = new Set(macros);
641
+ return (tree) => {
642
+ const newcommands = (0, import_unified_latex_util_macros4.listNewcommands)(tree);
643
+ const macros2 = newcommands.filter((s) => macrosSet.has(s.name));
644
+ const macroInfo = Object.fromEntries(
645
+ macros2.map((m) => [m.name, { signature: m.signature }])
646
+ );
647
+ (0, import_unified_latex_util_arguments3.attachMacroArgs)(tree, macroInfo);
648
+ (0, import_unified_latex_util_macros4.expandMacrosExcludingDefinitions)(tree, macros2);
649
+ };
650
+ };
651
+
623
652
  // libs/unified-args/index.ts
624
653
  var ttyStream = Object.assign(new import_node_stream.default.Readable(), { isTTY: true });
625
654
  var exitStatus = 0;
@@ -696,6 +725,12 @@ function unifiedArgs(cliConfig) {
696
725
  { macros: config.expandMacro }
697
726
  ]);
698
727
  }
728
+ if (config.expandDocumentMacro.length > 0) {
729
+ config.plugins.push([
730
+ expandDocumentMacrosPlugin,
731
+ { macros: config.expandDocumentMacro }
732
+ ]);
733
+ }
699
734
  if (config.statsJson) {
700
735
  config.plugins.push([statsJsonPlugin]);
701
736
  }
@@ -754,11 +789,23 @@ function noop() {
754
789
  }
755
790
 
756
791
  // index.ts
792
+ var import_node_fs = __toESM(require("node:fs"), 1);
793
+ var import_meta = {};
794
+ var version = "unknown (could not read version from package.json)";
795
+ try {
796
+ const packageJson = JSON.parse(
797
+ import_node_fs.default.readFileSync(new URL("./package.json", import_meta.url), {
798
+ encoding: "utf8"
799
+ })
800
+ );
801
+ version = packageJson.version;
802
+ } catch {
803
+ }
757
804
  unifiedArgs({
758
805
  processor: processLatexViaUnified,
759
806
  name: "unified-latex",
760
807
  description: "LaTeX processor powered by unified-latex",
761
- version: "1.0.8",
808
+ version,
762
809
  extensions: ["tex"],
763
810
  ignoreName: ".unifiedlatexignore",
764
811
  packageField: "unifiedLatexConfig",
package/index.cjs.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../libs/unified-latex.ts", "../libs/unified-args/index.ts", "../libs/unified-args/options.ts", "../libs/lints/index.ts", "../libs/unified-args/schema.ts", "../libs/macros/parse-macro-expansion.ts", "../libs/stats/index.ts", "../libs/stats/enclosing-position.ts", "../libs/macros/expand-macros-plugin.ts", "../libs/macros/attach-macro-args-plugin.ts", "../libs/html/format.ts", "../index.ts"],
4
- "sourcesContent": ["import { unified } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport {\n unifiedLatexAstComplier,\n unifiedLatexFromString,\n} from \"@unified-latex/unified-latex-util-parse\";\nimport {\n unifiedLatexStringCompiler,\n PluginOptions as StringCompilerPluginOptions,\n} from \"@unified-latex/unified-latex-util-to-string\";\n/**\n * Use `unified()` to a string to an `Ast.Ast` and then pretty-print it.\n */\nexport const processLatexViaUnified = (\n options?: StringCompilerPluginOptions\n) => {\n return unified()\n .use(unifiedLatexFromString)\n .use(\n unifiedLatexStringCompiler,\n Object.assign({ pretty: true, forceNewlineEnding: true }, options)\n );\n};\n\n/**\n * Use `unified()` to a string to an `Ast.Ast` and then return it. This function\n * will not print/pretty-print the `Ast.Ast` back to a string.\n */\nexport const processLatexToAstViaUnified = () => {\n return unified().use(unifiedLatexFromString).use(unifiedLatexAstComplier);\n};\n", "// Modified from unified-args https://github.com/unifiedjs/unified-args/blob/main/lib/index.js\n// MIT License\n\nimport process from \"node:process\";\nimport stream from \"node:stream\";\nimport chalk from \"chalk\";\nimport chokidar, { FSWatcher } from \"chokidar\";\nimport {\n engine,\n Callback as EngineCallback,\n Context as EngineContext,\n} from \"unified-engine\";\nimport { unifiedLatexToHast } from \"@unified-latex/unified-latex-to-hast\";\nimport { options, Options } from \"./options\";\nimport { availableLints } from \"../lints\";\nimport { statsJsonPlugin, statsPlugin } from \"../stats\";\nimport { expandMacrosPlugin } from \"../macros/expand-macros-plugin\";\nimport { attachMacroArgsPlugin } from \"../macros/attach-macro-args-plugin\";\nimport { prettyPrintHtmlPlugin } from \"../html/format\";\n\n// Fake TTY stream.\nconst ttyStream = Object.assign(new stream.Readable(), { isTTY: true });\n\n// Exit, lazily, with the correct exit status code.\nlet exitStatus = 0;\n\nprocess.on(\"exit\", onexit);\n\n// Handle uncaught errors, such as from unexpected async behavior.\nprocess.on(\"uncaughtException\", fail);\n\n/**\n * Start the CLI.\n *\n * @param {Options} cliConfig\n */\nexport function unifiedArgs(cliConfig: Options) {\n let config: ReturnType<typeof options>;\n let watcher: FSWatcher | undefined;\n let output: boolean | string | undefined;\n\n try {\n config = options(process.argv.slice(2), cliConfig);\n } catch (error) {\n const exception = error as Error;\n return fail(exception, true);\n }\n\n if (config.help) {\n process.stdout.write(\n [\n \"Usage: \" + cliConfig.name + \" [options] [path | glob ...]\",\n \"\",\n \" \" + cliConfig.description,\n \"\",\n \"Options:\",\n \"\",\n config.helpMessage,\n \"\",\n ].join(\"\\n\"),\n noop\n );\n\n return;\n }\n\n if (config.version) {\n process.stdout.write(cliConfig.version + \"\\n\", noop);\n\n return;\n }\n\n // Modify `config` for watching.\n if (config.watch) {\n output = config.output;\n\n // Do not read from stdin(4).\n config.streamIn = ttyStream;\n\n // Do not write to stdout(4).\n config.out = false;\n\n process.stderr.write(\n chalk.bold(\"Watching...\") + \" (press CTRL+C to exit)\\n\",\n noop\n );\n\n // Prevent infinite loop if set to regeneration.\n if (output === true) {\n config.output = false;\n\n process.stderr.write(\n chalk.yellow(\"Note\") + \": Ignoring `--output` until exit.\\n\",\n noop\n );\n }\n }\n\n if (config.lints) {\n for (const [lintName, lintArgs] of Object.entries(config.lints)) {\n const lint = availableLints[lintName];\n if (!lint) {\n throw new Error(\n `Could not find lint named \"${lintName}\"; available lints are ${Object.keys(\n availableLints\n ).join(\", \")}`\n );\n }\n config.plugins.push([lint, lintArgs]);\n }\n }\n\n if (config.stats) {\n config.plugins.push([statsPlugin]);\n }\n\n if (config.macro.length > 0) {\n config.plugins.push([attachMacroArgsPlugin, { macros: config.macro }]);\n }\n\n if (config.expandMacro.length > 0) {\n config.plugins.push([\n expandMacrosPlugin,\n { macros: config.expandMacro },\n ]);\n }\n\n if (config.statsJson) {\n config.plugins.push([statsJsonPlugin]);\n }\n\n if (config.html) {\n config.plugins.push([unifiedLatexToHast]);\n config.plugins.push([prettyPrintHtmlPlugin]);\n }\n\n /**\n * Handle complete run.\n *\n * @type {EngineCallback}\n */\n const done: EngineCallback = function done(error, code, context) {\n if (error) {\n clean();\n fail(error);\n } else {\n exitStatus = code || 0;\n\n if (config.watch && !watcher && context) {\n subscribe(context);\n }\n }\n };\n\n // Clean the watcher.\n function clean() {\n if (watcher) {\n watcher.close();\n watcher = undefined;\n }\n }\n\n /**\n * Subscribe a chokidar watcher to all processed files.\n */\n function subscribe(context: EngineContext) {\n watcher = chokidar\n .watch(context.fileSet?.origins || [], {\n cwd: config.cwd,\n ignoreInitial: true,\n })\n .on(\"error\", done)\n .on(\"change\", (filePath) => {\n config.files = [filePath];\n engine(config, done);\n });\n\n process.on(\"SIGINT\", onsigint);\n\n /**\n * Handle a SIGINT.\n */\n function onsigint() {\n // Hide the `^C` in terminal.\n process.stderr.write(\"\\n\", noop);\n\n clean();\n\n // Do another process if `output` specified regeneration.\n if (output === true) {\n config.output = output;\n config.watch = false;\n engine(config, done);\n }\n }\n }\n\n // Initial run.\n engine(config, done);\n}\n\n/**\n * Print an error, optionally with stack.\n *\n * @param {Error} error\n * @param {boolean} [pretty=false]\n */\nfunction fail(error: Error, pretty?: boolean) {\n const message = String((pretty ? error : error.stack) || error);\n\n exitStatus = 1;\n\n process.stderr.write(message.trim() + \"\\n\", noop);\n}\n\nfunction onexit() {\n process.exit(exitStatus);\n}\n\nfunction noop() {}\n", "// Modified from unified-args https://github.com/unifiedjs/unified-args/blob/main/lib/index.js\n// MIT License\n\nimport table from \"text-table\";\nimport camelcase from \"camelcase\";\nimport minimist from \"minimist\";\nimport json5 from \"json5\";\nimport { fault } from \"fault\";\nimport { schema } from \"./schema\";\nimport type { Options as EngineOptions } from \"unified-engine\";\nimport type { Option } from \"./schema\";\nimport { PluggableList } from \"unified\";\nimport { availableLints } from \"../lints\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { parseMacroExpansion } from \"../macros/parse-macro-expansion\";\n\ntype RequiredEngineOptions = Required<\n Pick<\n EngineOptions,\n | \"extensions\"\n | \"ignoreName\"\n | \"packageField\"\n | \"pluginPrefix\"\n | \"processor\"\n | \"rcName\"\n >\n>;\n\ntype ArgsOptionsFields = {\n /**\n * Name of executable\n */\n name: string;\n /**\n * description of executable\n */\n description: string;\n /**\n * Version (semver) of executable\n */\n version: string;\n};\n\nexport type Options = RequiredEngineOptions &\n Pick<EngineOptions, \"cwd\"> &\n ArgsOptionsFields;\n\nconst own = {}.hasOwnProperty;\n\n/**\n * Schema for `minimist`.\n */\nconst minischema = {\n unknown: handleUnknownArgument,\n default: {} as Record<string, string | boolean | null>,\n alias: {} as Record<string, string>,\n string: [] as string[],\n boolean: [] as string[],\n};\n\nlet index = -1;\nwhile (++index < schema.length) {\n addEach(schema[index]);\n}\n\n/**\n * Parse CLI options.\n */\nexport function options(flags: string[], configuration: Options) {\n const extension = configuration.extensions[0];\n const name = configuration.name;\n const config = toCamelCase(minimist(flags, minischema));\n let index = -1;\n\n while (++index < schema.length) {\n const option = schema[index];\n if (option.type === \"string\" && config[option.long] === \"\") {\n throw fault(\"Missing value:%s\", inspect(option).join(\" \"));\n }\n }\n\n const ext = commaSeparated(config.ext as string | string[]);\n const report = reporter(config.report as string | string[]);\n const help = [\n inspectAll(schema),\n \"\",\n \"Examples:\",\n \"\",\n \" # Process `input.\" + extension + \"`\",\n \" $ \" + name + \" input.\" + extension + \" -o output.\" + extension,\n \"\",\n \" # Pipe\",\n \" $ \" + name + \" < input.\" + extension + \" > output.\" + extension,\n \"\",\n \" # Rewrite all applicable files\",\n \" $ \" + name + \" . -o\",\n \"\",\n \" # Lint files and display the lint output (but not the processed file)\",\n \" $ \" + name + \" . --lint-all --no-stdout\",\n ].join(\"\\n\");\n\n const settings = parseSettings(config.setting as string);\n\n if (config.html && config.statsJson) {\n throw new Error(\"Both --html and --stats-json were specified; only one may be used at a time.\");\n }\n\n return {\n helpMessage: help,\n cwd: configuration.cwd,\n processor: configuration.processor,\n help: config.help,\n version: config.version,\n files: config._,\n filePath: config.filePath,\n watch: config.watch,\n extensions: ext.length === 0 ? configuration.extensions : ext,\n output: config.output,\n out: config.stdout,\n tree: config.tree,\n treeIn: config.treeIn,\n treeOut: config.treeOut,\n inspect: config.inspect,\n rcName: configuration.rcName,\n packageField: configuration.packageField,\n rcPath: config.rcPath,\n detectConfig: config.config,\n settings,\n ignoreName: configuration.ignoreName,\n ignorePath: config.ignorePath,\n ignorePathResolveFrom: config.ignorePathResolveFrom,\n ignorePatterns: commaSeparated(config.ignorePattern as string),\n silentlyIgnore: config.silentlyIgnore,\n detectIgnore: config.ignore,\n pluginPrefix: configuration.pluginPrefix,\n plugins: [],\n lints: normalizeLints(config.lint as string | string[], config),\n reporter: report[0],\n reporterOptions: report[1],\n color: config.color,\n silent: config.silent,\n quiet: config.quiet,\n frail: config.frail,\n stats: config.stats,\n statsJson: config.statsJson,\n expandMacro: normalizeToArray(config.expandMacro as string).map(\n parseMacroExpansion\n ),\n macro: normalizeToArray(config.macro as string).map(\n parseMacroExpansion\n ),\n html: config.html,\n } as EngineOptions & {\n help: boolean;\n helpMessage: string;\n watch: boolean;\n version: boolean;\n lints: Record<string, Record<string, unknown> | undefined>;\n plugins: PluggableList;\n stats: boolean;\n statsJson: boolean;\n expandMacro: { name: string; signature: string; body: Ast.Node[] }[];\n macro: { name: string; signature: string }[];\n html: boolean;\n };\n}\n\nfunction addEach(option: Option) {\n const value = option.default;\n\n minischema.default[option.long] = value === undefined ? null : value;\n\n if (option.type && option.type in minischema) {\n minischema[option.type].push(option.long);\n }\n\n if (option.short) {\n minischema.alias[option.short] = option.long;\n }\n}\n\n/**\n * Parse `extensions`.\n */\nfunction commaSeparated(value: string[] | string | null | undefined): string[] {\n return normalizeToArray(value).flatMap((d) => splitOnComma(d));\n}\n\n/**\n * Parse `plugins`.\n */\nfunction plugins(value: string[] | string | null | undefined) {\n const normalized = normalizeToArray(value).map(splitOnEquals);\n let index = -1;\n const result: Record<string, Record<string, unknown> | undefined> = {};\n\n while (++index < normalized.length) {\n const value = normalized[index];\n result[value[0]] = value[1] ? parseConfig(value[1], {}) : undefined;\n }\n\n return result;\n}\n\n/**\n * Normalize the specified lints\n */\nfunction normalizeLints(\n value: string[] | string | null | undefined,\n config: Record<\"lintAll\" | \"fixAll\", unknown>\n) {\n const normalized = normalizeToArray(value).map(splitOnEquals);\n validateLintNames(normalized);\n if (config.lintAll) {\n normalized.push(...Object.keys(availableLints).map((v) => [v]));\n }\n\n const result: Record<string, Record<string, unknown> | undefined> =\n Object.fromEntries(\n normalized.map((value) => {\n let params = value[1] ? parseConfig(value[1], {}) : undefined;\n if (config.fixAll) {\n if (params) {\n Object.assign(params, { fix: true });\n } else {\n params = { fix: true };\n }\n }\n return [value[0], params];\n })\n );\n\n return result;\n}\n\n/**\n * Parse `reporter`: only one is accepted.\n */\nfunction reporter(value: string[] | string | null | undefined) {\n const all = normalizeToArray(value)\n .map(splitOnEquals)\n .map((value) => [\n value[0],\n value[1] ? parseConfig(value[1], {}) : undefined,\n ]);\n\n return all[all.length - 1] || [];\n}\n\n/**\n * Parse `settings`.\n */\nfunction parseSettings(\n value: string[] | string | null | undefined\n): Record<string, unknown> {\n const normalized = normalizeToArray(value);\n const cache: Record<string, unknown> = {};\n\n for (const value of normalized) {\n parseConfig(value, cache);\n }\n\n return cache;\n}\n\n/**\n * Parse configuration.\n */\nfunction parseConfig(\n value: string,\n cache: Record<string, unknown>\n): Record<string, unknown> {\n let flags: Record<string, unknown>;\n let flag: string;\n\n try {\n flags = toCamelCase(parseJSON(value));\n } catch (error) {\n const exception = error as Error;\n throw fault(\n \"Cannot parse `%s` as JSON: %s\",\n value,\n // Fix position\n exception.message.replace(/at(?= position)/, \"around\")\n );\n }\n\n for (flag in flags) {\n if (own.call(flags, flag)) {\n cache[flag] = flags[flag];\n }\n }\n\n return cache;\n}\n/**\n * Handle an unknown flag.\n */\nfunction validateLintNames(lints: string[][]): boolean {\n for (const lint of lints) {\n const name = lint[0];\n if (!availableLints[name]) {\n const known = Object.keys(availableLints);\n throw fault(\n \"Unknown lint rule `%s`, available rules are:\\n%s\",\n name,\n \"\\t\" + known.join(\"\\n\\t\")\n );\n }\n }\n\n return true;\n}\n\n/**\n * Handle an unknown flag.\n */\nfunction handleUnknownArgument(flag: string): boolean {\n // Not a glob.\n if (flag.charAt(0) === \"-\") {\n // Long options, always unknown.\n if (flag.charAt(1) === \"-\") {\n throw fault(\n \"Unknown option `%s`, expected:\\n%s\",\n flag,\n inspectAll(schema)\n );\n }\n\n // Short options, can be grouped.\n const found = flag.slice(1).split(\"\");\n const known = schema.filter((d) => d.short);\n const knownKeys = new Set(known.map((d) => d.short));\n let index = -1;\n\n while (++index < found.length) {\n const key = found[index];\n if (!knownKeys.has(key)) {\n throw fault(\n \"Unknown short option `-%s`, expected:\\n%s\",\n key,\n inspectAll(known)\n );\n }\n }\n }\n\n return true;\n}\n\n/**\n * Inspect all `options`.\n */\nfunction inspectAll(options: Option[]): string {\n return table(options.map((d) => inspect(d)));\n}\n\n/**\n * Inspect one `option`.\n */\nfunction inspect(option: Option): string[] {\n let description = option.description;\n let long = option.long;\n\n if (option.default === true || option.truelike) {\n description += \" (on by default)\";\n long = \"[no-]\" + long;\n }\n\n return [\n \"\",\n option.short ? \"-\" + option.short : \"\",\n \"--\" + long + (option.value ? \" \" + option.value : \"\"),\n description,\n ];\n}\n\n/**\n * Normalize `value`.\n */\nfunction normalizeToArray(\n value: string | string[] | null | undefined\n): string[] {\n if (!value) {\n return [];\n }\n\n if (typeof value === \"string\") {\n return [value];\n }\n\n return value;\n}\n\nfunction splitOnEquals(value: string) {\n return value.split(\"=\");\n}\n\nfunction splitOnComma(value: string) {\n return value.split(\",\");\n}\n\n/**\n * Transform the keys on an object to camel-case, recursively.\n */\nfunction toCamelCase(object: Record<string, unknown>): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n let key: string;\n\n for (key in object) {\n if (own.call(object, key)) {\n let value = object[key];\n\n if (value && typeof value === \"object\" && !Array.isArray(value)) {\n // @ts-expect-error: looks like an object.\n value = toCamelCase(value);\n }\n\n result[camelcase(key)] = value;\n }\n }\n\n return result;\n}\n\n/**\n * Parse a (lazy?) JSON config.\n */\nfunction parseJSON(value: string): Record<string, unknown> {\n return json5.parse(\"{\" + value + \"}\");\n}\n", "import { lints } from \"@unified-latex/unified-latex-lint\";\n\nexport const availableLints = Object.fromEntries(\n Object.values(lints).map((lint) => [\n lint.name.replace(/^unified-latex-lint:/, \"\"),\n lint,\n ])\n);\n", "// Modified from unified-args https://github.com/unifiedjs/unified-args/blob/main/lib/index.js\n// MIT License\n\nimport { availableLints } from \"../lints\";\n\nexport type Option = {\n long: string;\n description: string;\n value?: string;\n short?: string;\n default?: string | boolean;\n truelike?: boolean;\n type?: \"boolean\" | \"string\";\n};\n\nexport const schema: Option[] = [\n {\n long: \"help\",\n description: \"Output usage information\",\n short: \"h\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"version\",\n description: \"Output version number\",\n short: \"v\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"output\",\n description: \"Specify output location\",\n short: \"o\",\n value: \"[path]\",\n },\n {\n long: \"rc-path\",\n description: \"Specify configuration file\",\n short: \"r\",\n type: \"string\",\n value: \"<path>\",\n },\n {\n long: \"ignore-path\",\n description: \"Specify ignore file\",\n short: \"i\",\n type: \"string\",\n value: \"<path>\",\n },\n {\n long: \"ext\",\n description: \"Specify extensions\",\n type: \"string\",\n value: \"<extensions>\",\n },\n {\n long: \"lint\",\n description: `Lint rules to apply. Use multiple times to specify multiple lints. Available rules: ${Object.keys(\n availableLints\n ).join(\", \")}`,\n short: \"l\",\n type: \"string\",\n value: \"<rule>\",\n },\n {\n long: \"lint-all\",\n description: `Apply all available lint rules`,\n type: \"boolean\",\n default: false,\n },\n {\n long: \"fix-all\",\n description: \"Apply fixes for all applied lints\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"watch\",\n description: \"Watch for changes and reprocess\",\n short: \"w\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"macro\",\n description:\n \"Attach arguments of the specified macro (by default, unrecognized macros are parsed as having no arguments). Accepts a string of the form `\\\\newcommand{<name>}[<num args>]{<body>}` or a JSON string `{name: <name>, signature: <xparse argument signature>, body: <macro body>}`\",\n short: \"m\",\n type: \"string\",\n value: \"<rule>\",\n },\n {\n long: \"expand-macro\",\n description:\n \"Expand the specified macro. Accepts a string of the form `\\\\newcommand{<name>}[<num args>]{<body>}` or a JSON string `{name: <name>, signature: <xparse argument signature>, body: <macro body>}`\",\n short: \"e\",\n type: \"string\",\n value: \"<rule>\",\n },\n {\n long: \"frail\",\n description: \"Exit with 1 on warnings\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"tree\",\n description: \"Specify input and output as syntax tree\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"report\",\n description: \"Specify reporter\",\n type: \"string\",\n value: \"<reporter>\",\n },\n {\n long: \"file-path\",\n description: \"Specify path to process as\",\n type: \"string\",\n value: \"<path>\",\n },\n {\n long: \"ignore-path-resolve-from\",\n description:\n \"Resolve patterns in `ignore-path` from its directory or cwd\",\n type: \"string\",\n value: \"dir|cwd\",\n default: \"dir\",\n },\n {\n long: \"ignore-pattern\",\n description: \"Specify ignore patterns\",\n type: \"string\",\n value: \"<globs>\",\n },\n {\n long: \"silently-ignore\",\n description: \"Do not fail when given ignored files\",\n type: \"boolean\",\n },\n {\n long: \"tree-in\",\n description: \"Specify input as syntax tree\",\n type: \"boolean\",\n },\n {\n long: \"tree-out\",\n description: \"Output syntax tree\",\n type: \"boolean\",\n },\n {\n long: \"inspect\",\n description: \"Output formatted syntax tree\",\n type: \"boolean\",\n },\n {\n long: \"stats\",\n description: \"Show information about the processed file\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"stats-json\",\n description:\n \"Show information about the processed file and output the information as JSON\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"html\",\n description:\n \"Convert the output to HTML. Note, for math to render properly, you will need to add a library like MathJax or KaTeX to your HTMl source; you should also expand/replace any macros not recognized by the converter\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"stdout\",\n description: \"[Don't] write the processed file's contents to stdout\",\n type: \"boolean\",\n truelike: true,\n },\n {\n long: \"color\",\n description: \"Specify color in report\",\n type: \"boolean\",\n default: true,\n },\n {\n long: \"config\",\n description: \"Search for configuration files\",\n type: \"boolean\",\n default: true,\n },\n {\n long: \"ignore\",\n description: \"Search for ignore files\",\n type: \"boolean\",\n default: true,\n },\n];\n", "import json5 from \"json5\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport {\n newcommandMacroToName,\n newcommandMacroToSpec,\n newcommandMacroToSubstitutionAst,\n} from \"@unified-latex/unified-latex-util-macros\";\nimport { parse } from \"@unified-latex/unified-latex-util-parse\";\n\n/**\n * Parse a macro specification given on the command line as either a \"\\newcommand\" string\n * or a JSON object specifying `name`, `signature`, and `body`.\n */\nexport function parseMacroExpansion(def: string): {\n name: string;\n signature: string;\n body: Ast.Node[];\n} {\n if (def.startsWith(\"\\\\\")) {\n const macro = parse(def).content[0] as Ast.Macro;\n const name = newcommandMacroToName(macro);\n if (!name) {\n // If there was no name specified, it must not have been a `\\newcommand` or other recognized macro\n throw new Error(\n `Could extract macro definition from \"${def}\"; expected the macro to be defined via \\\\newcommand or similar syntax`\n );\n }\n const signature = newcommandMacroToSpec(macro);\n const body = newcommandMacroToSubstitutionAst(macro);\n\n return { name, signature, body };\n }\n // If it wasn't specified via a `\\newcommand` macro, assume it's specified as JSON\n const parsedSpec = json5.parse(def);\n if (parsedSpec.name == null || parsedSpec.body == null) {\n throw new Error(\n `Expected a \"name\" field and a \"body\" field to be defined on ${def}`\n );\n }\n parsedSpec.signature = parsedSpec.signature || \"\";\n\n return {\n name: parsedSpec.name,\n signature: parsedSpec.signature,\n body: parse(parsedSpec.body).content,\n };\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { listPackages } from \"@unified-latex/unified-latex-util-packages\";\nimport { listNewcommands } from \"@unified-latex/unified-latex-util-macros\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport { Plugin } from \"unified\";\nimport { enclosingPosition } from \"./enclosing-position\";\n\n/**\n * Plugin that reports statistics on the contents of LaTeX files.\n */\nexport const statsPlugin: Plugin<void[], Ast.Root, Ast.Root> = function () {\n return (tree, file) => {\n const packages = listPackages(tree);\n const packageNames = packages.map((s) => printRaw(s));\n if (packages.length > 0) {\n file.info(\n `Found ${\n packages.length\n } imported packages: ${packageNames.join(\", \")}`\n );\n }\n\n const newcommands = listNewcommands(tree);\n if (newcommands.length > 0) {\n file.info(\n `Found ${newcommands.length} defined commands: ${newcommands\n .map((c) => `\\\\${c.name}`)\n .join(\", \")}`,\n enclosingPosition(newcommands.map((c) => c.definition))\n );\n }\n };\n};\n\n/**\n * Plugin that reports statistics on the contents of LaTeX files and replaces the file output with a JSON\n * representation of the statistics.\n */\nexport const statsJsonPlugin: Plugin<void[], Ast.Root, string> = function () {\n this.Compiler = (tree, file) => {\n file.extname = \".json\";\n file.basename += \"-stats\";\n\n const packages = listPackages(tree).map((s) => printRaw(s));\n const newcommands = listNewcommands(tree).map((c) => ({\n name: c.name,\n signature: c.signature,\n body: printRaw(c.body),\n definition: printRaw(c.definition),\n }));\n\n return JSON.stringify({ packages, newcommands }, null, 4) + \"\\n\";\n };\n};\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\n\ntype Position = { line: number; column: number; offset: number };\n\n/**\n * Find the smallest `position` object that contains all `nodes`.\n */\nexport function enclosingPosition(nodes: Ast.Node[]): {\n start: Position;\n end: Position;\n} {\n let start: Position = { line: 1, column: 1, offset: 0 };\n let end: Position = { line: 1, column: 1, offset: 0 };\n\n for (const node of nodes) {\n if (Number(node.position?.start.offset) < Number(start.offset)) {\n start = node.position?.start as Position;\n }\n if (Number(node.position?.end.offset) > Number(end.offset)) {\n end = node.position?.end as Position;\n }\n }\n\n return { start, end };\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { expandMacros } from \"@unified-latex/unified-latex-util-macros\";\nimport { Plugin } from \"unified\";\nimport { attachMacroArgs } from \"@unified-latex/unified-latex-util-arguments\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\n\ntype PluginOptions = {\n macros: { name: string; signature: string; body: Ast.Node[] }[];\n};\n\n/**\n * Plugin that expands the specified macros.\n */\nexport const expandMacrosPlugin: Plugin<PluginOptions[], Ast.Root, Ast.Root> =\n function (options) {\n const { macros = [] } = options || {};\n const macroInfo = Object.fromEntries(\n macros.map((m) => [m.name, { signature: m.signature }])\n );\n return (tree) => {\n // We need to attach the arguments to each macro before we process it!\n attachMacroArgs(tree, macroInfo);\n expandMacros(tree, macros);\n };\n };\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { Plugin } from \"unified\";\nimport { attachMacroArgs } from \"@unified-latex/unified-latex-util-arguments\";\n\ntype PluginOptions = {\n macros: { name: string; signature: string }[];\n};\n\n/**\n * Plugin that attaches the arguments of the specified macros.\n */\nexport const attachMacroArgsPlugin: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function (options) {\n const { macros = [] } = options || {};\n const macroInfo = Object.fromEntries(\n macros.map((m) => [m.name, { signature: m.signature }])\n );\n return (tree) => {\n // We need to attach the arguments to each macro before we process it!\n attachMacroArgs(tree, macroInfo);\n };\n};\n", "import { Root } from \"hastscript/lib/core\";\nimport rehypeStringify from \"rehype-stringify\";\nimport Prettier from \"prettier\";\nimport { Plugin, unified } from \"unified\";\n\n/**\n * Plugin that pretty-prints HTML.\n */\nexport const prettyPrintHtmlPlugin: Plugin<void[], Root, string> = function () {\n const processor = unified().use(rehypeStringify);\n this.Compiler = (tree, file) => {\n file.extname = \".html\";\n\n const html = processor.stringify(tree, file);\n try {\n return Prettier.format(html, { parser: \"html\", useTabs: true });\n } catch {}\n return html;\n };\n};\n", "import { processLatexViaUnified } from \"./libs/unified-latex\";\nimport { unifiedArgs } from \"./libs/unified-args\";\n\nunifiedArgs({\n processor: processLatexViaUnified,\n name: \"unified-latex\",\n description: \"LaTeX processor powered by unified-latex\",\n version: \"1.0.8\",\n extensions: [\"tex\"],\n ignoreName: \".unifiedlatexignore\",\n packageField: \"unifiedLatexConfig\",\n rcName: \".unifiedlatexrc\",\n pluginPrefix: \"@unified-latex/\",\n});\n\n// NOTE: The docstring comment must be the last item in the index.ts file!\n/**\n * ## What is this?\n *\n * Command line interface to common `unified-latex` functions.\n *\n * ## When should I use this?\n *\n * If you want to reformat, process, or gather statistic on LaTeX files from the command line.\n *\n * ## Examples\n *\n * Reformat and pretty-print a file\n *\n * ```bash\n * unified-latex input.tex -o output.tex\n * ```\n *\n * List all commands defined via `\\newcommand` and friends (and hide the file output).\n *\n * ```bash\n * unified-latex input.tex --no-stdout --stats\n * ```\n *\n * Expand the definition of the macro `\\foo{...}`, which takes one argument.\n *\n * ```bash\n * unified-latex input.tex -e \"\\\\newcommand{foo}[1]{FOO(#1)}\"\n * ```\n *\n * View the parsed AST.\n *\n * ```bash\n * unified-latex input.tex --inspect\n * ```\n *\n * Convert the file to HTML. (Note, you will need to include and configure a library like _MathJax_ or _KaTeX_ to render\n * any math in the resulting HTML. Warnings are provided for macros that aren't recognized by the converter.)\n *\n * ```bash\n * unified-latex input.tex -o output.html --html\n * ```\n *\n * Lint all tex files in the current directory and watch for changes.\n *\n * ```bash\n * unified-latex . --no-stdout --lint-all --watch\n * ```\n */\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA,qBAAwB;AAExB,sCAGO;AACP,0CAGO;AAIA,IAAM,yBAAyB,CAClCA,aACC;AACD,aAAO,wBAAQ,EACV,IAAI,sDAAsB,EAC1B;AAAA,IACG;AAAA,IACA,OAAO,OAAO,EAAE,QAAQ,MAAM,oBAAoB,KAAK,GAAGA,QAAO;AAAA,EACrE;AACR;;;ACnBA,0BAAoB;AACpB,yBAAmB;AACnB,mBAAkB;AAClB,sBAAoC;AACpC,4BAIO;AACP,mCAAmC;;;ACTnC,wBAAkB;AAClB,uBAAsB;AACtB,sBAAqB;AACrB,IAAAC,gBAAkB;AAClB,mBAAsB;;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AAe;AAAA,IACnB,CAAC,EACA,GAAG,SAAS,IAAI,EAChB,GAAG,UAAU,CAAC,aAAa;AACxB,aAAO,QAAQ,CAAC,QAAQ;AACxB,wCAAO,QAAQ,IAAI;AAAA,IACvB,CAAC;AAEL,wBAAAH,QAAQ,GAAG,UAAU,QAAQ;AAK7B,aAAS,WAAW;AAEhB,0BAAAA,QAAQ,OAAO,MAAM,MAAM,IAAI;AAE/B,YAAM;AAGN,UAAI,WAAW,MAAM;AACjB,eAAO,SAAS;AAChB,eAAO,QAAQ;AACf,0CAAO,QAAQ,IAAI;AAAA,MACvB;AAAA,IACJ;AAAA,EACJ;AAGA,oCAAO,QAAQ,IAAI;AACvB;AAQA,SAAS,KAAK,OAAc,QAAkB;AAC1C,QAAM,UAAU,QAAQ,SAAS,QAAQ,MAAM,UAAU,KAAK;AAE9D,eAAa;AAEb,sBAAAA,QAAQ,OAAO,MAAM,QAAQ,KAAK,IAAI,MAAM,IAAI;AACpD;AAEA,SAAS,SAAS;AACd,sBAAAA,QAAQ,KAAK,UAAU;AAC3B;AAEA,SAAS,OAAO;AAAC;;;AUxNjB,YAAY;AAAA,EACR,WAAW;AAAA,EACX,MAAM;AAAA,EACN,aAAa;AAAA,EACb,SAAS;AAAA,EACT,YAAY,CAAC,KAAK;AAAA,EAClB,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,QAAQ;AAAA,EACR,cAAc;AAClB,CAAC;",
6
- "names": ["options", "import_json5", "import_unified_latex_util_parse", "json5", "minimist", "index", "value", "lints", "index", "options", "table", "camelcase", "json5", "import_unified_latex_util_macros", "import_unified_latex_util_macros", "options", "import_unified_latex_util_arguments", "options", "import_unified", "rehypeStringify", "Prettier", "stream", "process", "chalk", "done", "chokidar"]
3
+ "sources": ["../libs/unified-latex.ts", "../libs/unified-args/index.ts", "../libs/unified-args/options.ts", "../libs/lints/index.ts", "../libs/unified-args/schema.ts", "../libs/macros/parse-macro-expansion.ts", "../libs/stats/index.ts", "../libs/stats/enclosing-position.ts", "../libs/macros/expand-macros-plugin.ts", "../libs/macros/attach-macro-args-plugin.ts", "../libs/html/format.ts", "../libs/macros/expand-document-macros-plugin.ts", "../index.ts"],
4
+ "sourcesContent": ["import { unified } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport {\n unifiedLatexAstComplier,\n unifiedLatexFromString,\n} from \"@unified-latex/unified-latex-util-parse\";\nimport {\n unifiedLatexStringCompiler,\n PluginOptions as StringCompilerPluginOptions,\n} from \"@unified-latex/unified-latex-util-to-string\";\n/**\n * Use `unified()` to a string to an `Ast.Ast` and then pretty-print it.\n */\nexport const processLatexViaUnified = (\n options?: StringCompilerPluginOptions\n) => {\n return unified()\n .use(unifiedLatexFromString)\n .use(\n unifiedLatexStringCompiler,\n Object.assign({ pretty: true, forceNewlineEnding: true }, options)\n );\n};\n\n/**\n * Use `unified()` to a string to an `Ast.Ast` and then return it. This function\n * will not print/pretty-print the `Ast.Ast` back to a string.\n */\nexport const processLatexToAstViaUnified = () => {\n return unified().use(unifiedLatexFromString).use(unifiedLatexAstComplier);\n};\n", "// Modified from unified-args https://github.com/unifiedjs/unified-args/blob/main/lib/index.js\n// MIT License\n\nimport process from \"node:process\";\nimport stream from \"node:stream\";\nimport chalk from \"chalk\";\nimport chokidar, { FSWatcher } from \"chokidar\";\nimport {\n engine,\n Callback as EngineCallback,\n Context as EngineContext,\n} from \"unified-engine\";\nimport { unifiedLatexToHast } from \"@unified-latex/unified-latex-to-hast\";\nimport { options, Options } from \"./options\";\nimport { availableLints } from \"../lints\";\nimport { statsJsonPlugin, statsPlugin } from \"../stats\";\nimport { expandMacrosPlugin } from \"../macros/expand-macros-plugin\";\nimport { attachMacroArgsPlugin } from \"../macros/attach-macro-args-plugin\";\nimport { prettyPrintHtmlPlugin } from \"../html/format\";\nimport { expandDocumentMacrosPlugin } from \"../macros/expand-document-macros-plugin\";\n\n// Fake TTY stream.\nconst ttyStream = Object.assign(new stream.Readable(), { isTTY: true });\n\n// Exit, lazily, with the correct exit status code.\nlet exitStatus = 0;\n\nprocess.on(\"exit\", onexit);\n\n// Handle uncaught errors, such as from unexpected async behavior.\nprocess.on(\"uncaughtException\", fail);\n\n/**\n * Start the CLI.\n *\n * @param {Options} cliConfig\n */\nexport function unifiedArgs(cliConfig: Options) {\n let config: ReturnType<typeof options>;\n let watcher: FSWatcher | undefined;\n let output: boolean | string | undefined;\n\n try {\n config = options(process.argv.slice(2), cliConfig);\n } catch (error) {\n const exception = error as Error;\n return fail(exception, true);\n }\n\n if (config.help) {\n process.stdout.write(\n [\n \"Usage: \" + cliConfig.name + \" [options] [path | glob ...]\",\n \"\",\n \" \" + cliConfig.description,\n \"\",\n \"Options:\",\n \"\",\n config.helpMessage,\n \"\",\n ].join(\"\\n\"),\n noop\n );\n\n return;\n }\n\n if (config.version) {\n process.stdout.write(cliConfig.version + \"\\n\", noop);\n\n return;\n }\n\n // Modify `config` for watching.\n if (config.watch) {\n output = config.output;\n\n // Do not read from stdin(4).\n config.streamIn = ttyStream;\n\n // Do not write to stdout(4).\n config.out = false;\n\n process.stderr.write(\n chalk.bold(\"Watching...\") + \" (press CTRL+C to exit)\\n\",\n noop\n );\n\n // Prevent infinite loop if set to regeneration.\n if (output === true) {\n config.output = false;\n\n process.stderr.write(\n chalk.yellow(\"Note\") + \": Ignoring `--output` until exit.\\n\",\n noop\n );\n }\n }\n\n if (config.lints) {\n for (const [lintName, lintArgs] of Object.entries(config.lints)) {\n const lint = availableLints[lintName];\n if (!lint) {\n throw new Error(\n `Could not find lint named \"${lintName}\"; available lints are ${Object.keys(\n availableLints\n ).join(\", \")}`\n );\n }\n config.plugins.push([lint, lintArgs]);\n }\n }\n\n if (config.stats) {\n config.plugins.push([statsPlugin]);\n }\n\n if (config.macro.length > 0) {\n config.plugins.push([attachMacroArgsPlugin, { macros: config.macro }]);\n }\n\n if (config.expandMacro.length > 0) {\n config.plugins.push([\n expandMacrosPlugin,\n { macros: config.expandMacro },\n ]);\n }\n\n if (config.expandDocumentMacro.length > 0) {\n config.plugins.push([\n expandDocumentMacrosPlugin,\n { macros: config.expandDocumentMacro },\n ]);\n }\n\n if (config.statsJson) {\n config.plugins.push([statsJsonPlugin]);\n }\n\n if (config.html) {\n config.plugins.push([unifiedLatexToHast]);\n config.plugins.push([prettyPrintHtmlPlugin]);\n }\n\n /**\n * Handle complete run.\n *\n * @type {EngineCallback}\n */\n const done: EngineCallback = function done(error, code, context) {\n if (error) {\n clean();\n fail(error);\n } else {\n exitStatus = code || 0;\n\n if (config.watch && !watcher && context) {\n subscribe(context);\n }\n }\n };\n\n // Clean the watcher.\n function clean() {\n if (watcher) {\n watcher.close();\n watcher = undefined;\n }\n }\n\n /**\n * Subscribe a chokidar watcher to all processed files.\n */\n function subscribe(context: EngineContext) {\n watcher = chokidar\n .watch(context.fileSet?.origins || [], {\n cwd: config.cwd,\n ignoreInitial: true,\n })\n .on(\"error\", done)\n .on(\"change\", (filePath) => {\n config.files = [filePath];\n engine(config, done);\n });\n\n process.on(\"SIGINT\", onsigint);\n\n /**\n * Handle a SIGINT.\n */\n function onsigint() {\n // Hide the `^C` in terminal.\n process.stderr.write(\"\\n\", noop);\n\n clean();\n\n // Do another process if `output` specified regeneration.\n if (output === true) {\n config.output = output;\n config.watch = false;\n engine(config, done);\n }\n }\n }\n\n // Initial run.\n engine(config, done);\n}\n\n/**\n * Print an error, optionally with stack.\n *\n * @param {Error} error\n * @param {boolean} [pretty=false]\n */\nfunction fail(error: Error, pretty?: boolean) {\n const message = String((pretty ? error : error.stack) || error);\n\n exitStatus = 1;\n\n process.stderr.write(message.trim() + \"\\n\", noop);\n}\n\nfunction onexit() {\n process.exit(exitStatus);\n}\n\nfunction noop() {}\n", "// Modified from unified-args https://github.com/unifiedjs/unified-args/blob/main/lib/index.js\n// MIT License\n\nimport table from \"text-table\";\nimport camelcase from \"camelcase\";\nimport minimist from \"minimist\";\nimport json5 from \"json5\";\nimport { fault } from \"fault\";\nimport { schema } from \"./schema\";\nimport type { Options as EngineOptions } from \"unified-engine\";\nimport type { Option } from \"./schema\";\nimport { PluggableList } from \"unified\";\nimport { availableLints } from \"../lints\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { parseMacroExpansion } from \"../macros/parse-macro-expansion\";\n\ntype RequiredEngineOptions = Required<\n Pick<\n EngineOptions,\n | \"extensions\"\n | \"ignoreName\"\n | \"packageField\"\n | \"pluginPrefix\"\n | \"processor\"\n | \"rcName\"\n >\n>;\n\ntype ArgsOptionsFields = {\n /**\n * Name of executable\n */\n name: string;\n /**\n * description of executable\n */\n description: string;\n /**\n * Version (semver) of executable\n */\n version: string;\n};\n\nexport type Options = RequiredEngineOptions &\n Pick<EngineOptions, \"cwd\"> &\n ArgsOptionsFields;\n\nconst own = {}.hasOwnProperty;\n\n/**\n * Schema for `minimist`.\n */\nconst minischema = {\n unknown: handleUnknownArgument,\n default: {} as Record<string, string | boolean | null>,\n alias: {} as Record<string, string>,\n string: [] as string[],\n boolean: [] as string[],\n};\n\nlet index = -1;\nwhile (++index < schema.length) {\n addEach(schema[index]);\n}\n\n/**\n * Parse CLI options.\n */\nexport function options(flags: string[], configuration: Options) {\n const extension = configuration.extensions[0];\n const name = configuration.name;\n const config = toCamelCase(minimist(flags, minischema));\n let index = -1;\n\n while (++index < schema.length) {\n const option = schema[index];\n if (option.type === \"string\" && config[option.long] === \"\") {\n throw fault(\"Missing value:%s\", inspect(option).join(\" \"));\n }\n }\n\n const ext = commaSeparated(config.ext as string | string[]);\n const report = reporter(config.report as string | string[]);\n const help = [\n inspectAll(schema),\n \"\",\n \"Examples:\",\n \"\",\n \" # Process `input.\" + extension + \"`\",\n \" $ \" + name + \" input.\" + extension + \" -o output.\" + extension,\n \"\",\n \" # Pipe\",\n \" $ \" + name + \" < input.\" + extension + \" > output.\" + extension,\n \"\",\n \" # Rewrite all applicable files\",\n \" $ \" + name + \" . -o\",\n \"\",\n \" # Lint files and display the lint output (but not the processed file)\",\n \" $ \" + name + \" . --lint-all --no-stdout\",\n ].join(\"\\n\");\n\n const settings = parseSettings(config.setting as string);\n\n if (config.html && config.statsJson) {\n throw new Error(\n \"Both --html and --stats-json were specified; only one may be used at a time.\"\n );\n }\n\n return {\n helpMessage: help,\n cwd: configuration.cwd,\n processor: configuration.processor,\n help: config.help,\n version: config.version,\n files: config._,\n filePath: config.filePath,\n watch: config.watch,\n extensions: ext.length === 0 ? configuration.extensions : ext,\n output: config.output,\n out: config.stdout,\n tree: config.tree,\n treeIn: config.treeIn,\n treeOut: config.treeOut,\n inspect: config.inspect,\n rcName: configuration.rcName,\n packageField: configuration.packageField,\n rcPath: config.rcPath,\n detectConfig: config.config,\n settings,\n ignoreName: configuration.ignoreName,\n ignorePath: config.ignorePath,\n ignorePathResolveFrom: config.ignorePathResolveFrom,\n ignorePatterns: commaSeparated(config.ignorePattern as string),\n silentlyIgnore: config.silentlyIgnore,\n detectIgnore: config.ignore,\n pluginPrefix: configuration.pluginPrefix,\n plugins: [],\n lints: normalizeLints(config.lint as string | string[], config),\n reporter: report[0],\n reporterOptions: report[1],\n color: config.color,\n silent: config.silent,\n quiet: config.quiet,\n frail: config.frail,\n stats: config.stats,\n statsJson: config.statsJson,\n expandMacro: normalizeToArray(config.expandMacro as string).map(\n parseMacroExpansion\n ),\n expandDocumentMacro: normalizeToArray(\n config.expandDocumentMacro as string\n ),\n macro: normalizeToArray(config.macro as string).map(\n parseMacroExpansion\n ),\n html: config.html,\n } as EngineOptions & {\n help: boolean;\n helpMessage: string;\n watch: boolean;\n version: boolean;\n lints: Record<string, Record<string, unknown> | undefined>;\n plugins: PluggableList;\n stats: boolean;\n statsJson: boolean;\n expandMacro: { name: string; signature: string; body: Ast.Node[] }[];\n expandDocumentMacro: string[];\n macro: { name: string; signature: string }[];\n html: boolean;\n };\n}\n\nfunction addEach(option: Option) {\n const value = option.default;\n\n minischema.default[option.long] = value === undefined ? null : value;\n\n if (option.type && option.type in minischema) {\n minischema[option.type].push(option.long);\n }\n\n if (option.short) {\n minischema.alias[option.short] = option.long;\n }\n}\n\n/**\n * Parse `extensions`.\n */\nfunction commaSeparated(value: string[] | string | null | undefined): string[] {\n return normalizeToArray(value).flatMap((d) => splitOnComma(d));\n}\n\n/**\n * Parse `plugins`.\n */\nfunction plugins(value: string[] | string | null | undefined) {\n const normalized = normalizeToArray(value).map(splitOnEquals);\n let index = -1;\n const result: Record<string, Record<string, unknown> | undefined> = {};\n\n while (++index < normalized.length) {\n const value = normalized[index];\n result[value[0]] = value[1] ? parseConfig(value[1], {}) : undefined;\n }\n\n return result;\n}\n\n/**\n * Normalize the specified lints\n */\nfunction normalizeLints(\n value: string[] | string | null | undefined,\n config: Record<\"lintAll\" | \"fixAll\", unknown>\n) {\n const normalized = normalizeToArray(value).map(splitOnEquals);\n validateLintNames(normalized);\n if (config.lintAll) {\n normalized.push(...Object.keys(availableLints).map((v) => [v]));\n }\n\n const result: Record<string, Record<string, unknown> | undefined> =\n Object.fromEntries(\n normalized.map((value) => {\n let params = value[1] ? parseConfig(value[1], {}) : undefined;\n if (config.fixAll) {\n if (params) {\n Object.assign(params, { fix: true });\n } else {\n params = { fix: true };\n }\n }\n return [value[0], params];\n })\n );\n\n return result;\n}\n\n/**\n * Parse `reporter`: only one is accepted.\n */\nfunction reporter(value: string[] | string | null | undefined) {\n const all = normalizeToArray(value)\n .map(splitOnEquals)\n .map((value) => [\n value[0],\n value[1] ? parseConfig(value[1], {}) : undefined,\n ]);\n\n return all[all.length - 1] || [];\n}\n\n/**\n * Parse `settings`.\n */\nfunction parseSettings(\n value: string[] | string | null | undefined\n): Record<string, unknown> {\n const normalized = normalizeToArray(value);\n const cache: Record<string, unknown> = {};\n\n for (const value of normalized) {\n parseConfig(value, cache);\n }\n\n return cache;\n}\n\n/**\n * Parse configuration.\n */\nfunction parseConfig(\n value: string,\n cache: Record<string, unknown>\n): Record<string, unknown> {\n let flags: Record<string, unknown>;\n let flag: string;\n\n try {\n flags = toCamelCase(parseJSON(value));\n } catch (error) {\n const exception = error as Error;\n throw fault(\n \"Cannot parse `%s` as JSON: %s\",\n value,\n // Fix position\n exception.message.replace(/at(?= position)/, \"around\")\n );\n }\n\n for (flag in flags) {\n if (own.call(flags, flag)) {\n cache[flag] = flags[flag];\n }\n }\n\n return cache;\n}\n/**\n * Handle an unknown flag.\n */\nfunction validateLintNames(lints: string[][]): boolean {\n for (const lint of lints) {\n const name = lint[0];\n if (!availableLints[name]) {\n const known = Object.keys(availableLints);\n throw fault(\n \"Unknown lint rule `%s`, available rules are:\\n%s\",\n name,\n \"\\t\" + known.join(\"\\n\\t\")\n );\n }\n }\n\n return true;\n}\n\n/**\n * Handle an unknown flag.\n */\nfunction handleUnknownArgument(flag: string): boolean {\n // Not a glob.\n if (flag.charAt(0) === \"-\") {\n // Long options, always unknown.\n if (flag.charAt(1) === \"-\") {\n throw fault(\n \"Unknown option `%s`, expected:\\n%s\",\n flag,\n inspectAll(schema)\n );\n }\n\n // Short options, can be grouped.\n const found = flag.slice(1).split(\"\");\n const known = schema.filter((d) => d.short);\n const knownKeys = new Set(known.map((d) => d.short));\n let index = -1;\n\n while (++index < found.length) {\n const key = found[index];\n if (!knownKeys.has(key)) {\n throw fault(\n \"Unknown short option `-%s`, expected:\\n%s\",\n key,\n inspectAll(known)\n );\n }\n }\n }\n\n return true;\n}\n\n/**\n * Inspect all `options`.\n */\nfunction inspectAll(options: Option[]): string {\n return table(options.map((d) => inspect(d)));\n}\n\n/**\n * Inspect one `option`.\n */\nfunction inspect(option: Option): string[] {\n let description = option.description;\n let long = option.long;\n\n if (option.default === true || option.truelike) {\n description += \" (on by default)\";\n long = \"[no-]\" + long;\n }\n\n return [\n \"\",\n option.short ? \"-\" + option.short : \"\",\n \"--\" + long + (option.value ? \" \" + option.value : \"\"),\n description,\n ];\n}\n\n/**\n * Normalize `value`.\n */\nfunction normalizeToArray(\n value: string | string[] | null | undefined\n): string[] {\n if (!value) {\n return [];\n }\n\n if (typeof value === \"string\") {\n return [value];\n }\n\n return value;\n}\n\nfunction splitOnEquals(value: string) {\n return value.split(\"=\");\n}\n\nfunction splitOnComma(value: string) {\n return value.split(\",\");\n}\n\n/**\n * Transform the keys on an object to camel-case, recursively.\n */\nfunction toCamelCase(object: Record<string, unknown>): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n let key: string;\n\n for (key in object) {\n if (own.call(object, key)) {\n let value = object[key];\n\n if (value && typeof value === \"object\" && !Array.isArray(value)) {\n // @ts-expect-error: looks like an object.\n value = toCamelCase(value);\n }\n\n result[camelcase(key)] = value;\n }\n }\n\n return result;\n}\n\n/**\n * Parse a (lazy?) JSON config.\n */\nfunction parseJSON(value: string): Record<string, unknown> {\n return json5.parse(\"{\" + value + \"}\");\n}\n", "import { lints } from \"@unified-latex/unified-latex-lint\";\n\nexport const availableLints = Object.fromEntries(\n Object.values(lints).map((lint) => [\n lint.name.replace(/^unified-latex-lint:/, \"\"),\n lint,\n ])\n);\n", "// Modified from unified-args https://github.com/unifiedjs/unified-args/blob/main/lib/index.js\n// MIT License\n\nimport { availableLints } from \"../lints\";\n\nexport type Option = {\n long: string;\n description: string;\n value?: string;\n short?: string;\n default?: string | boolean;\n truelike?: boolean;\n type?: \"boolean\" | \"string\";\n};\n\nexport const schema: Option[] = [\n {\n long: \"help\",\n description: \"Output usage information\",\n short: \"h\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"version\",\n description: \"Output version number\",\n short: \"v\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"output\",\n description: \"Specify output location\",\n short: \"o\",\n value: \"[path]\",\n },\n {\n long: \"rc-path\",\n description: \"Specify configuration file\",\n short: \"r\",\n type: \"string\",\n value: \"<path>\",\n },\n {\n long: \"ignore-path\",\n description: \"Specify ignore file\",\n short: \"i\",\n type: \"string\",\n value: \"<path>\",\n },\n {\n long: \"ext\",\n description: \"Specify extensions\",\n type: \"string\",\n value: \"<extensions>\",\n },\n {\n long: \"lint\",\n description: `Lint rules to apply. Use multiple times to specify multiple lints. Available rules: ${Object.keys(\n availableLints\n ).join(\", \")}`,\n short: \"l\",\n type: \"string\",\n value: \"<rule>\",\n },\n {\n long: \"lint-all\",\n description: `Apply all available lint rules`,\n type: \"boolean\",\n default: false,\n },\n {\n long: \"fix-all\",\n description: \"Apply fixes for all applied lints\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"watch\",\n description: \"Watch for changes and reprocess\",\n short: \"w\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"macro\",\n description:\n \"Attach arguments of the specified macro (by default, unrecognized macros are parsed as having no arguments). Accepts a string of the form `\\\\newcommand{<name>}[<num args>]{<body>}` or a JSON string `{name: <name>, signature: <xparse argument signature>, body: <macro body>}`\",\n short: \"m\",\n type: \"string\",\n value: \"<rule>\",\n },\n {\n long: \"expand-macro\",\n description:\n \"Expand the specified macro. Accepts a string of the form `\\\\newcommand{<name>}[<num args>]{<body>}` or a JSON string `{name: <name>, signature: <xparse argument signature>, body: <macro body>}`\",\n short: \"e\",\n type: \"string\",\n value: \"<rule>\",\n },\n {\n long: \"expand-document-macro\",\n description:\n \"Expand the specified macro which is defined in the document. You can use --stats to list all macros defined in the document.\",\n short: \"d\",\n type: \"string\",\n value: \"<name>\"\n },\n {\n long: \"frail\",\n description: \"Exit with 1 on warnings\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"tree\",\n description: \"Specify input and output as syntax tree\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"report\",\n description: \"Specify reporter\",\n type: \"string\",\n value: \"<reporter>\",\n },\n {\n long: \"file-path\",\n description: \"Specify path to process as\",\n type: \"string\",\n value: \"<path>\",\n },\n {\n long: \"ignore-path-resolve-from\",\n description:\n \"Resolve patterns in `ignore-path` from its directory or cwd\",\n type: \"string\",\n value: \"dir|cwd\",\n default: \"dir\",\n },\n {\n long: \"ignore-pattern\",\n description: \"Specify ignore patterns\",\n type: \"string\",\n value: \"<globs>\",\n },\n {\n long: \"silently-ignore\",\n description: \"Do not fail when given ignored files\",\n type: \"boolean\",\n },\n {\n long: \"tree-in\",\n description: \"Specify input as syntax tree\",\n type: \"boolean\",\n },\n {\n long: \"tree-out\",\n description: \"Output syntax tree\",\n type: \"boolean\",\n },\n {\n long: \"inspect\",\n description: \"Output formatted syntax tree\",\n type: \"boolean\",\n },\n {\n long: \"stats\",\n description: \"Show information about the processed file\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"stats-json\",\n description:\n \"Show information about the processed file and output the information as JSON\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"html\",\n description:\n \"Convert the output to HTML. Note, for math to render properly, you will need to add a library like MathJax or KaTeX to your HTMl source; you should also expand/replace any macros not recognized by the converter\",\n type: \"boolean\",\n default: false,\n },\n {\n long: \"stdout\",\n description: \"[Don't] write the processed file's contents to stdout\",\n type: \"boolean\",\n truelike: true,\n },\n {\n long: \"color\",\n description: \"Specify color in report\",\n type: \"boolean\",\n default: true,\n },\n {\n long: \"config\",\n description: \"Search for configuration files\",\n type: \"boolean\",\n default: true,\n },\n {\n long: \"ignore\",\n description: \"Search for ignore files\",\n type: \"boolean\",\n default: true,\n },\n];\n", "import json5 from \"json5\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport {\n newcommandMacroToName,\n newcommandMacroToSpec,\n newcommandMacroToSubstitutionAst,\n} from \"@unified-latex/unified-latex-util-macros\";\nimport { parse } from \"@unified-latex/unified-latex-util-parse\";\n\n/**\n * Parse a macro specification given on the command line as either a \"\\newcommand\" string\n * or a JSON object specifying `name`, `signature`, and `body`.\n */\nexport function parseMacroExpansion(def: string): {\n name: string;\n signature: string;\n body: Ast.Node[];\n} {\n if (def.startsWith(\"\\\\\")) {\n const macro = parse(def).content[0] as Ast.Macro;\n const name = newcommandMacroToName(macro);\n if (!name) {\n // If there was no name specified, it must not have been a `\\newcommand` or other recognized macro\n throw new Error(\n `Could extract macro definition from \"${def}\"; expected the macro to be defined via \\\\newcommand or similar syntax`\n );\n }\n const signature = newcommandMacroToSpec(macro);\n const body = newcommandMacroToSubstitutionAst(macro);\n\n return { name, signature, body };\n }\n // If it wasn't specified via a `\\newcommand` macro, assume it's specified as JSON\n const parsedSpec = json5.parse(def);\n if (parsedSpec.name == null || parsedSpec.body == null) {\n throw new Error(\n `Expected a \"name\" field and a \"body\" field to be defined on ${def}`\n );\n }\n parsedSpec.signature = parsedSpec.signature || \"\";\n\n return {\n name: parsedSpec.name,\n signature: parsedSpec.signature,\n body: parse(parsedSpec.body).content,\n };\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { listPackages } from \"@unified-latex/unified-latex-util-packages\";\nimport { listNewcommands } from \"@unified-latex/unified-latex-util-macros\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport { Plugin } from \"unified\";\nimport { enclosingPosition } from \"./enclosing-position\";\n\n/**\n * Plugin that reports statistics on the contents of LaTeX files.\n */\nexport const statsPlugin: Plugin<void[], Ast.Root, Ast.Root> = function () {\n return (tree, file) => {\n const packages = listPackages(tree);\n const packageNames = packages.map((s) => printRaw(s));\n if (packages.length > 0) {\n file.info(\n `Found ${\n packages.length\n } imported packages: ${packageNames.join(\", \")}`\n );\n }\n\n const newcommands = listNewcommands(tree);\n if (newcommands.length > 0) {\n file.info(\n `Found ${newcommands.length} defined commands: ${newcommands\n .map((c) => `\\\\${c.name}`)\n .join(\", \")}`,\n enclosingPosition(newcommands.map((c) => c.definition))\n );\n }\n };\n};\n\n/**\n * Plugin that reports statistics on the contents of LaTeX files and replaces the file output with a JSON\n * representation of the statistics.\n */\nexport const statsJsonPlugin: Plugin<void[], Ast.Root, string> = function () {\n this.Compiler = (tree, file) => {\n file.extname = \".json\";\n file.basename += \"-stats\";\n\n const packages = listPackages(tree).map((s) => printRaw(s));\n const newcommands = listNewcommands(tree).map((c) => ({\n name: c.name,\n signature: c.signature,\n body: printRaw(c.body),\n definition: printRaw(c.definition),\n }));\n\n return JSON.stringify({ packages, newcommands }, null, 4) + \"\\n\";\n };\n};\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\n\ntype Position = { line: number; column: number; offset: number };\n\n/**\n * Find the smallest `position` object that contains all `nodes`.\n */\nexport function enclosingPosition(nodes: Ast.Node[]): {\n start: Position;\n end: Position;\n} {\n let start: Position = { line: 1, column: 1, offset: 0 };\n let end: Position = { line: 1, column: 1, offset: 0 };\n\n for (const node of nodes) {\n if (Number(node.position?.start.offset) < Number(start.offset)) {\n start = node.position?.start as Position;\n }\n if (Number(node.position?.end.offset) > Number(end.offset)) {\n end = node.position?.end as Position;\n }\n }\n\n return { start, end };\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport {\n expandMacros,\n expandMacrosExcludingDefinitions,\n} from \"@unified-latex/unified-latex-util-macros\";\nimport { Plugin } from \"unified\";\nimport { attachMacroArgs } from \"@unified-latex/unified-latex-util-arguments\";\n\ntype PluginOptions = {\n macros: { name: string; signature: string; body: Ast.Node[] }[];\n};\n\n/**\n * Plugin that expands the specified macros.\n */\nexport const expandMacrosPlugin: Plugin<PluginOptions[], Ast.Root, Ast.Root> =\n function (options) {\n const { macros = [] } = options || {};\n const macroInfo = Object.fromEntries(\n macros.map((m) => [m.name, { signature: m.signature }])\n );\n return (tree) => {\n // We need to attach the arguments to each macro before we process it!\n attachMacroArgs(tree, macroInfo);\n expandMacros(tree, macros);\n };\n };\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { Plugin } from \"unified\";\nimport { attachMacroArgs } from \"@unified-latex/unified-latex-util-arguments\";\n\ntype PluginOptions = {\n macros: { name: string; signature: string }[];\n};\n\n/**\n * Plugin that attaches the arguments of the specified macros.\n */\nexport const attachMacroArgsPlugin: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function (options) {\n const { macros = [] } = options || {};\n const macroInfo = Object.fromEntries(\n macros.map((m) => [m.name, { signature: m.signature }])\n );\n return (tree) => {\n // We need to attach the arguments to each macro before we process it!\n attachMacroArgs(tree, macroInfo);\n };\n};\n", "import { Root } from \"hastscript/lib/core\";\nimport rehypeStringify from \"rehype-stringify\";\nimport Prettier from \"prettier\";\nimport { Plugin, unified } from \"unified\";\n\n/**\n * Plugin that pretty-prints HTML.\n */\nexport const prettyPrintHtmlPlugin: Plugin<void[], Root, string> = function () {\n const processor = unified().use(rehypeStringify);\n this.Compiler = (tree, file) => {\n file.extname = \".html\";\n\n const html = processor.stringify(tree, file);\n try {\n return Prettier.format(html, { parser: \"html\", useTabs: true });\n } catch {}\n return html;\n };\n};\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport {\n expandMacros,\n expandMacrosExcludingDefinitions,\n listNewcommands,\n} from \"@unified-latex/unified-latex-util-macros\";\nimport { Plugin } from \"unified\";\nimport { attachMacroArgs } from \"@unified-latex/unified-latex-util-arguments\";\n\ntype PluginOptions = {\n macros?: string[];\n};\n\n/**\n * Plugin that expands the specified macros by name. These macros must be defined in the document via\n * `\\newcommand...` or equivalent.\n */\nexport const expandDocumentMacrosPlugin: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function (options) {\n const { macros = [] } = options || {};\n const macrosSet = new Set(macros);\n\n return (tree) => {\n const newcommands = listNewcommands(tree);\n const macros = newcommands.filter((s) => macrosSet.has(s.name));\n\n const macroInfo = Object.fromEntries(\n macros.map((m) => [m.name, { signature: m.signature }])\n );\n // We need to attach the arguments to each macro before we process it!\n attachMacroArgs(tree, macroInfo);\n expandMacrosExcludingDefinitions(tree, macros);\n };\n};\n", "import { processLatexViaUnified } from \"./libs/unified-latex\";\nimport { unifiedArgs } from \"./libs/unified-args\";\nimport fs from \"node:fs\";\n\nlet version = \"unknown (could not read version from package.json)\";\ntry {\n // Read the version dynamically on startup\n type PackageJson = { version: string };\n const packageJson: PackageJson = JSON.parse(\n fs.readFileSync(new URL(\"./package.json\", import.meta.url), {\n encoding: \"utf8\",\n })\n );\n version = packageJson.version;\n} catch {}\n\nunifiedArgs({\n processor: processLatexViaUnified,\n name: \"unified-latex\",\n description: \"LaTeX processor powered by unified-latex\",\n version,\n extensions: [\"tex\"],\n ignoreName: \".unifiedlatexignore\",\n packageField: \"unifiedLatexConfig\",\n rcName: \".unifiedlatexrc\",\n pluginPrefix: \"@unified-latex/\",\n});\n\n// NOTE: The docstring comment must be the last item in the index.ts file!\n/**\n * ## What is this?\n *\n * Command line interface to common `unified-latex` functions.\n *\n * ## When should I use this?\n *\n * If you want to reformat, process, or gather statistic on LaTeX files from the command line.\n *\n * ## Examples\n *\n * Reformat and pretty-print a file\n *\n * ```bash\n * unified-latex input.tex -o output.tex\n * ```\n *\n * List all commands defined via `\\newcommand` and friends (and hide the file output).\n *\n * ```bash\n * unified-latex input.tex --no-stdout --stats\n * ```\n *\n * Expand the definition of the macro `\\foo{...}`, which takes one argument.\n *\n * ```bash\n * unified-latex input.tex -e \"\\\\newcommand{foo}[1]{FOO(#1)}\"\n * ```\n *\n * View the parsed AST.\n *\n * ```bash\n * unified-latex input.tex --inspect\n * ```\n *\n * Convert the file to HTML. (Note, you will need to include and configure a library like _MathJax_ or _KaTeX_ to render\n * any math in the resulting HTML. Warnings are provided for macros that aren't recognized by the converter.)\n *\n * ```bash\n * unified-latex input.tex -o output.html --html\n * ```\n *\n * Lint all tex files in the current directory and watch for changes.\n *\n * ```bash\n * unified-latex . --no-stdout --lint-all --watch\n * ```\n */\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;AAAA,qBAAwB;AAExB,sCAGO;AACP,0CAGO;AAIA,IAAM,yBAAyB,CAClCA,aACC;AACD,aAAO,wBAAQ,EACV,IAAI,sDAAsB,EAC1B;AAAA,IACG;AAAA,IACA,OAAO,OAAO,EAAE,QAAQ,MAAM,oBAAoB,KAAK,GAAGA,QAAO;AAAA,EACrE;AACR;;;ACnBA,0BAAoB;AACpB,yBAAmB;AACnB,mBAAkB;AAClB,sBAAoC;AACpC,4BAIO;AACP,mCAAmC;;;ACTnC,wBAAkB;AAClB,uBAAsB;AACtB,sBAAqB;AACrB,IAAAC,gBAAkB;AAClB,mBAAsB;;;ACPtB,gCAAsB;AAEf,IAAM,iBAAiB,OAAO;AA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UAAU,QAAQ,SAAS,QAAQ,MAAM,UAAU,KAAK;AAE9D,eAAa;AAEb,sBAAAA,QAAQ,OAAO,MAAM,QAAQ,KAAK,IAAI,MAAM,IAAI;AACpD;AAEA,SAAS,SAAS;AACd,sBAAAA,QAAQ,KAAK,UAAU;AAC3B;AAEA,SAAS,OAAO;AAAC;;;AWjOjB,qBAAe;AAFf;AAIA,IAAI,UAAU;AACd,IAAI;AAGA,QAAM,cAA2B,KAAK;AAAA,IAClC,eAAAI,QAAG,aAAa,IAAI,IAAI,kBAAkB,YAAY,GAAG,GAAG;AAAA,MACxD,UAAU;AAAA,IACd,CAAC;AAAA,EACL;AACA,YAAU,YAAY;AAC1B,QAAE;AAAO;AAET,YAAY;AAAA,EACR,WAAW;AAAA,EACX,MAAM;AAAA,EACN,aAAa;AAAA,EACb;AAAA,EACA,YAAY,CAAC,KAAK;AAAA,EAClB,YAAY;AAAA,EACZ,cAAc;AAAA,EACd,QAAQ;AAAA,EACR,cAAc;AAClB,CAAC;",
6
+ "names": ["options", "import_json5", "import_unified_latex_util_parse", "json5", "minimist", "index", "value", "lints", "index", "options", "table", "camelcase", "json5", "import_unified_latex_util_macros", "import_unified_latex_util_macros", "options", "import_unified_latex_util_arguments", "options", "import_unified", "rehypeStringify", "Prettier", "import_unified_latex_util_macros", "import_unified_latex_util_arguments", "options", "macros", "stream", "process", "chalk", "done", "chokidar", "fs"]
7
7
  }
package/index.js CHANGED
@@ -124,6 +124,13 @@ var schema = [
124
124
  type: "string",
125
125
  value: "<rule>"
126
126
  },
127
+ {
128
+ long: "expand-document-macro",
129
+ description: "Expand the specified macro which is defined in the document. You can use --stats to list all macros defined in the document.",
130
+ short: "d",
131
+ type: "string",
132
+ value: "<name>"
133
+ },
127
134
  {
128
135
  long: "frail",
129
136
  description: "Exit with 1 on warnings",
@@ -305,7 +312,9 @@ function options(flags, configuration) {
305
312
  ].join("\n");
306
313
  const settings = parseSettings(config.setting);
307
314
  if (config.html && config.statsJson) {
308
- throw new Error("Both --html and --stats-json were specified; only one may be used at a time.");
315
+ throw new Error(
316
+ "Both --html and --stats-json were specified; only one may be used at a time."
317
+ );
309
318
  }
310
319
  return {
311
320
  helpMessage: help,
@@ -348,6 +357,9 @@ function options(flags, configuration) {
348
357
  expandMacro: normalizeToArray(config.expandMacro).map(
349
358
  parseMacroExpansion
350
359
  ),
360
+ expandDocumentMacro: normalizeToArray(
361
+ config.expandDocumentMacro
362
+ ),
351
363
  macro: normalizeToArray(config.macro).map(
352
364
  parseMacroExpansion
353
365
  ),
@@ -569,7 +581,9 @@ var statsJsonPlugin = function() {
569
581
  };
570
582
 
571
583
  // libs/macros/expand-macros-plugin.ts
572
- import { expandMacros } from "@unified-latex/unified-latex-util-macros";
584
+ import {
585
+ expandMacros
586
+ } from "@unified-latex/unified-latex-util-macros";
573
587
  import { attachMacroArgs } from "@unified-latex/unified-latex-util-arguments";
574
588
  var expandMacrosPlugin = function(options2) {
575
589
  const { macros = [] } = options2 || {};
@@ -611,6 +625,26 @@ var prettyPrintHtmlPlugin = function() {
611
625
  };
612
626
  };
613
627
 
628
+ // libs/macros/expand-document-macros-plugin.ts
629
+ import {
630
+ expandMacrosExcludingDefinitions as expandMacrosExcludingDefinitions2,
631
+ listNewcommands as listNewcommands2
632
+ } from "@unified-latex/unified-latex-util-macros";
633
+ import { attachMacroArgs as attachMacroArgs3 } from "@unified-latex/unified-latex-util-arguments";
634
+ var expandDocumentMacrosPlugin = function(options2) {
635
+ const { macros = [] } = options2 || {};
636
+ const macrosSet = new Set(macros);
637
+ return (tree) => {
638
+ const newcommands = listNewcommands2(tree);
639
+ const macros2 = newcommands.filter((s) => macrosSet.has(s.name));
640
+ const macroInfo = Object.fromEntries(
641
+ macros2.map((m) => [m.name, { signature: m.signature }])
642
+ );
643
+ attachMacroArgs3(tree, macroInfo);
644
+ expandMacrosExcludingDefinitions2(tree, macros2);
645
+ };
646
+ };
647
+
614
648
  // libs/unified-args/index.ts
615
649
  var ttyStream = Object.assign(new stream.Readable(), { isTTY: true });
616
650
  var exitStatus = 0;
@@ -687,6 +721,12 @@ function unifiedArgs(cliConfig) {
687
721
  { macros: config.expandMacro }
688
722
  ]);
689
723
  }
724
+ if (config.expandDocumentMacro.length > 0) {
725
+ config.plugins.push([
726
+ expandDocumentMacrosPlugin,
727
+ { macros: config.expandDocumentMacro }
728
+ ]);
729
+ }
690
730
  if (config.statsJson) {
691
731
  config.plugins.push([statsJsonPlugin]);
692
732
  }
@@ -745,11 +785,22 @@ function noop() {
745
785
  }
746
786
 
747
787
  // index.ts
788
+ import fs from "node:fs";
789
+ var version = "unknown (could not read version from package.json)";
790
+ try {
791
+ const packageJson = JSON.parse(
792
+ fs.readFileSync(new URL("./package.json", import.meta.url), {
793
+ encoding: "utf8"
794
+ })
795
+ );
796
+ version = packageJson.version;
797
+ } catch {
798
+ }
748
799
  unifiedArgs({
749
800
  processor: processLatexViaUnified,
750
801
  name: "unified-latex",
751
802
  description: "LaTeX processor powered by unified-latex",
752
- version: "1.0.8",
803
+ version,
753
804
  extensions: ["tex"],
754
805
  ignoreName: ".unifiedlatexignore",
755
806
  packageField: "unifiedLatexConfig",