@unified-latex/unified-latex-util-parse 1.0.12 → 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/README.md CHANGED
@@ -51,18 +51,23 @@ Parse a string to a LaTeX AST.
51
51
  #### options
52
52
 
53
53
  ```typescript
54
- { mode?: "math" | "regular"; macros?: Ast.MacroInfoRecord; environments?: Ast.EnvInfoRecord; }
54
+ { mode?: "math" | "regular"; macros?: Ast.MacroInfoRecord; environments?: Ast.EnvInfoRecord; flags?: { atLetter?: boolean; expl3?: boolean; autodetectExpl3AndAtLetter?: boolean; }; }
55
55
  ```
56
56
 
57
57
  ### Type
58
58
 
59
- `Plugin<{ mode?: "math" | "regular"; macros?: Ast.MacroInfoRecord; environments?: Ast.EnvInfoRecord; }[], string, Ast.Root>`
59
+ `Plugin<{ mode?: "math" | "regular"; macros?: Ast.MacroInfoRecord; environments?: Ast.EnvInfoRecord; flags?: { atLetter?: boolean; expl3?: boolean; autodetectExpl3AndAtLetter?: boolean; }; }[], string, Ast.Root>`
60
60
 
61
61
  ```typescript
62
62
  function unifiedLatexFromString(options: {
63
63
  mode?: "math" | "regular";
64
64
  macros?: Ast.MacroInfoRecord;
65
65
  environments?: Ast.EnvInfoRecord;
66
+ flags?: {
67
+ atLetter?: boolean;
68
+ expl3?: boolean;
69
+ autodetectExpl3AndAtLetter?: boolean;
70
+ };
66
71
  }): void;
67
72
  ```
68
73
 
@@ -165,6 +170,21 @@ export type PluginOptions =
165
170
  mode?: "math" | "regular";
166
171
  macros?: MacroInfoRecord;
167
172
  environments?: EnvInfoRecord;
173
+ flags?: {
174
+ /**
175
+ * Whether to parse macros as if `\makeatletter` is set (i.e., parse `@` as a regular macro character)
176
+ */
177
+ atLetter?: boolean;
178
+ /**
179
+ * Whether to parse macros as if `\ExplSyntaxOn` is set (i.e., parse `_` and `:` as a regular macro character)
180
+ */
181
+ expl3?: boolean;
182
+ /**
183
+ * Attempt to autodetect whether there are macros that look like they should contain `@`, `_`, or `:`.
184
+ * Defaults to `false`.
185
+ */
186
+ autodetectExpl3AndAtLetter?: boolean;
187
+ };
168
188
  }
169
189
  | undefined;
170
190
  ```
package/index.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -79,41 +80,57 @@ function unifiedLatexReparseMathConstructPlugin({
79
80
  const isMathEnvironment = import_unified_latex_util_match.match.createEnvironmentMatcher(mathEnvs);
80
81
  const isMathMacro = import_unified_latex_util_match.match.createMacroMatcher(mathMacros);
81
82
  return (tree) => {
82
- (0, import_unified_latex_util_visit.visit)(tree, (node) => {
83
- if (import_unified_latex_util_match.match.anyMacro(node)) {
84
- for (const arg of node.args || []) {
85
- if (arg.content.length > 0 && !wasParsedInMathMode(arg.content)) {
86
- arg.content = parseMathMinimal((0, import_unified_latex_util_print_raw.printRaw)(arg.content));
83
+ (0, import_unified_latex_util_visit.visit)(
84
+ tree,
85
+ (node) => {
86
+ if (import_unified_latex_util_match.match.anyMacro(node)) {
87
+ for (const arg of node.args || []) {
88
+ if (arg.content.length > 0 && !wasParsedInMathMode(arg.content)) {
89
+ arg.content = parseMathMinimal(
90
+ (0, import_unified_latex_util_print_raw.printRaw)(arg.content)
91
+ );
92
+ }
87
93
  }
88
94
  }
89
- }
90
- if (import_unified_latex_util_match.match.anyEnvironment(node)) {
91
- if (!wasParsedInMathMode(node.content)) {
92
- node.content = parseMathMinimal((0, import_unified_latex_util_print_raw.printRaw)(node.content));
95
+ if (import_unified_latex_util_match.match.anyEnvironment(node)) {
96
+ if (!wasParsedInMathMode(node.content)) {
97
+ node.content = parseMathMinimal((0, import_unified_latex_util_print_raw.printRaw)(node.content));
98
+ }
93
99
  }
100
+ },
101
+ {
102
+ test: (node) => isMathEnvironment(node) || isMathMacro(node)
94
103
  }
95
- }, {
96
- test: (node) => isMathEnvironment(node) || isMathMacro(node)
97
- });
104
+ );
98
105
  };
99
106
  }
100
107
  function wasParsedInMathMode(nodes) {
101
- return !nodes.some((node) => import_unified_latex_util_match.match.anyString(node) && node.content.length > 1 || import_unified_latex_util_match.match.string(node, "^") || import_unified_latex_util_match.match.string(node, "_"));
108
+ return !nodes.some(
109
+ (node) => import_unified_latex_util_match.match.anyString(node) && node.content.length > 1 || import_unified_latex_util_match.match.string(node, "^") || import_unified_latex_util_match.match.string(node, "_")
110
+ );
102
111
  }
103
112
 
104
113
  // libs/process-macros-and-environments.ts
105
114
  var import_unified_latex_util_arguments = require("@unified-latex/unified-latex-util-arguments");
106
115
  var import_unified_latex_util_environments = require("@unified-latex/unified-latex-util-environments");
107
- var unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse = function unifiedLatexAttachMacroArguments(options) {
116
+ var unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse = function unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse2(options) {
108
117
  const { environments = {}, macros = {} } = options || {};
109
- const mathMacros = Object.fromEntries(Object.entries(macros).filter(([_, info]) => {
110
- var _a;
111
- return ((_a = info.renderInfo) == null ? void 0 : _a.inMathMode) === true;
112
- }));
113
- const mathEnvs = Object.fromEntries(Object.entries(environments).filter(([_, info]) => {
114
- var _a;
115
- return ((_a = info.renderInfo) == null ? void 0 : _a.inMathMode) === true;
116
- }));
118
+ const mathMacros = Object.fromEntries(
119
+ Object.entries(macros).filter(
120
+ ([_, info]) => {
121
+ var _a;
122
+ return ((_a = info.renderInfo) == null ? void 0 : _a.inMathMode) === true;
123
+ }
124
+ )
125
+ );
126
+ const mathEnvs = Object.fromEntries(
127
+ Object.entries(environments).filter(
128
+ ([_, info]) => {
129
+ var _a;
130
+ return ((_a = info.renderInfo) == null ? void 0 : _a.inMathMode) === true;
131
+ }
132
+ )
133
+ );
117
134
  const mathReparser = unifiedLatexReparseMathConstructPlugin({
118
135
  mathEnvs: Object.keys(mathEnvs),
119
136
  mathMacros: Object.keys(mathMacros)
@@ -121,45 +138,89 @@ var unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse = function unifiedLa
121
138
  const isRelevantEnvironment = import_unified_latex_util_match2.match.createEnvironmentMatcher(environments);
122
139
  const isRelevantMathEnvironment = import_unified_latex_util_match2.match.createEnvironmentMatcher(mathEnvs);
123
140
  return (tree) => {
124
- (0, import_unified_latex_util_visit2.visit)(tree, {
125
- enter: (nodes) => {
126
- if (!Array.isArray(nodes)) {
127
- return;
141
+ (0, import_unified_latex_util_visit2.visit)(
142
+ tree,
143
+ {
144
+ enter: (nodes) => {
145
+ if (!Array.isArray(nodes)) {
146
+ return;
147
+ }
148
+ (0, import_unified_latex_util_arguments.attachMacroArgsInArray)(nodes, mathMacros);
149
+ },
150
+ leave: (node) => {
151
+ if (!isRelevantMathEnvironment(node)) {
152
+ return;
153
+ }
154
+ const envName = (0, import_unified_latex_util_print_raw2.printRaw)(node.env);
155
+ const envInfo = environments[envName];
156
+ if (!envInfo) {
157
+ throw new Error(
158
+ `Could not find environment info for environment "${envName}"`
159
+ );
160
+ }
161
+ (0, import_unified_latex_util_environments.processEnvironment)(node, envInfo);
128
162
  }
129
- (0, import_unified_latex_util_arguments.attachMacroArgsInArray)(nodes, mathMacros);
130
163
  },
131
- leave: (node) => {
132
- if (!isRelevantMathEnvironment(node)) {
133
- return;
134
- }
135
- const envName = (0, import_unified_latex_util_print_raw2.printRaw)(node.env);
136
- const envInfo = environments[envName];
137
- if (!envInfo) {
138
- throw new Error(`Could not find environment info for environment "${envName}"`);
139
- }
140
- (0, import_unified_latex_util_environments.processEnvironment)(node, envInfo);
141
- }
142
- }, { includeArrays: true });
164
+ { includeArrays: true }
165
+ );
143
166
  mathReparser(tree);
144
- (0, import_unified_latex_util_visit2.visit)(tree, {
145
- enter: (nodes) => {
146
- if (!Array.isArray(nodes)) {
147
- return;
167
+ (0, import_unified_latex_util_visit2.visit)(
168
+ tree,
169
+ {
170
+ enter: (nodes) => {
171
+ if (!Array.isArray(nodes)) {
172
+ return;
173
+ }
174
+ (0, import_unified_latex_util_arguments.attachMacroArgsInArray)(nodes, macros);
175
+ },
176
+ leave: (node) => {
177
+ if (!isRelevantEnvironment(node)) {
178
+ return;
179
+ }
180
+ const envName = (0, import_unified_latex_util_print_raw2.printRaw)(node.env);
181
+ const envInfo = environments[envName];
182
+ if (!envInfo) {
183
+ throw new Error(
184
+ `Could not find environment info for environment "${envName}"`
185
+ );
186
+ }
187
+ (0, import_unified_latex_util_environments.processEnvironment)(node, envInfo);
148
188
  }
149
- (0, import_unified_latex_util_arguments.attachMacroArgsInArray)(nodes, macros);
150
189
  },
151
- leave: (node) => {
152
- if (!isRelevantEnvironment(node)) {
153
- return;
154
- }
155
- const envName = (0, import_unified_latex_util_print_raw2.printRaw)(node.env);
156
- const envInfo = environments[envName];
157
- if (!envInfo) {
158
- throw new Error(`Could not find environment info for environment "${envName}"`);
159
- }
160
- (0, import_unified_latex_util_environments.processEnvironment)(node, envInfo);
161
- }
162
- }, { includeArrays: true });
190
+ { includeArrays: true }
191
+ );
192
+ };
193
+ };
194
+
195
+ // libs/process-at-letter-and-expl-macros.ts
196
+ var import_unified_latex_util_catcode = require("@unified-latex/unified-latex-util-catcode");
197
+ var import_unified_latex_util_catcode2 = require("@unified-latex/unified-latex-util-catcode");
198
+ var unifiedLatexProcessAtLetterAndExplMacros = function unifiedLatexProcessAtLetterAndExplMacros2(options) {
199
+ let {
200
+ atLetter = false,
201
+ expl3 = false,
202
+ autodetectExpl3AndAtLetter = false
203
+ } = options || {};
204
+ return (tree) => {
205
+ (0, import_unified_latex_util_catcode.reparseExpl3AndAtLetterRegions)(tree);
206
+ if (atLetter || expl3) {
207
+ autodetectExpl3AndAtLetter = false;
208
+ }
209
+ if (autodetectExpl3AndAtLetter) {
210
+ atLetter = (0, import_unified_latex_util_catcode2.hasReparsableMacroNames)(tree, "@");
211
+ expl3 = (0, import_unified_latex_util_catcode2.hasReparsableMacroNames)(tree, "_");
212
+ }
213
+ const charSet = /* @__PURE__ */ new Set();
214
+ if (atLetter) {
215
+ charSet.add("@");
216
+ }
217
+ if (expl3) {
218
+ charSet.add(":");
219
+ charSet.add("_");
220
+ }
221
+ if (charSet.size > 0) {
222
+ (0, import_unified_latex_util_catcode2.reparseMacroNames)(tree, charSet);
223
+ }
163
224
  };
164
225
  };
165
226
 
@@ -168,11 +229,28 @@ var unifiedLatexFromString = function unifiedLatexFromString2(options) {
168
229
  const {
169
230
  mode = "regular",
170
231
  macros = {},
171
- environments = {}
232
+ environments = {},
233
+ flags: {
234
+ atLetter = false,
235
+ expl3 = false,
236
+ autodetectExpl3AndAtLetter = false
237
+ } = {}
172
238
  } = options || {};
173
- const allMacroInfo = Object.assign({}, macros, ...Object.values(import_unified_latex_ctan.macroInfo));
174
- const allEnvInfo = Object.assign({}, environments, ...Object.values(import_unified_latex_ctan.environmentInfo));
175
- const fullParser = (0, import_unified.unified)().use(unifiedLatexFromStringMinimal, { mode }).use(unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse, {
239
+ const allMacroInfo = Object.assign(
240
+ {},
241
+ macros,
242
+ ...Object.values(import_unified_latex_ctan.macroInfo)
243
+ );
244
+ const allEnvInfo = Object.assign(
245
+ {},
246
+ environments,
247
+ ...Object.values(import_unified_latex_ctan.environmentInfo)
248
+ );
249
+ const fullParser = (0, import_unified.unified)().use(unifiedLatexFromStringMinimal, { mode }).use(unifiedLatexProcessAtLetterAndExplMacros, {
250
+ atLetter,
251
+ expl3,
252
+ autodetectExpl3AndAtLetter
253
+ }).use(unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse, {
176
254
  macros: allMacroInfo,
177
255
  environments: allEnvInfo
178
256
  }).use(import_unified_latex_util_trim.unifiedLatexTrimEnvironmentContents).use(import_unified_latex_util_trim.unifiedLatexTrimRoot).use(unifiedLatexAstComplier);
package/index.cjs.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../index.ts", "../libs/compiler-ast.ts", "../libs/plugin-from-string.ts", "../libs/parse-minimal.ts", "../libs/plugin-from-string-minimal.ts", "../libs/process-macros-and-environments.ts", "../libs/reparse-math.ts", "../libs/parse.ts", "../libs/parse-math.ts"],
4
- "sourcesContent": ["export * from \"./libs/compiler-ast\";\nexport * from \"./libs/plugin-from-string\";\nexport * from \"./libs/plugin-from-string-minimal\";\nexport * from \"./libs/parse-minimal\";\nexport * from \"./libs/parse\";\nexport * from \"./libs/parse-math\";\n\n// NOTE: The docstring comment must be the last item in the index.ts file!\n/**\n * ## What is this?\n *\n * Functions parse strings to a `unified-latex` Abstract Syntax Tree (AST).\n *\n * ## When should I use this?\n *\n * If you have a string that you would like to parse to a `unified-latex` `Ast.Ast`, or\n * if you are building a plugin for `unified()` that manipulates LaTeX.\n */\n", "import { Plugin } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\n\n/**\n * Unified complier plugin that passes through a LaTeX AST without modification.\n */\nexport const unifiedLatexAstComplier: Plugin<void[], Ast.Root, Ast.Root> =\n function unifiedLatexAstComplier() {\n Object.assign(this, { Compiler: (x: Ast.Root) => x });\n };\n", "import { Plugin, Parser, unified } from \"unified\";\nimport { environmentInfo, macroInfo } from \"@unified-latex/unified-latex-ctan\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { EnvInfoRecord, MacroInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport {\n unifiedLatexTrimEnvironmentContents,\n unifiedLatexTrimRoot,\n} from \"@unified-latex/unified-latex-util-trim\";\nimport { unifiedLatexAstComplier } from \"./compiler-ast\";\nimport { unifiedLatexFromStringMinimal } from \"./plugin-from-string-minimal\";\nimport { unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse } from \"./process-macros-and-environments\";\n\nexport type PluginOptions =\n | {\n mode?: \"math\" | \"regular\";\n macros?: MacroInfoRecord;\n environments?: EnvInfoRecord;\n }\n | undefined;\n\n/**\n * Parse a string to a LaTeX AST.\n */\nexport const unifiedLatexFromString: Plugin<PluginOptions[], string, Ast.Root> =\n function unifiedLatexFromString(options) {\n const {\n mode = \"regular\",\n macros = {},\n environments = {},\n } = options || {};\n\n // Build up a parsing plugin with only unified components\n const allMacroInfo: MacroInfoRecord = Object.assign(\n {},\n macros,\n ...Object.values(macroInfo)\n );\n const allEnvInfo: EnvInfoRecord = Object.assign(\n {},\n environments,\n ...Object.values(environmentInfo)\n );\n\n // Build up a parser that will perform all the needed steps\n const fullParser = unified()\n .use(unifiedLatexFromStringMinimal, { mode })\n // Math environments that aren't hardcoded into the PEG grammar need to be re-parsed,\n // so do a minimal pass first with just those environments.\n .use(unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse, {\n macros: allMacroInfo,\n environments: allEnvInfo,\n })\n .use(unifiedLatexTrimEnvironmentContents)\n .use(unifiedLatexTrimRoot)\n .use(unifiedLatexAstComplier);\n\n const parser: Parser<Ast.Root> = (str) => {\n const file = fullParser.processSync({ value: str });\n return file.result;\n };\n\n Object.assign(this, { Parser: parser });\n };\n", "import { LatexPegParser } from \"@unified-latex/unified-latex-util-pegjs\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\n\n/**\n * Parse `str` to an AST with minimal processing. E.g., macro\n * arguments are not attached to macros, etc. when parsed with this\n * function.\n */\nexport function parseMinimal(str: string): Ast.Root {\n return LatexPegParser.parse(str);\n}\n\n/**\n * Parse `str` to an AST with minimal processing. E.g., macro\n * arguments are not attached to macros, etc. when parsed with this\n * function.\n *\n * The parsing assumes a math-mode context, so, for example, `^` and `_` are\n * parsed as macros (even though arguments are not attached to them).\n */\nexport function parseMathMinimal(str: string): Ast.Node[] {\n return LatexPegParser.parse(str, { startRule: \"math\" });\n}\n", "import { Plugin, Parser } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { parseMathMinimal, parseMinimal } from \"./parse-minimal\";\n\ntype PluginOptions = {\n /**\n * Whether the text will be parsed assuming math mode or not.\n */\n mode: \"math\" | \"regular\";\n} | void;\n\n/**\n * Parse a string to a LaTeX AST with no post processing. For example,\n * no macro arguments will be attached, etc.\n */\nexport const unifiedLatexFromStringMinimal: Plugin<\n PluginOptions[],\n string,\n Ast.Root\n> = function unifiedLatexFromStringMinimal(options) {\n const parser: Parser<Ast.Root> = (str) => {\n if (options?.mode === \"math\") {\n return {\n type: \"root\",\n content: parseMathMinimal(str),\n _renderInfo: { inMathMode: true },\n };\n }\n return parseMinimal(str);\n };\n\n Object.assign(this, { Parser: parser });\n};\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { EnvInfoRecord, MacroInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { Plugin } from \"unified\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport {\n unifiedLatexReparseMathConstructPlugin,\n} from \"./reparse-math\";\nimport { attachMacroArgsInArray } from \"@unified-latex/unified-latex-util-arguments\";\nimport { processEnvironment } from \"@unified-latex/unified-latex-util-environments\";\n\ntype PluginOptions =\n | { environments: EnvInfoRecord; macros: MacroInfoRecord }\n | undefined;\n\n/**\n * Unified plugin to process macros and environments. Any environments that contain math content\n * are reparsed (if needed) in math mode.\n */\nexport const unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexAttachMacroArguments(options) {\n const { environments = {}, macros = {} } = options || {};\n\n const mathMacros = Object.fromEntries(\n Object.entries(macros).filter(\n ([_, info]) => info.renderInfo?.inMathMode === true\n )\n );\n const mathEnvs = Object.fromEntries(\n Object.entries(environments).filter(\n ([_, info]) => info.renderInfo?.inMathMode === true\n )\n );\n\n const mathReparser = unifiedLatexReparseMathConstructPlugin({\n mathEnvs: Object.keys(mathEnvs),\n mathMacros: Object.keys(mathMacros),\n });\n\n const isRelevantEnvironment = match.createEnvironmentMatcher(environments);\n const isRelevantMathEnvironment = match.createEnvironmentMatcher(mathEnvs);\n\n return (tree) => {\n // First we attach all arguments/process all nodes/environments that have math content\n visit(\n tree,\n {\n enter: (nodes) => {\n if (!Array.isArray(nodes)) {\n return;\n }\n attachMacroArgsInArray(nodes, mathMacros);\n },\n leave: (node) => {\n if (!isRelevantMathEnvironment(node)) {\n return;\n }\n const envName = printRaw(node.env);\n const envInfo = environments[envName];\n if (!envInfo) {\n throw new Error(\n `Could not find environment info for environment \"${envName}\"`\n );\n }\n processEnvironment(node, envInfo);\n },\n },\n { includeArrays: true }\n );\n\n // Next we reparse macros/envs that may not have been parsed in math mode\n mathReparser(tree);\n\n // Now we attach all arguments/process all environment bodies\n visit(\n tree,\n {\n enter: (nodes) => {\n if (!Array.isArray(nodes)) {\n return;\n }\n attachMacroArgsInArray(nodes, macros);\n },\n leave: (node) => {\n if (!isRelevantEnvironment(node)) {\n return;\n }\n const envName = printRaw(node.env);\n const envInfo = environments[envName];\n if (!envInfo) {\n throw new Error(\n `Could not find environment info for environment \"${envName}\"`\n );\n }\n processEnvironment(node, envInfo);\n },\n },\n { includeArrays: true }\n );\n };\n};\n", "import { Plugin } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { parseMathMinimal } from \"./parse-minimal\";\n\ntype PluginOptions =\n | {\n /**\n * List of environments whose body should be parsed in math mode\n */\n mathEnvs: string[];\n /**\n * List of macros whose bodies should be parsed in math mode\n */\n mathMacros: string[];\n }\n | undefined;\n\n/**\n * Reparse math environments/macro contents that should have been parsed in math mode but weren't.\n */\nexport const unifiedLatexReparseMath: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexReparseMath(options) {\n const { mathEnvs = [], mathMacros = [] } = options || {};\n\n return unifiedLatexReparseMathConstructPlugin({ mathMacros, mathEnvs });\n};\n\n/**\n * Construct the inner function for the `unifiedLatexReparseMath` plugin. This function should not be used by libraries.\n */\nexport function unifiedLatexReparseMathConstructPlugin({\n mathEnvs,\n mathMacros,\n}: {\n mathEnvs: string[];\n mathMacros: string[];\n}) {\n const isMathEnvironment = match.createEnvironmentMatcher(mathEnvs);\n const isMathMacro = match.createMacroMatcher(mathMacros);\n\n return (tree: Ast.Root) => {\n visit(\n tree,\n (node) => {\n if (match.anyMacro(node)) {\n for (const arg of node.args || []) {\n if (\n arg.content.length > 0 &&\n !wasParsedInMathMode(arg.content)\n ) {\n arg.content = parseMathMinimal(\n printRaw(arg.content)\n );\n }\n }\n }\n if (match.anyEnvironment(node)) {\n if (!wasParsedInMathMode(node.content)) {\n node.content = parseMathMinimal(printRaw(node.content));\n }\n }\n },\n {\n test: (node) => isMathEnvironment(node) || isMathMacro(node),\n }\n );\n };\n}\n\n/**\n * Use a heuristic to decide whether a string was parsed in math mode. The heuristic\n * looks for strings of length greater than 1 or the failure for \"_\" and \"^\" to be parsed\n * as a macro.\n */\nfunction wasParsedInMathMode(nodes: Ast.Node[]): boolean {\n return !nodes.some(\n (node) =>\n // If there are multi-char strings or ^ and _ have been parsed as strings, we know\n // that we were not parsed in math mode.\n (match.anyString(node) && node.content.length > 1) ||\n match.string(node, \"^\") ||\n match.string(node, \"_\")\n );\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { unified } from \"unified\";\nimport { unifiedLatexFromString } from \"./plugin-from-string\";\n\nconst parser = unified().use(unifiedLatexFromString).freeze();\n\n/**\n * Parse the string into an AST.\n */\nexport function parse(str: string): Ast.Root {\n return parser.parse(str);\n}\n", "import { unified } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport { unifiedLatexAstComplier } from \"./compiler-ast\";\nimport { unifiedLatexFromString } from \"./plugin-from-string\";\n\n/**\n * Parse `str` into an AST. Parsing starts in math mode and a list of\n * nodes is returned (instead of a \"root\" node).\n */\nexport function parseMath(str: string | Ast.Ast): Ast.Node[] {\n if (typeof str !== \"string\") {\n str = printRaw(str);\n }\n const file = unified()\n .use(unifiedLatexFromString, { mode: \"math\" })\n .use(unifiedLatexAstComplier)\n .processSync({ value: str });\n return (file.result as Ast.Root).content;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,IAAM,0BACT,oCAAmC;AAC/B,SAAO,OAAO,MAAM,EAAE,UAAU,CAAC,MAAgB,EAAE,CAAC;AACxD;;;ACTJ,qBAAwC;AACxC,gCAA2C;AAG3C,qCAGO;;;ACPP,sCAA+B;AAQxB,sBAAsB,KAAuB;AAChD,SAAO,+CAAe,MAAM,GAAG;AACnC;AAUO,0BAA0B,KAAyB;AACtD,SAAO,+CAAe,MAAM,KAAK,EAAE,WAAW,OAAO,CAAC;AAC1D;;;ACPO,IAAM,gCAIT,wCAAuC,SAAS;AAChD,QAAM,UAA2B,CAAC,QAAQ;AACtC,QAAI,oCAAS,UAAS,QAAQ;AAC1B,aAAO;AAAA,QACH,MAAM;AAAA,QACN,SAAS,iBAAiB,GAAG;AAAA,QAC7B,aAAa,EAAE,YAAY,KAAK;AAAA,MACpC;AAAA,IACJ;AACA,WAAO,aAAa,GAAG;AAAA,EAC3B;AAEA,SAAO,OAAO,MAAM,EAAE,QAAQ,QAAO,CAAC;AAC1C;;;AC7BA,uCAAsB;AACtB,uCAAsB;AACtB,2CAAyB;;;ACHzB,sCAAsB;AACtB,0CAAyB;AACzB,sCAAsB;AAgCf,gDAAgD;AAAA,EACnD;AAAA,EACA;AAAA,GAID;AACC,QAAM,oBAAoB,sCAAM,yBAAyB,QAAQ;AACjE,QAAM,cAAc,sCAAM,mBAAmB,UAAU;AAEvD,SAAO,CAAC,SAAmB;AACvB,+CACI,MACA,CAAC,SAAS;AACN,UAAI,sCAAM,SAAS,IAAI,GAAG;AACtB,mBA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,OAAO,OACrC,CAAC,GACD,cACA,GAAG,OAAO,OAAO,yCAAe,CACpC;AAGA,QAAM,aAAa,4BAAQ,EACtB,IAAI,+BAA+B,EAAE,KAAK,CAAC,EAG3C,IAAI,yDAAyD;AAAA,IAC1D,QAAQ;AAAA,IACR,cAAc;AAAA,EAClB,CAAC,EACA,IAAI,kEAAmC,EACvC,IAAI,mDAAoB,EACxB,IAAI,uBAAuB;AAEhC,QAAM,UAA2B,CAAC,QAAQ;AACtC,UAAM,OAAO,WAAW,YAAY,EAAE,OAAO,IAAI,CAAC;AAClD,WAAO,KAAK;AAAA,EAChB;AAEA,SAAO,OAAO,MAAM,EAAE,QAAQ,QAAO,CAAC;AAC1C;;;AK7DJ,sBAAwB;AAGxB,IAAM,SAAS,6BAAQ,EAAE,IAAI,sBAAsB,EAAE,OAAO;AAKrD,eAAe,KAAuB;AACzC,SAAO,OAAO,MAAM,GAAG;AAC3B;;;ACXA,sBAAwB;AAExB,2CAAyB;AAQlB,mBAAmB,KAAmC;AACzD,MAAI,OAAO,QAAQ,UAAU;AACzB,UAAM,mDAAS,GAAG;AAAA,EACtB;AACA,QAAM,OAAO,6BAAQ,EAChB,IAAI,wBAAwB,EAAE,MAAM,OAAO,CAAC,EAC5C,IAAI,uBAAuB,EAC3B,YAAY,EAAE,OAAO,IAAI,CAAC;AAC/B,SAAQ,KAAK,OAAoB;AACrC;",
6
- "names": []
3
+ "sources": ["../index.ts", "../libs/compiler-ast.ts", "../libs/plugin-from-string.ts", "../libs/parse-minimal.ts", "../libs/plugin-from-string-minimal.ts", "../libs/process-macros-and-environments.ts", "../libs/reparse-math.ts", "../libs/process-at-letter-and-expl-macros.ts", "../libs/parse.ts", "../libs/parse-math.ts"],
4
+ "sourcesContent": ["export * from \"./libs/compiler-ast\";\nexport * from \"./libs/plugin-from-string\";\nexport * from \"./libs/plugin-from-string-minimal\";\nexport * from \"./libs/parse-minimal\";\nexport * from \"./libs/parse\";\nexport * from \"./libs/parse-math\";\n\n// NOTE: The docstring comment must be the last item in the index.ts file!\n/**\n * ## What is this?\n *\n * Functions parse strings to a `unified-latex` Abstract Syntax Tree (AST).\n *\n * ## When should I use this?\n *\n * If you have a string that you would like to parse to a `unified-latex` `Ast.Ast`, or\n * if you are building a plugin for `unified()` that manipulates LaTeX.\n */\n", "import { Plugin } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\n\n/**\n * Unified complier plugin that passes through a LaTeX AST without modification.\n */\nexport const unifiedLatexAstComplier: Plugin<void[], Ast.Root, Ast.Root> =\n function unifiedLatexAstComplier() {\n Object.assign(this, { Compiler: (x: Ast.Root) => x });\n };\n", "import { Plugin, Parser, unified } from \"unified\";\nimport { environmentInfo, macroInfo } from \"@unified-latex/unified-latex-ctan\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport {\n EnvInfoRecord,\n MacroInfoRecord,\n} from \"@unified-latex/unified-latex-types\";\nimport {\n unifiedLatexTrimEnvironmentContents,\n unifiedLatexTrimRoot,\n} from \"@unified-latex/unified-latex-util-trim\";\nimport { unifiedLatexAstComplier } from \"./compiler-ast\";\nimport { unifiedLatexFromStringMinimal } from \"./plugin-from-string-minimal\";\nimport { unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse } from \"./process-macros-and-environments\";\nimport { unifiedLatexProcessAtLetterAndExplMacros } from \"./process-at-letter-and-expl-macros\";\n\nexport type PluginOptions =\n | {\n mode?: \"math\" | \"regular\";\n macros?: MacroInfoRecord;\n environments?: EnvInfoRecord;\n flags?: {\n /**\n * Whether to parse macros as if `\\makeatletter` is set (i.e., parse `@` as a regular macro character)\n */\n atLetter?: boolean;\n /**\n * Whether to parse macros as if `\\ExplSyntaxOn` is set (i.e., parse `_` and `:` as a regular macro character)\n */\n expl3?: boolean;\n /**\n * Attempt to autodetect whether there are macros that look like they should contain `@`, `_`, or `:`.\n * Defaults to `false`.\n */\n autodetectExpl3AndAtLetter?: boolean;\n };\n }\n | undefined;\n\n/**\n * Parse a string to a LaTeX AST.\n */\nexport const unifiedLatexFromString: Plugin<PluginOptions[], string, Ast.Root> =\n function unifiedLatexFromString(options) {\n const {\n mode = \"regular\",\n macros = {},\n environments = {},\n flags: {\n atLetter = false,\n expl3 = false,\n autodetectExpl3AndAtLetter = false,\n } = {},\n } = options || {};\n\n // Build up a parsing plugin with only unified components\n const allMacroInfo: MacroInfoRecord = Object.assign(\n {},\n macros,\n ...Object.values(macroInfo)\n );\n const allEnvInfo: EnvInfoRecord = Object.assign(\n {},\n environments,\n ...Object.values(environmentInfo)\n );\n\n // Build up a parser that will perform all the needed steps\n const fullParser = unified()\n .use(unifiedLatexFromStringMinimal, { mode })\n .use(unifiedLatexProcessAtLetterAndExplMacros, {\n atLetter,\n expl3,\n autodetectExpl3AndAtLetter,\n })\n // Math environments that aren't hardcoded into the PEG grammar need to be re-parsed,\n // so do a minimal pass first with just those environments.\n .use(unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse, {\n macros: allMacroInfo,\n environments: allEnvInfo,\n })\n .use(unifiedLatexTrimEnvironmentContents)\n .use(unifiedLatexTrimRoot)\n .use(unifiedLatexAstComplier);\n\n const parser: Parser<Ast.Root> = (str) => {\n const file = fullParser.processSync({ value: str });\n return file.result;\n };\n\n Object.assign(this, { Parser: parser });\n };\n", "import { LatexPegParser } from \"@unified-latex/unified-latex-util-pegjs\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\n\n/**\n * Parse `str` to an AST with minimal processing. E.g., macro\n * arguments are not attached to macros, etc. when parsed with this\n * function.\n */\nexport function parseMinimal(str: string): Ast.Root {\n return LatexPegParser.parse(str);\n}\n\n/**\n * Parse `str` to an AST with minimal processing. E.g., macro\n * arguments are not attached to macros, etc. when parsed with this\n * function.\n *\n * The parsing assumes a math-mode context, so, for example, `^` and `_` are\n * parsed as macros (even though arguments are not attached to them).\n */\nexport function parseMathMinimal(str: string): Ast.Node[] {\n return LatexPegParser.parse(str, { startRule: \"math\" });\n}\n", "import { Plugin, Parser } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { parseMathMinimal, parseMinimal } from \"./parse-minimal\";\n\ntype PluginOptions = {\n /**\n * Whether the text will be parsed assuming math mode or not.\n */\n mode: \"math\" | \"regular\";\n} | void;\n\n/**\n * Parse a string to a LaTeX AST with no post processing. For example,\n * no macro arguments will be attached, etc.\n */\nexport const unifiedLatexFromStringMinimal: Plugin<\n PluginOptions[],\n string,\n Ast.Root\n> = function unifiedLatexFromStringMinimal(options) {\n const parser: Parser<Ast.Root> = (str) => {\n if (options?.mode === \"math\") {\n return {\n type: \"root\",\n content: parseMathMinimal(str),\n _renderInfo: { inMathMode: true },\n };\n }\n return parseMinimal(str);\n };\n\n Object.assign(this, { Parser: parser });\n};\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { EnvInfoRecord, MacroInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { Plugin } from \"unified\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport {\n unifiedLatexReparseMathConstructPlugin,\n} from \"./reparse-math\";\nimport { attachMacroArgsInArray } from \"@unified-latex/unified-latex-util-arguments\";\nimport { processEnvironment } from \"@unified-latex/unified-latex-util-environments\";\n\ntype PluginOptions =\n | { environments: EnvInfoRecord; macros: MacroInfoRecord }\n | undefined;\n\n/**\n * Unified plugin to process macros and environments. Any environments that contain math content\n * are reparsed (if needed) in math mode.\n */\nexport const unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse(options) {\n const { environments = {}, macros = {} } = options || {};\n\n const mathMacros = Object.fromEntries(\n Object.entries(macros).filter(\n ([_, info]) => info.renderInfo?.inMathMode === true\n )\n );\n const mathEnvs = Object.fromEntries(\n Object.entries(environments).filter(\n ([_, info]) => info.renderInfo?.inMathMode === true\n )\n );\n\n const mathReparser = unifiedLatexReparseMathConstructPlugin({\n mathEnvs: Object.keys(mathEnvs),\n mathMacros: Object.keys(mathMacros),\n });\n\n const isRelevantEnvironment = match.createEnvironmentMatcher(environments);\n const isRelevantMathEnvironment = match.createEnvironmentMatcher(mathEnvs);\n\n return (tree) => {\n // First we attach all arguments/process all nodes/environments that have math content\n visit(\n tree,\n {\n enter: (nodes) => {\n if (!Array.isArray(nodes)) {\n return;\n }\n attachMacroArgsInArray(nodes, mathMacros);\n },\n leave: (node) => {\n if (!isRelevantMathEnvironment(node)) {\n return;\n }\n const envName = printRaw(node.env);\n const envInfo = environments[envName];\n if (!envInfo) {\n throw new Error(\n `Could not find environment info for environment \"${envName}\"`\n );\n }\n processEnvironment(node, envInfo);\n },\n },\n { includeArrays: true }\n );\n\n // Next we reparse macros/envs that may not have been parsed in math mode\n mathReparser(tree);\n\n // Now we attach all arguments/process all environment bodies\n visit(\n tree,\n {\n enter: (nodes) => {\n if (!Array.isArray(nodes)) {\n return;\n }\n attachMacroArgsInArray(nodes, macros);\n },\n leave: (node) => {\n if (!isRelevantEnvironment(node)) {\n return;\n }\n const envName = printRaw(node.env);\n const envInfo = environments[envName];\n if (!envInfo) {\n throw new Error(\n `Could not find environment info for environment \"${envName}\"`\n );\n }\n processEnvironment(node, envInfo);\n },\n },\n { includeArrays: true }\n );\n };\n};\n", "import { Plugin } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { parseMathMinimal } from \"./parse-minimal\";\n\ntype PluginOptions =\n | {\n /**\n * List of environments whose body should be parsed in math mode\n */\n mathEnvs: string[];\n /**\n * List of macros whose bodies should be parsed in math mode\n */\n mathMacros: string[];\n }\n | undefined;\n\n/**\n * Reparse math environments/macro contents that should have been parsed in math mode but weren't.\n */\nexport const unifiedLatexReparseMath: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexReparseMath(options) {\n const { mathEnvs = [], mathMacros = [] } = options || {};\n\n return unifiedLatexReparseMathConstructPlugin({ mathMacros, mathEnvs });\n};\n\n/**\n * Construct the inner function for the `unifiedLatexReparseMath` plugin. This function should not be used by libraries.\n */\nexport function unifiedLatexReparseMathConstructPlugin({\n mathEnvs,\n mathMacros,\n}: {\n mathEnvs: string[];\n mathMacros: string[];\n}) {\n const isMathEnvironment = match.createEnvironmentMatcher(mathEnvs);\n const isMathMacro = match.createMacroMatcher(mathMacros);\n\n return (tree: Ast.Root) => {\n visit(\n tree,\n (node) => {\n if (match.anyMacro(node)) {\n for (const arg of node.args || []) {\n if (\n arg.content.length > 0 &&\n !wasParsedInMathMode(arg.content)\n ) {\n arg.content = parseMathMinimal(\n printRaw(arg.content)\n );\n }\n }\n }\n if (match.anyEnvironment(node)) {\n if (!wasParsedInMathMode(node.content)) {\n node.content = parseMathMinimal(printRaw(node.content));\n }\n }\n },\n {\n test: (node) => isMathEnvironment(node) || isMathMacro(node),\n }\n );\n };\n}\n\n/**\n * Use a heuristic to decide whether a string was parsed in math mode. The heuristic\n * looks for strings of length greater than 1 or the failure for \"_\" and \"^\" to be parsed\n * as a macro.\n */\nfunction wasParsedInMathMode(nodes: Ast.Node[]): boolean {\n return !nodes.some(\n (node) =>\n // If there are multi-char strings or ^ and _ have been parsed as strings, we know\n // that we were not parsed in math mode.\n (match.anyString(node) && node.content.length > 1) ||\n match.string(node, \"^\") ||\n match.string(node, \"_\")\n );\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { Plugin } from \"unified\";\nimport { reparseExpl3AndAtLetterRegions } from \"@unified-latex/unified-latex-util-catcode\";\nimport {\n hasReparsableMacroNames,\n reparseMacroNames,\n} from \"@unified-latex/unified-latex-util-catcode\";\n\ntype PluginOptions =\n | {\n /**\n * Whether to parse macros as if `\\makeatletter` is set (i.e., parse `@` as a regular macro character).\n * If this option is true, it disables autodetect.\n */\n atLetter?: boolean;\n /**\n * Whether to parse macros as if `\\ExplSyntaxOn` is set (i.e., parse `_` and `:` as a regular macro character)\n * If this option is true, it disables autodetect.\n */\n expl3?: boolean;\n /**\n * Attempt to autodetect whether there are macros that look like they should contain `@`, `_`, or `:`.\n * Defaults to `true`.\n */\n autodetectExpl3AndAtLetter?: boolean;\n }\n | undefined;\n\n/**\n * Unified plugin to reprocess macros names to possibly include `@`, `_`, or `:`.\n * This plugin detects the `\\makeatletter` and `\\ExplSyntaxOn` commands and reprocesses macro names\n * inside of those blocks to include those characters.\n */\nexport const unifiedLatexProcessAtLetterAndExplMacros: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexProcessAtLetterAndExplMacros(options) {\n let {\n atLetter = false,\n expl3 = false,\n autodetectExpl3AndAtLetter = false,\n } = options || {};\n\n return (tree) => {\n // First we reparse based on explicit \\makeatletter and \\ExplSyntaxOn macros\n reparseExpl3AndAtLetterRegions(tree);\n if (atLetter || expl3) {\n autodetectExpl3AndAtLetter = false;\n }\n if (autodetectExpl3AndAtLetter) {\n atLetter = hasReparsableMacroNames(tree, \"@\");\n // We don't check for the `:` here because it could be prone to misidentification.\n expl3 = hasReparsableMacroNames(tree, \"_\");\n }\n const charSet: Set<string> = new Set();\n if (atLetter) {\n charSet.add(\"@\");\n }\n if (expl3) {\n charSet.add(\":\");\n charSet.add(\"_\");\n }\n\n if (charSet.size > 0) {\n reparseMacroNames(tree, charSet);\n }\n };\n};\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { unified } from \"unified\";\nimport { unifiedLatexFromString } from \"./plugin-from-string\";\n\nconst parser = unified().use(unifiedLatexFromString).freeze();\n\n/**\n * Parse the string into an AST.\n */\nexport function parse(str: string): Ast.Root {\n return parser.parse(str);\n}\n", "import { unified } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport { unifiedLatexAstComplier } from \"./compiler-ast\";\nimport { unifiedLatexFromString } from \"./plugin-from-string\";\n\n/**\n * Parse `str` into an AST. Parsing starts in math mode and a list of\n * nodes is returned (instead of a \"root\" node).\n */\nexport function parseMath(str: string | Ast.Ast): Ast.Node[] {\n if (typeof str !== \"string\") {\n str = printRaw(str);\n }\n const file = unified()\n .use(unifiedLatexFromString, { mode: \"math\" })\n .use(unifiedLatexAstComplier)\n .processSync({ value: str });\n return (file.result as Ast.Root).content;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,IAAM,0BACT,SAASA,2BAA0B;AAC/B,SAAO,OAAO,MAAM,EAAE,UAAU,CAAC,MAAgB,EAAE,CAAC;AACxD;;;ACTJ,qBAAwC;AACxC,gCAA2C;AAM3C,qCAGO;;;ACVP,sCAA+B;AAQxB,SAAS,aAAa,KAAuB;AAChD,SAAO,+CAAe,MAAM,GAAG;AACnC;AAUO,SAAS,iBAAiB,KAAyB;AACtD,SAAO,+CAAe,MAAM,KAAK,EAAE,WAAW,OAAO,CAAC;AAC1D;;;ACPO,IAAM,gCAIT,SAASC,+BAA8B,SAAS;AAChD,QAAMC,UAA2B,CAAC,QAAQ;AACtC,SAAI,mCAAS,UAAS,QAAQ;AAC1B,aAAO;AAAA,QACH,MAAM;AAAA,QACN,SAAS,iBAAiB,GAAG;AAAA,QAC7B,aAAa,EAAE,YAAY,KAAK;AAAA,MACpC;AAAA,IACJ;AACA,WAAO,aAAa,GAAG;AAAA,EAC3B;AAEA,SAAO,OAAO,MAAM,EAAE,QAAQA,QAAO,CAAC;AAC1C;;;AC7BA,IAAAC,mCAAsB;AACtB,IAAAC,mCAAsB;AACtB,IAAAC,uCAAyB;;;ACHzB,sCAAsB;AACtB,0CAAyB;AACzB,sCAAsB;AAgCf,SAAS,uCAAuC;AAAA,EACnD;AAAA,E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;AAAA,EACpC;AAGA,QAAM,iBAAa,wBAAQ,EACtB,IAAI,+BAA+B,EAAE,KAAK,CAAC,EAC3C,IAAI,0CAA0C;AAAA,IAC3C;AAAA,IACA;AAAA,IACA;AAAA,EACJ,CAAC,EAGA,IAAI,yDAAyD;AAAA,IAC1D,QAAQ;AAAA,IACR,cAAc;AAAA,EAClB,CAAC,EACA,IAAI,kEAAmC,EACvC,IAAI,mDAAoB,EACxB,IAAI,uBAAuB;AAEhC,QAAMC,UAA2B,CAAC,QAAQ;AACtC,UAAM,OAAO,WAAW,YAAY,EAAE,OAAO,IAAI,CAAC;AAClD,WAAO,KAAK;AAAA,EAChB;AAEA,SAAO,OAAO,MAAM,EAAE,QAAQA,QAAO,CAAC;AAC1C;;;AM1FJ,IAAAC,kBAAwB;AAGxB,IAAM,aAAS,yBAAQ,EAAE,IAAI,sBAAsB,EAAE,OAAO;AAKrD,SAAS,MAAM,KAAuB;AACzC,SAAO,OAAO,MAAM,GAAG;AAC3B;;;ACXA,IAAAC,kBAAwB;AAExB,IAAAC,uCAAyB;AAQlB,SAAS,UAAU,KAAmC;AACzD,MAAI,OAAO,QAAQ,UAAU;AACzB,cAAM,+CAAS,GAAG;AAAA,EACtB;AACA,QAAM,WAAO,yBAAQ,EAChB,IAAI,wBAAwB,EAAE,MAAM,OAAO,CAAC,EAC5C,IAAI,uBAAuB,EAC3B,YAAY,EAAE,OAAO,IAAI,CAAC;AAC/B,SAAQ,KAAK,OAAoB;AACrC;",
6
+ "names": ["unifiedLatexAstComplier", "unifiedLatexFromStringMinimal", "parser", "import_unified_latex_util_visit", "import_unified_latex_util_match", "import_unified_latex_util_print_raw", "unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse", "import_unified_latex_util_catcode", "unifiedLatexProcessAtLetterAndExplMacros", "unifiedLatexFromString", "parser", "import_unified", "import_unified", "import_unified_latex_util_print_raw"]
7
7
  }
package/index.js CHANGED
@@ -51,41 +51,57 @@ function unifiedLatexReparseMathConstructPlugin({
51
51
  const isMathEnvironment = match.createEnvironmentMatcher(mathEnvs);
52
52
  const isMathMacro = match.createMacroMatcher(mathMacros);
53
53
  return (tree) => {
54
- visit(tree, (node) => {
55
- if (match.anyMacro(node)) {
56
- for (const arg of node.args || []) {
57
- if (arg.content.length > 0 && !wasParsedInMathMode(arg.content)) {
58
- arg.content = parseMathMinimal(printRaw(arg.content));
54
+ visit(
55
+ tree,
56
+ (node) => {
57
+ if (match.anyMacro(node)) {
58
+ for (const arg of node.args || []) {
59
+ if (arg.content.length > 0 && !wasParsedInMathMode(arg.content)) {
60
+ arg.content = parseMathMinimal(
61
+ printRaw(arg.content)
62
+ );
63
+ }
59
64
  }
60
65
  }
61
- }
62
- if (match.anyEnvironment(node)) {
63
- if (!wasParsedInMathMode(node.content)) {
64
- node.content = parseMathMinimal(printRaw(node.content));
66
+ if (match.anyEnvironment(node)) {
67
+ if (!wasParsedInMathMode(node.content)) {
68
+ node.content = parseMathMinimal(printRaw(node.content));
69
+ }
65
70
  }
71
+ },
72
+ {
73
+ test: (node) => isMathEnvironment(node) || isMathMacro(node)
66
74
  }
67
- }, {
68
- test: (node) => isMathEnvironment(node) || isMathMacro(node)
69
- });
75
+ );
70
76
  };
71
77
  }
72
78
  function wasParsedInMathMode(nodes) {
73
- return !nodes.some((node) => match.anyString(node) && node.content.length > 1 || match.string(node, "^") || match.string(node, "_"));
79
+ return !nodes.some(
80
+ (node) => match.anyString(node) && node.content.length > 1 || match.string(node, "^") || match.string(node, "_")
81
+ );
74
82
  }
75
83
 
76
84
  // libs/process-macros-and-environments.ts
77
85
  import { attachMacroArgsInArray } from "@unified-latex/unified-latex-util-arguments";
78
86
  import { processEnvironment } from "@unified-latex/unified-latex-util-environments";
79
- var unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse = function unifiedLatexAttachMacroArguments(options) {
87
+ var unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse = function unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse2(options) {
80
88
  const { environments = {}, macros = {} } = options || {};
81
- const mathMacros = Object.fromEntries(Object.entries(macros).filter(([_, info]) => {
82
- var _a;
83
- return ((_a = info.renderInfo) == null ? void 0 : _a.inMathMode) === true;
84
- }));
85
- const mathEnvs = Object.fromEntries(Object.entries(environments).filter(([_, info]) => {
86
- var _a;
87
- return ((_a = info.renderInfo) == null ? void 0 : _a.inMathMode) === true;
88
- }));
89
+ const mathMacros = Object.fromEntries(
90
+ Object.entries(macros).filter(
91
+ ([_, info]) => {
92
+ var _a;
93
+ return ((_a = info.renderInfo) == null ? void 0 : _a.inMathMode) === true;
94
+ }
95
+ )
96
+ );
97
+ const mathEnvs = Object.fromEntries(
98
+ Object.entries(environments).filter(
99
+ ([_, info]) => {
100
+ var _a;
101
+ return ((_a = info.renderInfo) == null ? void 0 : _a.inMathMode) === true;
102
+ }
103
+ )
104
+ );
89
105
  const mathReparser = unifiedLatexReparseMathConstructPlugin({
90
106
  mathEnvs: Object.keys(mathEnvs),
91
107
  mathMacros: Object.keys(mathMacros)
@@ -93,45 +109,92 @@ var unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse = function unifiedLa
93
109
  const isRelevantEnvironment = match2.createEnvironmentMatcher(environments);
94
110
  const isRelevantMathEnvironment = match2.createEnvironmentMatcher(mathEnvs);
95
111
  return (tree) => {
96
- visit2(tree, {
97
- enter: (nodes) => {
98
- if (!Array.isArray(nodes)) {
99
- return;
112
+ visit2(
113
+ tree,
114
+ {
115
+ enter: (nodes) => {
116
+ if (!Array.isArray(nodes)) {
117
+ return;
118
+ }
119
+ attachMacroArgsInArray(nodes, mathMacros);
120
+ },
121
+ leave: (node) => {
122
+ if (!isRelevantMathEnvironment(node)) {
123
+ return;
124
+ }
125
+ const envName = printRaw2(node.env);
126
+ const envInfo = environments[envName];
127
+ if (!envInfo) {
128
+ throw new Error(
129
+ `Could not find environment info for environment "${envName}"`
130
+ );
131
+ }
132
+ processEnvironment(node, envInfo);
100
133
  }
101
- attachMacroArgsInArray(nodes, mathMacros);
102
134
  },
103
- leave: (node) => {
104
- if (!isRelevantMathEnvironment(node)) {
105
- return;
106
- }
107
- const envName = printRaw2(node.env);
108
- const envInfo = environments[envName];
109
- if (!envInfo) {
110
- throw new Error(`Could not find environment info for environment "${envName}"`);
111
- }
112
- processEnvironment(node, envInfo);
113
- }
114
- }, { includeArrays: true });
135
+ { includeArrays: true }
136
+ );
115
137
  mathReparser(tree);
116
- visit2(tree, {
117
- enter: (nodes) => {
118
- if (!Array.isArray(nodes)) {
119
- return;
138
+ visit2(
139
+ tree,
140
+ {
141
+ enter: (nodes) => {
142
+ if (!Array.isArray(nodes)) {
143
+ return;
144
+ }
145
+ attachMacroArgsInArray(nodes, macros);
146
+ },
147
+ leave: (node) => {
148
+ if (!isRelevantEnvironment(node)) {
149
+ return;
150
+ }
151
+ const envName = printRaw2(node.env);
152
+ const envInfo = environments[envName];
153
+ if (!envInfo) {
154
+ throw new Error(
155
+ `Could not find environment info for environment "${envName}"`
156
+ );
157
+ }
158
+ processEnvironment(node, envInfo);
120
159
  }
121
- attachMacroArgsInArray(nodes, macros);
122
160
  },
123
- leave: (node) => {
124
- if (!isRelevantEnvironment(node)) {
125
- return;
126
- }
127
- const envName = printRaw2(node.env);
128
- const envInfo = environments[envName];
129
- if (!envInfo) {
130
- throw new Error(`Could not find environment info for environment "${envName}"`);
131
- }
132
- processEnvironment(node, envInfo);
133
- }
134
- }, { includeArrays: true });
161
+ { includeArrays: true }
162
+ );
163
+ };
164
+ };
165
+
166
+ // libs/process-at-letter-and-expl-macros.ts
167
+ import { reparseExpl3AndAtLetterRegions } from "@unified-latex/unified-latex-util-catcode";
168
+ import {
169
+ hasReparsableMacroNames,
170
+ reparseMacroNames
171
+ } from "@unified-latex/unified-latex-util-catcode";
172
+ var unifiedLatexProcessAtLetterAndExplMacros = function unifiedLatexProcessAtLetterAndExplMacros2(options) {
173
+ let {
174
+ atLetter = false,
175
+ expl3 = false,
176
+ autodetectExpl3AndAtLetter = false
177
+ } = options || {};
178
+ return (tree) => {
179
+ reparseExpl3AndAtLetterRegions(tree);
180
+ if (atLetter || expl3) {
181
+ autodetectExpl3AndAtLetter = false;
182
+ }
183
+ if (autodetectExpl3AndAtLetter) {
184
+ atLetter = hasReparsableMacroNames(tree, "@");
185
+ expl3 = hasReparsableMacroNames(tree, "_");
186
+ }
187
+ const charSet = /* @__PURE__ */ new Set();
188
+ if (atLetter) {
189
+ charSet.add("@");
190
+ }
191
+ if (expl3) {
192
+ charSet.add(":");
193
+ charSet.add("_");
194
+ }
195
+ if (charSet.size > 0) {
196
+ reparseMacroNames(tree, charSet);
197
+ }
135
198
  };
136
199
  };
137
200
 
@@ -140,11 +203,28 @@ var unifiedLatexFromString = function unifiedLatexFromString2(options) {
140
203
  const {
141
204
  mode = "regular",
142
205
  macros = {},
143
- environments = {}
206
+ environments = {},
207
+ flags: {
208
+ atLetter = false,
209
+ expl3 = false,
210
+ autodetectExpl3AndAtLetter = false
211
+ } = {}
144
212
  } = options || {};
145
- const allMacroInfo = Object.assign({}, macros, ...Object.values(macroInfo));
146
- const allEnvInfo = Object.assign({}, environments, ...Object.values(environmentInfo));
147
- const fullParser = unified().use(unifiedLatexFromStringMinimal, { mode }).use(unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse, {
213
+ const allMacroInfo = Object.assign(
214
+ {},
215
+ macros,
216
+ ...Object.values(macroInfo)
217
+ );
218
+ const allEnvInfo = Object.assign(
219
+ {},
220
+ environments,
221
+ ...Object.values(environmentInfo)
222
+ );
223
+ const fullParser = unified().use(unifiedLatexFromStringMinimal, { mode }).use(unifiedLatexProcessAtLetterAndExplMacros, {
224
+ atLetter,
225
+ expl3,
226
+ autodetectExpl3AndAtLetter
227
+ }).use(unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse, {
148
228
  macros: allMacroInfo,
149
229
  environments: allEnvInfo
150
230
  }).use(unifiedLatexTrimEnvironmentContents).use(unifiedLatexTrimRoot).use(unifiedLatexAstComplier);
package/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../libs/compiler-ast.ts", "../libs/plugin-from-string.ts", "../libs/parse-minimal.ts", "../libs/plugin-from-string-minimal.ts", "../libs/process-macros-and-environments.ts", "../libs/reparse-math.ts", "../libs/parse.ts", "../libs/parse-math.ts"],
4
- "sourcesContent": ["import { Plugin } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\n\n/**\n * Unified complier plugin that passes through a LaTeX AST without modification.\n */\nexport const unifiedLatexAstComplier: Plugin<void[], Ast.Root, Ast.Root> =\n function unifiedLatexAstComplier() {\n Object.assign(this, { Compiler: (x: Ast.Root) => x });\n };\n", "import { Plugin, Parser, unified } from \"unified\";\nimport { environmentInfo, macroInfo } from \"@unified-latex/unified-latex-ctan\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { EnvInfoRecord, MacroInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport {\n unifiedLatexTrimEnvironmentContents,\n unifiedLatexTrimRoot,\n} from \"@unified-latex/unified-latex-util-trim\";\nimport { unifiedLatexAstComplier } from \"./compiler-ast\";\nimport { unifiedLatexFromStringMinimal } from \"./plugin-from-string-minimal\";\nimport { unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse } from \"./process-macros-and-environments\";\n\nexport type PluginOptions =\n | {\n mode?: \"math\" | \"regular\";\n macros?: MacroInfoRecord;\n environments?: EnvInfoRecord;\n }\n | undefined;\n\n/**\n * Parse a string to a LaTeX AST.\n */\nexport const unifiedLatexFromString: Plugin<PluginOptions[], string, Ast.Root> =\n function unifiedLatexFromString(options) {\n const {\n mode = \"regular\",\n macros = {},\n environments = {},\n } = options || {};\n\n // Build up a parsing plugin with only unified components\n const allMacroInfo: MacroInfoRecord = Object.assign(\n {},\n macros,\n ...Object.values(macroInfo)\n );\n const allEnvInfo: EnvInfoRecord = Object.assign(\n {},\n environments,\n ...Object.values(environmentInfo)\n );\n\n // Build up a parser that will perform all the needed steps\n const fullParser = unified()\n .use(unifiedLatexFromStringMinimal, { mode })\n // Math environments that aren't hardcoded into the PEG grammar need to be re-parsed,\n // so do a minimal pass first with just those environments.\n .use(unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse, {\n macros: allMacroInfo,\n environments: allEnvInfo,\n })\n .use(unifiedLatexTrimEnvironmentContents)\n .use(unifiedLatexTrimRoot)\n .use(unifiedLatexAstComplier);\n\n const parser: Parser<Ast.Root> = (str) => {\n const file = fullParser.processSync({ value: str });\n return file.result;\n };\n\n Object.assign(this, { Parser: parser });\n };\n", "import { LatexPegParser } from \"@unified-latex/unified-latex-util-pegjs\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\n\n/**\n * Parse `str` to an AST with minimal processing. E.g., macro\n * arguments are not attached to macros, etc. when parsed with this\n * function.\n */\nexport function parseMinimal(str: string): Ast.Root {\n return LatexPegParser.parse(str);\n}\n\n/**\n * Parse `str` to an AST with minimal processing. E.g., macro\n * arguments are not attached to macros, etc. when parsed with this\n * function.\n *\n * The parsing assumes a math-mode context, so, for example, `^` and `_` are\n * parsed as macros (even though arguments are not attached to them).\n */\nexport function parseMathMinimal(str: string): Ast.Node[] {\n return LatexPegParser.parse(str, { startRule: \"math\" });\n}\n", "import { Plugin, Parser } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { parseMathMinimal, parseMinimal } from \"./parse-minimal\";\n\ntype PluginOptions = {\n /**\n * Whether the text will be parsed assuming math mode or not.\n */\n mode: \"math\" | \"regular\";\n} | void;\n\n/**\n * Parse a string to a LaTeX AST with no post processing. For example,\n * no macro arguments will be attached, etc.\n */\nexport const unifiedLatexFromStringMinimal: Plugin<\n PluginOptions[],\n string,\n Ast.Root\n> = function unifiedLatexFromStringMinimal(options) {\n const parser: Parser<Ast.Root> = (str) => {\n if (options?.mode === \"math\") {\n return {\n type: \"root\",\n content: parseMathMinimal(str),\n _renderInfo: { inMathMode: true },\n };\n }\n return parseMinimal(str);\n };\n\n Object.assign(this, { Parser: parser });\n};\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { EnvInfoRecord, MacroInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { Plugin } from \"unified\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport {\n unifiedLatexReparseMathConstructPlugin,\n} from \"./reparse-math\";\nimport { attachMacroArgsInArray } from \"@unified-latex/unified-latex-util-arguments\";\nimport { processEnvironment } from \"@unified-latex/unified-latex-util-environments\";\n\ntype PluginOptions =\n | { environments: EnvInfoRecord; macros: MacroInfoRecord }\n | undefined;\n\n/**\n * Unified plugin to process macros and environments. Any environments that contain math content\n * are reparsed (if needed) in math mode.\n */\nexport const unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexAttachMacroArguments(options) {\n const { environments = {}, macros = {} } = options || {};\n\n const mathMacros = Object.fromEntries(\n Object.entries(macros).filter(\n ([_, info]) => info.renderInfo?.inMathMode === true\n )\n );\n const mathEnvs = Object.fromEntries(\n Object.entries(environments).filter(\n ([_, info]) => info.renderInfo?.inMathMode === true\n )\n );\n\n const mathReparser = unifiedLatexReparseMathConstructPlugin({\n mathEnvs: Object.keys(mathEnvs),\n mathMacros: Object.keys(mathMacros),\n });\n\n const isRelevantEnvironment = match.createEnvironmentMatcher(environments);\n const isRelevantMathEnvironment = match.createEnvironmentMatcher(mathEnvs);\n\n return (tree) => {\n // First we attach all arguments/process all nodes/environments that have math content\n visit(\n tree,\n {\n enter: (nodes) => {\n if (!Array.isArray(nodes)) {\n return;\n }\n attachMacroArgsInArray(nodes, mathMacros);\n },\n leave: (node) => {\n if (!isRelevantMathEnvironment(node)) {\n return;\n }\n const envName = printRaw(node.env);\n const envInfo = environments[envName];\n if (!envInfo) {\n throw new Error(\n `Could not find environment info for environment \"${envName}\"`\n );\n }\n processEnvironment(node, envInfo);\n },\n },\n { includeArrays: true }\n );\n\n // Next we reparse macros/envs that may not have been parsed in math mode\n mathReparser(tree);\n\n // Now we attach all arguments/process all environment bodies\n visit(\n tree,\n {\n enter: (nodes) => {\n if (!Array.isArray(nodes)) {\n return;\n }\n attachMacroArgsInArray(nodes, macros);\n },\n leave: (node) => {\n if (!isRelevantEnvironment(node)) {\n return;\n }\n const envName = printRaw(node.env);\n const envInfo = environments[envName];\n if (!envInfo) {\n throw new Error(\n `Could not find environment info for environment \"${envName}\"`\n );\n }\n processEnvironment(node, envInfo);\n },\n },\n { includeArrays: true }\n );\n };\n};\n", "import { Plugin } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { parseMathMinimal } from \"./parse-minimal\";\n\ntype PluginOptions =\n | {\n /**\n * List of environments whose body should be parsed in math mode\n */\n mathEnvs: string[];\n /**\n * List of macros whose bodies should be parsed in math mode\n */\n mathMacros: string[];\n }\n | undefined;\n\n/**\n * Reparse math environments/macro contents that should have been parsed in math mode but weren't.\n */\nexport const unifiedLatexReparseMath: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexReparseMath(options) {\n const { mathEnvs = [], mathMacros = [] } = options || {};\n\n return unifiedLatexReparseMathConstructPlugin({ mathMacros, mathEnvs });\n};\n\n/**\n * Construct the inner function for the `unifiedLatexReparseMath` plugin. This function should not be used by libraries.\n */\nexport function unifiedLatexReparseMathConstructPlugin({\n mathEnvs,\n mathMacros,\n}: {\n mathEnvs: string[];\n mathMacros: string[];\n}) {\n const isMathEnvironment = match.createEnvironmentMatcher(mathEnvs);\n const isMathMacro = match.createMacroMatcher(mathMacros);\n\n return (tree: Ast.Root) => {\n visit(\n tree,\n (node) => {\n if (match.anyMacro(node)) {\n for (const arg of node.args || []) {\n if (\n arg.content.length > 0 &&\n !wasParsedInMathMode(arg.content)\n ) {\n arg.content = parseMathMinimal(\n printRaw(arg.content)\n );\n }\n }\n }\n if (match.anyEnvironment(node)) {\n if (!wasParsedInMathMode(node.content)) {\n node.content = parseMathMinimal(printRaw(node.content));\n }\n }\n },\n {\n test: (node) => isMathEnvironment(node) || isMathMacro(node),\n }\n );\n };\n}\n\n/**\n * Use a heuristic to decide whether a string was parsed in math mode. The heuristic\n * looks for strings of length greater than 1 or the failure for \"_\" and \"^\" to be parsed\n * as a macro.\n */\nfunction wasParsedInMathMode(nodes: Ast.Node[]): boolean {\n return !nodes.some(\n (node) =>\n // If there are multi-char strings or ^ and _ have been parsed as strings, we know\n // that we were not parsed in math mode.\n (match.anyString(node) && node.content.length > 1) ||\n match.string(node, \"^\") ||\n match.string(node, \"_\")\n );\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { unified } from \"unified\";\nimport { unifiedLatexFromString } from \"./plugin-from-string\";\n\nconst parser = unified().use(unifiedLatexFromString).freeze();\n\n/**\n * Parse the string into an AST.\n */\nexport function parse(str: string): Ast.Root {\n return parser.parse(str);\n}\n", "import { unified } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport { unifiedLatexAstComplier } from \"./compiler-ast\";\nimport { unifiedLatexFromString } from \"./plugin-from-string\";\n\n/**\n * Parse `str` into an AST. Parsing starts in math mode and a list of\n * nodes is returned (instead of a \"root\" node).\n */\nexport function parseMath(str: string | Ast.Ast): Ast.Node[] {\n if (typeof str !== \"string\") {\n str = printRaw(str);\n }\n const file = unified()\n .use(unifiedLatexFromString, { mode: \"math\" })\n .use(unifiedLatexAstComplier)\n .processSync({ value: str });\n return (file.result as Ast.Root).content;\n}\n"],
5
- "mappings": ";AAMO,IAAM,0BACT,oCAAmC;AAC/B,SAAO,OAAO,MAAM,EAAE,UAAU,CAAC,MAAgB,EAAE,CAAC;AAC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E,OAAO;AAKrD,eAAe,KAAuB;AACzC,SAAO,OAAO,MAAM,GAAG;AAC3B;;;ACXA;AAEA;AAQO,mBAAmB,KAAmC;AACzD,MAAI,OAAO,QAAQ,UAAU;AACzB,UAAM,UAAS,GAAG;AAAA,EACtB;AACA,QAAM,OAAO,SAAQ,EAChB,IAAI,wBAAwB,EAAE,MAAM,OAAO,CAAC,EAC5C,IAAI,uBAAuB,EAC3B,YAAY,EAAE,OAAO,IAAI,CAAC;AAC/B,SAAQ,KAAK,OAAoB;AACrC;",
6
- "names": []
3
+ "sources": ["../libs/compiler-ast.ts", "../libs/plugin-from-string.ts", "../libs/parse-minimal.ts", "../libs/plugin-from-string-minimal.ts", "../libs/process-macros-and-environments.ts", "../libs/reparse-math.ts", "../libs/process-at-letter-and-expl-macros.ts", "../libs/parse.ts", "../libs/parse-math.ts"],
4
+ "sourcesContent": ["import { Plugin } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\n\n/**\n * Unified complier plugin that passes through a LaTeX AST without modification.\n */\nexport const unifiedLatexAstComplier: Plugin<void[], Ast.Root, Ast.Root> =\n function unifiedLatexAstComplier() {\n Object.assign(this, { Compiler: (x: Ast.Root) => x });\n };\n", "import { Plugin, Parser, unified } from \"unified\";\nimport { environmentInfo, macroInfo } from \"@unified-latex/unified-latex-ctan\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport {\n EnvInfoRecord,\n MacroInfoRecord,\n} from \"@unified-latex/unified-latex-types\";\nimport {\n unifiedLatexTrimEnvironmentContents,\n unifiedLatexTrimRoot,\n} from \"@unified-latex/unified-latex-util-trim\";\nimport { unifiedLatexAstComplier } from \"./compiler-ast\";\nimport { unifiedLatexFromStringMinimal } from \"./plugin-from-string-minimal\";\nimport { unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse } from \"./process-macros-and-environments\";\nimport { unifiedLatexProcessAtLetterAndExplMacros } from \"./process-at-letter-and-expl-macros\";\n\nexport type PluginOptions =\n | {\n mode?: \"math\" | \"regular\";\n macros?: MacroInfoRecord;\n environments?: EnvInfoRecord;\n flags?: {\n /**\n * Whether to parse macros as if `\\makeatletter` is set (i.e., parse `@` as a regular macro character)\n */\n atLetter?: boolean;\n /**\n * Whether to parse macros as if `\\ExplSyntaxOn` is set (i.e., parse `_` and `:` as a regular macro character)\n */\n expl3?: boolean;\n /**\n * Attempt to autodetect whether there are macros that look like they should contain `@`, `_`, or `:`.\n * Defaults to `false`.\n */\n autodetectExpl3AndAtLetter?: boolean;\n };\n }\n | undefined;\n\n/**\n * Parse a string to a LaTeX AST.\n */\nexport const unifiedLatexFromString: Plugin<PluginOptions[], string, Ast.Root> =\n function unifiedLatexFromString(options) {\n const {\n mode = \"regular\",\n macros = {},\n environments = {},\n flags: {\n atLetter = false,\n expl3 = false,\n autodetectExpl3AndAtLetter = false,\n } = {},\n } = options || {};\n\n // Build up a parsing plugin with only unified components\n const allMacroInfo: MacroInfoRecord = Object.assign(\n {},\n macros,\n ...Object.values(macroInfo)\n );\n const allEnvInfo: EnvInfoRecord = Object.assign(\n {},\n environments,\n ...Object.values(environmentInfo)\n );\n\n // Build up a parser that will perform all the needed steps\n const fullParser = unified()\n .use(unifiedLatexFromStringMinimal, { mode })\n .use(unifiedLatexProcessAtLetterAndExplMacros, {\n atLetter,\n expl3,\n autodetectExpl3AndAtLetter,\n })\n // Math environments that aren't hardcoded into the PEG grammar need to be re-parsed,\n // so do a minimal pass first with just those environments.\n .use(unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse, {\n macros: allMacroInfo,\n environments: allEnvInfo,\n })\n .use(unifiedLatexTrimEnvironmentContents)\n .use(unifiedLatexTrimRoot)\n .use(unifiedLatexAstComplier);\n\n const parser: Parser<Ast.Root> = (str) => {\n const file = fullParser.processSync({ value: str });\n return file.result;\n };\n\n Object.assign(this, { Parser: parser });\n };\n", "import { LatexPegParser } from \"@unified-latex/unified-latex-util-pegjs\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\n\n/**\n * Parse `str` to an AST with minimal processing. E.g., macro\n * arguments are not attached to macros, etc. when parsed with this\n * function.\n */\nexport function parseMinimal(str: string): Ast.Root {\n return LatexPegParser.parse(str);\n}\n\n/**\n * Parse `str` to an AST with minimal processing. E.g., macro\n * arguments are not attached to macros, etc. when parsed with this\n * function.\n *\n * The parsing assumes a math-mode context, so, for example, `^` and `_` are\n * parsed as macros (even though arguments are not attached to them).\n */\nexport function parseMathMinimal(str: string): Ast.Node[] {\n return LatexPegParser.parse(str, { startRule: \"math\" });\n}\n", "import { Plugin, Parser } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { parseMathMinimal, parseMinimal } from \"./parse-minimal\";\n\ntype PluginOptions = {\n /**\n * Whether the text will be parsed assuming math mode or not.\n */\n mode: \"math\" | \"regular\";\n} | void;\n\n/**\n * Parse a string to a LaTeX AST with no post processing. For example,\n * no macro arguments will be attached, etc.\n */\nexport const unifiedLatexFromStringMinimal: Plugin<\n PluginOptions[],\n string,\n Ast.Root\n> = function unifiedLatexFromStringMinimal(options) {\n const parser: Parser<Ast.Root> = (str) => {\n if (options?.mode === \"math\") {\n return {\n type: \"root\",\n content: parseMathMinimal(str),\n _renderInfo: { inMathMode: true },\n };\n }\n return parseMinimal(str);\n };\n\n Object.assign(this, { Parser: parser });\n};\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { EnvInfoRecord, MacroInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { Plugin } from \"unified\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport {\n unifiedLatexReparseMathConstructPlugin,\n} from \"./reparse-math\";\nimport { attachMacroArgsInArray } from \"@unified-latex/unified-latex-util-arguments\";\nimport { processEnvironment } from \"@unified-latex/unified-latex-util-environments\";\n\ntype PluginOptions =\n | { environments: EnvInfoRecord; macros: MacroInfoRecord }\n | undefined;\n\n/**\n * Unified plugin to process macros and environments. Any environments that contain math content\n * are reparsed (if needed) in math mode.\n */\nexport const unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse(options) {\n const { environments = {}, macros = {} } = options || {};\n\n const mathMacros = Object.fromEntries(\n Object.entries(macros).filter(\n ([_, info]) => info.renderInfo?.inMathMode === true\n )\n );\n const mathEnvs = Object.fromEntries(\n Object.entries(environments).filter(\n ([_, info]) => info.renderInfo?.inMathMode === true\n )\n );\n\n const mathReparser = unifiedLatexReparseMathConstructPlugin({\n mathEnvs: Object.keys(mathEnvs),\n mathMacros: Object.keys(mathMacros),\n });\n\n const isRelevantEnvironment = match.createEnvironmentMatcher(environments);\n const isRelevantMathEnvironment = match.createEnvironmentMatcher(mathEnvs);\n\n return (tree) => {\n // First we attach all arguments/process all nodes/environments that have math content\n visit(\n tree,\n {\n enter: (nodes) => {\n if (!Array.isArray(nodes)) {\n return;\n }\n attachMacroArgsInArray(nodes, mathMacros);\n },\n leave: (node) => {\n if (!isRelevantMathEnvironment(node)) {\n return;\n }\n const envName = printRaw(node.env);\n const envInfo = environments[envName];\n if (!envInfo) {\n throw new Error(\n `Could not find environment info for environment \"${envName}\"`\n );\n }\n processEnvironment(node, envInfo);\n },\n },\n { includeArrays: true }\n );\n\n // Next we reparse macros/envs that may not have been parsed in math mode\n mathReparser(tree);\n\n // Now we attach all arguments/process all environment bodies\n visit(\n tree,\n {\n enter: (nodes) => {\n if (!Array.isArray(nodes)) {\n return;\n }\n attachMacroArgsInArray(nodes, macros);\n },\n leave: (node) => {\n if (!isRelevantEnvironment(node)) {\n return;\n }\n const envName = printRaw(node.env);\n const envInfo = environments[envName];\n if (!envInfo) {\n throw new Error(\n `Could not find environment info for environment \"${envName}\"`\n );\n }\n processEnvironment(node, envInfo);\n },\n },\n { includeArrays: true }\n );\n };\n};\n", "import { Plugin } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { parseMathMinimal } from \"./parse-minimal\";\n\ntype PluginOptions =\n | {\n /**\n * List of environments whose body should be parsed in math mode\n */\n mathEnvs: string[];\n /**\n * List of macros whose bodies should be parsed in math mode\n */\n mathMacros: string[];\n }\n | undefined;\n\n/**\n * Reparse math environments/macro contents that should have been parsed in math mode but weren't.\n */\nexport const unifiedLatexReparseMath: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexReparseMath(options) {\n const { mathEnvs = [], mathMacros = [] } = options || {};\n\n return unifiedLatexReparseMathConstructPlugin({ mathMacros, mathEnvs });\n};\n\n/**\n * Construct the inner function for the `unifiedLatexReparseMath` plugin. This function should not be used by libraries.\n */\nexport function unifiedLatexReparseMathConstructPlugin({\n mathEnvs,\n mathMacros,\n}: {\n mathEnvs: string[];\n mathMacros: string[];\n}) {\n const isMathEnvironment = match.createEnvironmentMatcher(mathEnvs);\n const isMathMacro = match.createMacroMatcher(mathMacros);\n\n return (tree: Ast.Root) => {\n visit(\n tree,\n (node) => {\n if (match.anyMacro(node)) {\n for (const arg of node.args || []) {\n if (\n arg.content.length > 0 &&\n !wasParsedInMathMode(arg.content)\n ) {\n arg.content = parseMathMinimal(\n printRaw(arg.content)\n );\n }\n }\n }\n if (match.anyEnvironment(node)) {\n if (!wasParsedInMathMode(node.content)) {\n node.content = parseMathMinimal(printRaw(node.content));\n }\n }\n },\n {\n test: (node) => isMathEnvironment(node) || isMathMacro(node),\n }\n );\n };\n}\n\n/**\n * Use a heuristic to decide whether a string was parsed in math mode. The heuristic\n * looks for strings of length greater than 1 or the failure for \"_\" and \"^\" to be parsed\n * as a macro.\n */\nfunction wasParsedInMathMode(nodes: Ast.Node[]): boolean {\n return !nodes.some(\n (node) =>\n // If there are multi-char strings or ^ and _ have been parsed as strings, we know\n // that we were not parsed in math mode.\n (match.anyString(node) && node.content.length > 1) ||\n match.string(node, \"^\") ||\n match.string(node, \"_\")\n );\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { Plugin } from \"unified\";\nimport { reparseExpl3AndAtLetterRegions } from \"@unified-latex/unified-latex-util-catcode\";\nimport {\n hasReparsableMacroNames,\n reparseMacroNames,\n} from \"@unified-latex/unified-latex-util-catcode\";\n\ntype PluginOptions =\n | {\n /**\n * Whether to parse macros as if `\\makeatletter` is set (i.e., parse `@` as a regular macro character).\n * If this option is true, it disables autodetect.\n */\n atLetter?: boolean;\n /**\n * Whether to parse macros as if `\\ExplSyntaxOn` is set (i.e., parse `_` and `:` as a regular macro character)\n * If this option is true, it disables autodetect.\n */\n expl3?: boolean;\n /**\n * Attempt to autodetect whether there are macros that look like they should contain `@`, `_`, or `:`.\n * Defaults to `true`.\n */\n autodetectExpl3AndAtLetter?: boolean;\n }\n | undefined;\n\n/**\n * Unified plugin to reprocess macros names to possibly include `@`, `_`, or `:`.\n * This plugin detects the `\\makeatletter` and `\\ExplSyntaxOn` commands and reprocesses macro names\n * inside of those blocks to include those characters.\n */\nexport const unifiedLatexProcessAtLetterAndExplMacros: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexProcessAtLetterAndExplMacros(options) {\n let {\n atLetter = false,\n expl3 = false,\n autodetectExpl3AndAtLetter = false,\n } = options || {};\n\n return (tree) => {\n // First we reparse based on explicit \\makeatletter and \\ExplSyntaxOn macros\n reparseExpl3AndAtLetterRegions(tree);\n if (atLetter || expl3) {\n autodetectExpl3AndAtLetter = false;\n }\n if (autodetectExpl3AndAtLetter) {\n atLetter = hasReparsableMacroNames(tree, \"@\");\n // We don't check for the `:` here because it could be prone to misidentification.\n expl3 = hasReparsableMacroNames(tree, \"_\");\n }\n const charSet: Set<string> = new Set();\n if (atLetter) {\n charSet.add(\"@\");\n }\n if (expl3) {\n charSet.add(\":\");\n charSet.add(\"_\");\n }\n\n if (charSet.size > 0) {\n reparseMacroNames(tree, charSet);\n }\n };\n};\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { unified } from \"unified\";\nimport { unifiedLatexFromString } from \"./plugin-from-string\";\n\nconst parser = unified().use(unifiedLatexFromString).freeze();\n\n/**\n * Parse the string into an AST.\n */\nexport function parse(str: string): Ast.Root {\n return parser.parse(str);\n}\n", "import { unified } from \"unified\";\nimport * as Ast from \"@unified-latex/unified-latex-types\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\nimport { unifiedLatexAstComplier } from \"./compiler-ast\";\nimport { unifiedLatexFromString } from \"./plugin-from-string\";\n\n/**\n * Parse `str` into an AST. Parsing starts in math mode and a list of\n * nodes is returned (instead of a \"root\" node).\n */\nexport function parseMath(str: string | Ast.Ast): Ast.Node[] {\n if (typeof str !== \"string\") {\n str = printRaw(str);\n }\n const file = unified()\n .use(unifiedLatexFromString, { mode: \"math\" })\n .use(unifiedLatexAstComplier)\n .processSync({ value: str });\n return (file.result as Ast.Root).content;\n}\n"],
5
+ "mappings": ";AAMO,IAAM,0BACT,SAASA,2BAA0B;AAC/B,SAAO,OAAO,MAAM,EAAE,UAAU,CAAC,MAAgB,EAAE,CAAC;AACxD;;;ACTJ,SAAyB,eAAe;AACxC,SAAS,iBAAiB,iBAAiB;AAM3C;AAAA,EACI;AAAA,EACA;AAAA,OACG;;;ACVP,SAAS,sBAAsB;AAQxB,SAAS,aAAa,KAAuB;AAChD,SAAO,eAAe,MAAM,GAAG;AACnC;AAUO,SAAS,iBAAiB,KAAyB;AACtD,SAAO,eAAe,MAAM,KAAK,EAAE,WAAW,OAAO,CAAC;AAC1D;;;ACPO,IAAM,gCAIT,SAASC,+BAA8B,SAAS;AAChD,QAAMC,UAA2B,CAAC,QAAQ;AACtC,SAAI,mCAAS,UAAS,QAAQ;AAC1B,aAAO;AAAA,QACH,MAAM;AAAA,QACN,SAAS,iBAAiB,GAAG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B,EAC3B,YAAY,EAAE,OAAO,IAAI,CAAC;AAC/B,SAAQ,KAAK,OAAoB;AACrC;",
6
+ "names": ["unifiedLatexAstComplier", "unifiedLatexFromStringMinimal", "parser", "visit", "match", "printRaw", "unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse", "match", "visit", "printRaw", "unifiedLatexProcessAtLetterAndExplMacros", "unifiedLatexFromString", "parser", "unified", "unified", "unified", "printRaw", "printRaw", "unified"]
7
7
  }
@@ -5,6 +5,21 @@ export declare type PluginOptions = {
5
5
  mode?: "math" | "regular";
6
6
  macros?: MacroInfoRecord;
7
7
  environments?: EnvInfoRecord;
8
+ flags?: {
9
+ /**
10
+ * Whether to parse macros as if `\makeatletter` is set (i.e., parse `@` as a regular macro character)
11
+ */
12
+ atLetter?: boolean;
13
+ /**
14
+ * Whether to parse macros as if `\ExplSyntaxOn` is set (i.e., parse `_` and `:` as a regular macro character)
15
+ */
16
+ expl3?: boolean;
17
+ /**
18
+ * Attempt to autodetect whether there are macros that look like they should contain `@`, `_`, or `:`.
19
+ * Defaults to `false`.
20
+ */
21
+ autodetectExpl3AndAtLetter?: boolean;
22
+ };
8
23
  } | undefined;
9
24
  /**
10
25
  * Parse a string to a LaTeX AST.
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-from-string.d.ts","sourceRoot":"","sources":["../../libs/plugin-from-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmB,MAAM,SAAS,CAAC;AAElD,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AASpF,oBAAY,aAAa,GACnB;IACI,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,YAAY,CAAC,EAAE,aAAa,CAAC;CAChC,GACD,SAAS,CAAC;AAEhB;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,CAuCxE,CAAC"}
1
+ {"version":3,"file":"plugin-from-string.d.ts","sourceRoot":"","sources":["../../libs/plugin-from-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAmB,MAAM,SAAS,CAAC;AAElD,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAC1D,OAAO,EACH,aAAa,EACb,eAAe,EAClB,MAAM,oCAAoC,CAAC;AAU5C,oBAAY,aAAa,GACnB;IACI,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB,YAAY,CAAC,EAAE,aAAa,CAAC;IAC7B,KAAK,CAAC,EAAE;QACJ;;WAEG;QACH,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB;;WAEG;QACH,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB;;;WAGG;QACH,0BAA0B,CAAC,EAAE,OAAO,CAAC;KACxC,CAAC;CACL,GACD,SAAS,CAAC;AAEhB;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,aAAa,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,IAAI,CAiDxE,CAAC"}
@@ -0,0 +1,27 @@
1
+ import * as Ast from "@unified-latex/unified-latex-types";
2
+ import { Plugin } from "unified";
3
+ declare type PluginOptions = {
4
+ /**
5
+ * Whether to parse macros as if `\makeatletter` is set (i.e., parse `@` as a regular macro character).
6
+ * If this option is true, it disables autodetect.
7
+ */
8
+ atLetter?: boolean;
9
+ /**
10
+ * Whether to parse macros as if `\ExplSyntaxOn` is set (i.e., parse `_` and `:` as a regular macro character)
11
+ * If this option is true, it disables autodetect.
12
+ */
13
+ expl3?: boolean;
14
+ /**
15
+ * Attempt to autodetect whether there are macros that look like they should contain `@`, `_`, or `:`.
16
+ * Defaults to `true`.
17
+ */
18
+ autodetectExpl3AndAtLetter?: boolean;
19
+ } | undefined;
20
+ /**
21
+ * Unified plugin to reprocess macros names to possibly include `@`, `_`, or `:`.
22
+ * This plugin detects the `\makeatletter` and `\ExplSyntaxOn` commands and reprocesses macro names
23
+ * inside of those blocks to include those characters.
24
+ */
25
+ export declare const unifiedLatexProcessAtLetterAndExplMacros: Plugin<PluginOptions[], Ast.Root, Ast.Root>;
26
+ export {};
27
+ //# sourceMappingURL=process-at-letter-and-expl-macros.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-at-letter-and-expl-macros.d.ts","sourceRoot":"","sources":["../../libs/process-at-letter-and-expl-macros.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAOjC,aAAK,aAAa,GACZ;IACI;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;OAGG;IACH,0BAA0B,CAAC,EAAE,OAAO,CAAC;CACxC,GACD,SAAS,CAAC;AAEhB;;;;GAIG;AACH,eAAO,MAAM,wCAAwC,EAAE,MAAM,CACzD,aAAa,EAAE,EACf,GAAG,CAAC,IAAI,EACR,GAAG,CAAC,IAAI,CAgCX,CAAC"}
package/package.json CHANGED
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "name": "@unified-latex/unified-latex-util-parse",
3
- "version": "1.0.12",
3
+ "version": "1.2.0",
4
4
  "description": "Tools for manipulating unified-latex ASTs",
5
5
  "main": "index.js",
6
6
  "type": "module",
7
7
  "dependencies": {
8
- "@unified-latex/unified-latex-ctan": "^1.0.12",
9
- "@unified-latex/unified-latex-types": "^1.0.12",
10
- "@unified-latex/unified-latex-util-arguments": "^1.0.12",
11
- "@unified-latex/unified-latex-util-environments": "^1.0.12",
12
- "@unified-latex/unified-latex-util-match": "^1.0.12",
13
- "@unified-latex/unified-latex-util-pegjs": "^1.0.12",
14
- "@unified-latex/unified-latex-util-print-raw": "^1.0.12",
15
- "@unified-latex/unified-latex-util-trim": "^1.0.12",
16
- "@unified-latex/unified-latex-util-visit": "^1.0.12",
8
+ "@unified-latex/unified-latex-ctan": "^1.2.0",
9
+ "@unified-latex/unified-latex-types": "^1.2.0",
10
+ "@unified-latex/unified-latex-util-arguments": "^1.2.0",
11
+ "@unified-latex/unified-latex-util-catcode": "^1.2.0",
12
+ "@unified-latex/unified-latex-util-environments": "^1.2.0",
13
+ "@unified-latex/unified-latex-util-match": "^1.2.0",
14
+ "@unified-latex/unified-latex-util-pegjs": "^1.2.0",
15
+ "@unified-latex/unified-latex-util-print-raw": "^1.2.0",
16
+ "@unified-latex/unified-latex-util-trim": "^1.2.0",
17
+ "@unified-latex/unified-latex-util-visit": "^1.2.0",
17
18
  "unified": "^10.1.2"
18
19
  },
19
20
  "repository": {