@unified-latex/unified-latex-util-parse 1.0.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 ADDED
@@ -0,0 +1,194 @@
1
+ <!-- DO NOT MODIFY -->
2
+ <!-- This file was autogenerated by build-docs.ts -->
3
+ <!-- Edit the docstring in index.ts and regenerate -->
4
+ <!-- rather than editing this file directly. -->
5
+ # unified-latex-util-parse
6
+
7
+ ## What is this?
8
+
9
+ Functions parse strings to a `unified-latex` Abstract Syntax Tree (AST).
10
+
11
+ ## When should I use this?
12
+
13
+ If you have a string that you would like to parse to a `unified-latex` `Ast.Ast`, or
14
+ if you are building a plugin for `unified()` that manipulates LaTeX.
15
+
16
+ # Plugins
17
+
18
+ ## `unifiedLatexAstComplier`
19
+
20
+ Unified complier plugin that passes through a LaTeX AST without modification.
21
+
22
+ ### Usage
23
+
24
+ `unified().use(unifiedLatexAstComplier)`
25
+
26
+ ### Type
27
+
28
+ `Plugin<void[], Ast.Root, Ast.Root>`
29
+
30
+ ```typescript
31
+ function unifiedLatexAstComplier(): void;
32
+ ```
33
+
34
+ ## `unifiedLatexFromString`
35
+
36
+ Parse a string to a LaTeX AST.
37
+
38
+ ### Usage
39
+
40
+ `unified().use(unifiedLatexFromString[, options])`
41
+
42
+ #### options
43
+
44
+ ```typescript
45
+ { mode?: "math" | "regular"; macros?: Ast.MacroInfoRecord; environments?: Ast.EnvInfoRecord; }
46
+ ```
47
+
48
+ ### Type
49
+
50
+ `Plugin<{ mode?: "math" | "regular"; macros?: Ast.MacroInfoRecord; environments?: Ast.EnvInfoRecord; }[], string, Ast.Root>`
51
+
52
+ ```typescript
53
+ function unifiedLatexFromString(options: {
54
+ mode?: "math" | "regular";
55
+ macros?: Ast.MacroInfoRecord;
56
+ environments?: Ast.EnvInfoRecord;
57
+ }): void;
58
+ ```
59
+
60
+ ## `unifiedLatexFromStringMinimal`
61
+
62
+ Parse a string to a LaTeX AST with no post processing. For example,
63
+ no macro arguments will be attached, etc.
64
+
65
+ ### Usage
66
+
67
+ `unified().use(unifiedLatexFromStringMinimal[, options])`
68
+
69
+ #### options
70
+
71
+ ```typescript
72
+ PluginOptions
73
+ ```
74
+
75
+ ### Type
76
+
77
+ `Plugin<PluginOptions[], string, Ast.Root>`
78
+
79
+ ```typescript
80
+ function unifiedLatexFromStringMinimal(options: PluginOptions): void;
81
+ ```
82
+
83
+ ## `unifiedLatexStringComplier`
84
+
85
+ Unified complier plugin that prints a LaTeX AST as a string.
86
+
87
+ ### Usage
88
+
89
+ `unified().use(unifiedLatexStringComplier[, options])`
90
+
91
+ #### options
92
+
93
+ ```typescript
94
+ { pretty?: boolean; printWidth?: number; useTabs?: boolean; }
95
+ ```
96
+
97
+ ### Type
98
+
99
+ `Plugin<{ pretty?: boolean; printWidth?: number; useTabs?: boolean; }[], Ast.Root, string>`
100
+
101
+ ```typescript
102
+ function unifiedLatexStringComplier(options: {
103
+ pretty?: boolean;
104
+ printWidth?: number;
105
+ useTabs?: boolean;
106
+ }): void;
107
+ ```
108
+
109
+ # Functions
110
+
111
+ ## `parse(str)`
112
+
113
+ Parse the string into an AST.
114
+
115
+ ```typescript
116
+ function parse(str: String): Ast.Root;
117
+ ```
118
+
119
+ **Parameters**
120
+
121
+ | Param | Type |
122
+ | :---- | :------- |
123
+ | str | `String` |
124
+
125
+ ## `parseMath(str)`
126
+
127
+ Parse `str` into an AST. Parsing starts in math mode and a list of
128
+ nodes is returned (instead of a "root" node).
129
+
130
+ ```typescript
131
+ function parseMath(str: string | Ast.Ast): Ast.Node[];
132
+ ```
133
+
134
+ **Parameters**
135
+
136
+ | Param | Type |
137
+ | :---- | :------------------ |
138
+ | str | `string \| Ast.Ast` |
139
+
140
+ ## `parseMathMinimal(str)`
141
+
142
+ Parse `str` to an AST with minimal processing. E.g., macro
143
+ arguments are not attached to macros, etc. when parsed with this
144
+ function.
145
+
146
+ The parsing assumes a math-mode context, so, for example, `^` and `_` are
147
+ parsed as macros (even though arguments are not attached to them).
148
+
149
+ ```typescript
150
+ function parseMathMinimal(str: String): Ast.Node[];
151
+ ```
152
+
153
+ **Parameters**
154
+
155
+ | Param | Type |
156
+ | :---- | :------- |
157
+ | str | `String` |
158
+
159
+ ## `parseMinimal(str)`
160
+
161
+ Parse `str` to an AST with minimal processing. E.g., macro
162
+ arguments are not attached to macros, etc. when parsed with this
163
+ function.
164
+
165
+ ```typescript
166
+ function parseMinimal(str: String): Ast.Root;
167
+ ```
168
+
169
+ **Parameters**
170
+
171
+ | Param | Type |
172
+ | :---- | :------- |
173
+ | str | `String` |
174
+
175
+ # Constants
176
+
177
+ | Name | Type | Description |
178
+ | :---------------------------- | :------------------------------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------- |
179
+ | `processLatexToAstViaUnified` | `() => Processor<Root, Root, Root, void>` | Use `unified()` to a string to an `Ast.Ast` and then return it. This function&#xA;will not print/pretty-print the `Ast.Ast` back to a string. |
180
+ | `processLatexViaUnified` | `() => Processor<Root, Root, Root, string>` | Use `unified()` to a string to an `Ast.Ast` and then pretty-print it. |
181
+
182
+ # Types
183
+
184
+ ## `PluginOptions`
185
+
186
+ ```typescript
187
+ export type PluginOptions =
188
+ | {
189
+ mode?: "math" | "regular";
190
+ macros?: MacroInfoRecord;
191
+ environments?: EnvInfoRecord;
192
+ }
193
+ | undefined;
194
+ ```
@@ -0,0 +1,7 @@
1
+ {
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", "../../unified-latex-util-environments/libs/process-environment.ts", "../../unified-latex-util-environments/libs/unified-latex-process-environment.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 { EnvInfo, EnvInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { updateRenderInfo } from \"@unified-latex/unified-latex-util-render-info\";\nimport { gobbleArguments } from \"@unified-latex/unified-latex-util-arguments\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\n\n/**\n * Performs any needed processing on the environment (as specified by `envInfo`)\n * include attaching arguments and possibly manipulating the environment's body.\n */\nexport function processEnvironment(envNode: Ast.Environment, envInfo: EnvInfo) {\n if (envInfo.signature && envNode.args == null) {\n const { args } = gobbleArguments(envNode.content, envInfo.signature);\n envNode.args = args;\n }\n\n updateRenderInfo(envNode, envInfo.renderInfo);\n if (typeof envInfo.processContent === \"function\") {\n envNode.content = envInfo.processContent(envNode.content);\n }\n}\n\n/**\n * Recursively search for and process the specified environments. Arguments are\n * consumed according to the `signature` specified. The body is processed\n * with the specified `processContent` function (if given). Any specified `renderInfo`\n * is attached to the environment node.\n */\nexport function processEnvironments(\n tree: Ast.Ast,\n environments: EnvInfoRecord\n) {\n const isRelevantEnvironment = match.createEnvironmentMatcher(environments);\n\n visit(\n tree,\n {\n leave: (node) => {\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 { test: isRelevantEnvironment }\n );\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { EnvInfoRecord } 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 { processEnvironment } from \"./process-environment\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\n\ntype PluginOptions = { environments: EnvInfoRecord } | undefined;\n\n/**\n * Unified plugin to process environment content and attach arguments.\n *\n * @param environments An object whose keys are environment names and values contains information about the environment and its argument signature.\n */\nexport const unifiedLatexProcessEnvironments: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexAttachMacroArguments(options) {\n const { environments = {} } = options || {};\n const isRelevantEnvironment = match.createEnvironmentMatcher(environments);\n\n return (tree) => {\n if (Object.keys(environments).length === 0) {\n console.warn(\n \"Attempting to attach macro arguments but no macros are specified.\"\n );\n }\n\n visit(\n tree,\n {\n leave: (node) => {\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 { test: isRelevantEnvironment }\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,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,gDAA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C;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": []
7
+ }
@@ -0,0 +1,17 @@
1
+ export * from "./libs/compiler-ast";
2
+ export * from "./libs/plugin-from-string";
3
+ export * from "./libs/plugin-from-string-minimal";
4
+ export * from "./libs/parse-minimal";
5
+ export * from "./libs/parse";
6
+ export * from "./libs/parse-math";
7
+ /**
8
+ * ## What is this?
9
+ *
10
+ * Functions parse strings to a `unified-latex` Abstract Syntax Tree (AST).
11
+ *
12
+ * ## When should I use this?
13
+ *
14
+ * If you have a string that you would like to parse to a `unified-latex` `Ast.Ast`, or
15
+ * if you are building a plugin for `unified()` that manipulates LaTeX.
16
+ */
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mCAAmC,CAAC;AAClD,cAAc,sBAAsB,CAAC;AACrC,cAAc,cAAc,CAAC;AAC7B,cAAc,mBAAmB,CAAC;AAGlC;;;;;;;;;GASG"}
package/dist/index.js ADDED
@@ -0,0 +1,205 @@
1
+ // libs/compiler-ast.ts
2
+ var unifiedLatexAstComplier = function unifiedLatexAstComplier2() {
3
+ Object.assign(this, { Compiler: (x) => x });
4
+ };
5
+
6
+ // libs/plugin-from-string.ts
7
+ import { unified } from "unified";
8
+ import { environmentInfo, macroInfo } from "@unified-latex/unified-latex-ctan";
9
+ import {
10
+ unifiedLatexTrimEnvironmentContents,
11
+ unifiedLatexTrimRoot
12
+ } from "@unified-latex/unified-latex-util-trim";
13
+
14
+ // libs/parse-minimal.ts
15
+ import { LatexPegParser } from "@unified-latex/unified-latex-util-pegjs";
16
+ function parseMinimal(str) {
17
+ return LatexPegParser.parse(str);
18
+ }
19
+ function parseMathMinimal(str) {
20
+ return LatexPegParser.parse(str, { startRule: "math" });
21
+ }
22
+
23
+ // libs/plugin-from-string-minimal.ts
24
+ var unifiedLatexFromStringMinimal = function unifiedLatexFromStringMinimal2(options) {
25
+ const parser2 = (str) => {
26
+ if ((options == null ? void 0 : options.mode) === "math") {
27
+ return {
28
+ type: "root",
29
+ content: parseMathMinimal(str),
30
+ _renderInfo: { inMathMode: true }
31
+ };
32
+ }
33
+ return parseMinimal(str);
34
+ };
35
+ Object.assign(this, { Parser: parser2 });
36
+ };
37
+
38
+ // libs/process-macros-and-environments.ts
39
+ import { visit as visit3 } from "@unified-latex/unified-latex-util-visit";
40
+ import { match as match3 } from "@unified-latex/unified-latex-util-match";
41
+ import { printRaw as printRaw3 } from "@unified-latex/unified-latex-util-print-raw";
42
+
43
+ // libs/reparse-math.ts
44
+ import { match } from "@unified-latex/unified-latex-util-match";
45
+ import { printRaw } from "@unified-latex/unified-latex-util-print-raw";
46
+ import { visit } from "@unified-latex/unified-latex-util-visit";
47
+ function unifiedLatexReparseMathConstructPlugin({
48
+ mathEnvs,
49
+ mathMacros
50
+ }) {
51
+ const isMathEnvironment = match.createEnvironmentMatcher(mathEnvs);
52
+ const isMathMacro = match.createMacroMatcher(mathMacros);
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));
59
+ }
60
+ }
61
+ }
62
+ if (match.anyEnvironment(node)) {
63
+ if (!wasParsedInMathMode(node.content)) {
64
+ node.content = parseMathMinimal(printRaw(node.content));
65
+ }
66
+ }
67
+ }, {
68
+ test: (node) => isMathEnvironment(node) || isMathMacro(node)
69
+ });
70
+ };
71
+ }
72
+ function wasParsedInMathMode(nodes) {
73
+ return !nodes.some((node) => match.anyString(node) && node.content.length > 1 || match.string(node, "^") || match.string(node, "_"));
74
+ }
75
+
76
+ // libs/process-macros-and-environments.ts
77
+ import { attachMacroArgsInArray } from "@unified-latex/unified-latex-util-arguments";
78
+
79
+ // ../unified-latex-util-environments/dist/index.js
80
+ import { updateRenderInfo } from "@unified-latex/unified-latex-util-render-info";
81
+ import { gobbleArguments } from "@unified-latex/unified-latex-util-arguments";
82
+ import { match as match2 } from "@unified-latex/unified-latex-util-match";
83
+ import { visit as visit2 } from "@unified-latex/unified-latex-util-visit";
84
+ import { printRaw as printRaw2 } from "@unified-latex/unified-latex-util-print-raw";
85
+ import { visit as visit22 } from "@unified-latex/unified-latex-util-visit";
86
+ import { match as match22 } from "@unified-latex/unified-latex-util-match";
87
+ import { printRaw as printRaw22 } from "@unified-latex/unified-latex-util-print-raw";
88
+ function processEnvironment(envNode, envInfo) {
89
+ if (envInfo.signature && envNode.args == null) {
90
+ const { args } = gobbleArguments(envNode.content, envInfo.signature);
91
+ envNode.args = args;
92
+ }
93
+ updateRenderInfo(envNode, envInfo.renderInfo);
94
+ if (typeof envInfo.processContent === "function") {
95
+ envNode.content = envInfo.processContent(envNode.content);
96
+ }
97
+ }
98
+
99
+ // libs/process-macros-and-environments.ts
100
+ var unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse = function unifiedLatexAttachMacroArguments(options) {
101
+ const { environments = {}, macros = {} } = options || {};
102
+ const mathMacros = Object.fromEntries(Object.entries(macros).filter(([_, info]) => {
103
+ var _a;
104
+ return ((_a = info.renderInfo) == null ? void 0 : _a.inMathMode) === true;
105
+ }));
106
+ const mathEnvs = Object.fromEntries(Object.entries(environments).filter(([_, info]) => {
107
+ var _a;
108
+ return ((_a = info.renderInfo) == null ? void 0 : _a.inMathMode) === true;
109
+ }));
110
+ const mathReparser = unifiedLatexReparseMathConstructPlugin({
111
+ mathEnvs: Object.keys(mathEnvs),
112
+ mathMacros: Object.keys(mathMacros)
113
+ });
114
+ const isRelevantEnvironment = match3.createEnvironmentMatcher(environments);
115
+ const isRelevantMathEnvironment = match3.createEnvironmentMatcher(mathEnvs);
116
+ return (tree) => {
117
+ visit3(tree, {
118
+ enter: (nodes) => {
119
+ if (!Array.isArray(nodes)) {
120
+ return;
121
+ }
122
+ attachMacroArgsInArray(nodes, mathMacros);
123
+ },
124
+ leave: (node) => {
125
+ if (!isRelevantMathEnvironment(node)) {
126
+ return;
127
+ }
128
+ const envName = printRaw3(node.env);
129
+ const envInfo = environments[envName];
130
+ if (!envInfo) {
131
+ throw new Error(`Could not find environment info for environment "${envName}"`);
132
+ }
133
+ processEnvironment(node, envInfo);
134
+ }
135
+ }, { includeArrays: true });
136
+ mathReparser(tree);
137
+ visit3(tree, {
138
+ enter: (nodes) => {
139
+ if (!Array.isArray(nodes)) {
140
+ return;
141
+ }
142
+ attachMacroArgsInArray(nodes, macros);
143
+ },
144
+ leave: (node) => {
145
+ if (!isRelevantEnvironment(node)) {
146
+ return;
147
+ }
148
+ const envName = printRaw3(node.env);
149
+ const envInfo = environments[envName];
150
+ if (!envInfo) {
151
+ throw new Error(`Could not find environment info for environment "${envName}"`);
152
+ }
153
+ processEnvironment(node, envInfo);
154
+ }
155
+ }, { includeArrays: true });
156
+ };
157
+ };
158
+
159
+ // libs/plugin-from-string.ts
160
+ var unifiedLatexFromString = function unifiedLatexFromString2(options) {
161
+ const {
162
+ mode = "regular",
163
+ macros = {},
164
+ environments = {}
165
+ } = options || {};
166
+ const allMacroInfo = Object.assign({}, macros, ...Object.values(macroInfo));
167
+ const allEnvInfo = Object.assign({}, environments, ...Object.values(environmentInfo));
168
+ const fullParser = unified().use(unifiedLatexFromStringMinimal, { mode }).use(unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse, {
169
+ macros: allMacroInfo,
170
+ environments: allEnvInfo
171
+ }).use(unifiedLatexTrimEnvironmentContents).use(unifiedLatexTrimRoot).use(unifiedLatexAstComplier);
172
+ const parser2 = (str) => {
173
+ const file = fullParser.processSync({ value: str });
174
+ return file.result;
175
+ };
176
+ Object.assign(this, { Parser: parser2 });
177
+ };
178
+
179
+ // libs/parse.ts
180
+ import { unified as unified2 } from "unified";
181
+ var parser = unified2().use(unifiedLatexFromString).freeze();
182
+ function parse(str) {
183
+ return parser.parse(str);
184
+ }
185
+
186
+ // libs/parse-math.ts
187
+ import { unified as unified3 } from "unified";
188
+ import { printRaw as printRaw4 } from "@unified-latex/unified-latex-util-print-raw";
189
+ function parseMath(str) {
190
+ if (typeof str !== "string") {
191
+ str = printRaw4(str);
192
+ }
193
+ const file = unified3().use(unifiedLatexFromString, { mode: "math" }).use(unifiedLatexAstComplier).processSync({ value: str });
194
+ return file.result.content;
195
+ }
196
+ export {
197
+ parse,
198
+ parseMath,
199
+ parseMathMinimal,
200
+ parseMinimal,
201
+ unifiedLatexAstComplier,
202
+ unifiedLatexFromString,
203
+ unifiedLatexFromStringMinimal
204
+ };
205
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
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", "../../unified-latex-util-environments/libs/process-environment.ts", "../../unified-latex-util-environments/libs/unified-latex-process-environment.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 { EnvInfo, EnvInfoRecord } from \"@unified-latex/unified-latex-types\";\nimport { updateRenderInfo } from \"@unified-latex/unified-latex-util-render-info\";\nimport { gobbleArguments } from \"@unified-latex/unified-latex-util-arguments\";\nimport { match } from \"@unified-latex/unified-latex-util-match\";\nimport { visit } from \"@unified-latex/unified-latex-util-visit\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\n\n/**\n * Performs any needed processing on the environment (as specified by `envInfo`)\n * include attaching arguments and possibly manipulating the environment's body.\n */\nexport function processEnvironment(envNode: Ast.Environment, envInfo: EnvInfo) {\n if (envInfo.signature && envNode.args == null) {\n const { args } = gobbleArguments(envNode.content, envInfo.signature);\n envNode.args = args;\n }\n\n updateRenderInfo(envNode, envInfo.renderInfo);\n if (typeof envInfo.processContent === \"function\") {\n envNode.content = envInfo.processContent(envNode.content);\n }\n}\n\n/**\n * Recursively search for and process the specified environments. Arguments are\n * consumed according to the `signature` specified. The body is processed\n * with the specified `processContent` function (if given). Any specified `renderInfo`\n * is attached to the environment node.\n */\nexport function processEnvironments(\n tree: Ast.Ast,\n environments: EnvInfoRecord\n) {\n const isRelevantEnvironment = match.createEnvironmentMatcher(environments);\n\n visit(\n tree,\n {\n leave: (node) => {\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 { test: isRelevantEnvironment }\n );\n}\n", "import * as Ast from \"@unified-latex/unified-latex-types\";\nimport { EnvInfoRecord } 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 { processEnvironment } from \"./process-environment\";\nimport { printRaw } from \"@unified-latex/unified-latex-util-print-raw\";\n\ntype PluginOptions = { environments: EnvInfoRecord } | undefined;\n\n/**\n * Unified plugin to process environment content and attach arguments.\n *\n * @param environments An object whose keys are environment names and values contains information about the environment and its argument signature.\n */\nexport const unifiedLatexProcessEnvironments: Plugin<\n PluginOptions[],\n Ast.Root,\n Ast.Root\n> = function unifiedLatexAttachMacroArguments(options) {\n const { environments = {} } = options || {};\n const isRelevantEnvironment = match.createEnvironmentMatcher(environments);\n\n return (tree) => {\n if (Object.keys(environments).length === 0) {\n console.warn(\n \"Attempting to attach macro arguments but no macros are specified.\"\n );\n }\n\n visit(\n tree,\n {\n leave: (node) => {\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 { test: isRelevantEnvironment }\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,oCAAmC;AAC/B,SAAO,OAAO,MAAM,EAAE,UAAU,CAAC,MAAgB,EAAE,CAAC;AACxD;;;ACTJ;AACA;AAGA;AAAA;AAAA;AAAA;;;AC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,IAAI,mCAAmC,EACvC,IAAI,oBAAoB,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;;;AO7DJ;AAGA,IAAM,SAAS,SAAQ,EAAE,IAAI,sBAAsB,EAAE,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": []
7
+ }
@@ -0,0 +1,7 @@
1
+ import { Plugin } from "unified";
2
+ import * as Ast from "@unified-latex/unified-latex-types";
3
+ /**
4
+ * Unified complier plugin that passes through a LaTeX AST without modification.
5
+ */
6
+ export declare const unifiedLatexAstComplier: Plugin<void[], Ast.Root, Ast.Root>;
7
+ //# sourceMappingURL=compiler-ast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler-ast.d.ts","sourceRoot":"","sources":["../../libs/compiler-ast.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAE1D;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,IAAI,EAAE,EAAE,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI,CAGlE,CAAC"}
@@ -0,0 +1,7 @@
1
+ import * as Ast from "@unified-latex/unified-latex-types";
2
+ /**
3
+ * Parse `str` into an AST. Parsing starts in math mode and a list of
4
+ * nodes is returned (instead of a "root" node).
5
+ */
6
+ export declare function parseMath(str: string | Ast.Ast): Ast.Node[];
7
+ //# sourceMappingURL=parse-math.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-math.d.ts","sourceRoot":"","sources":["../../libs/parse-math.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAK1D;;;GAGG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,EAAE,CAS3D"}
@@ -0,0 +1,17 @@
1
+ import * as Ast from "@unified-latex/unified-latex-types";
2
+ /**
3
+ * Parse `str` to an AST with minimal processing. E.g., macro
4
+ * arguments are not attached to macros, etc. when parsed with this
5
+ * function.
6
+ */
7
+ export declare function parseMinimal(str: string): Ast.Root;
8
+ /**
9
+ * Parse `str` to an AST with minimal processing. E.g., macro
10
+ * arguments are not attached to macros, etc. when parsed with this
11
+ * function.
12
+ *
13
+ * The parsing assumes a math-mode context, so, for example, `^` and `_` are
14
+ * parsed as macros (even though arguments are not attached to them).
15
+ */
16
+ export declare function parseMathMinimal(str: string): Ast.Node[];
17
+ //# sourceMappingURL=parse-minimal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse-minimal.d.ts","sourceRoot":"","sources":["../../libs/parse-minimal.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAE1D;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,IAAI,CAElD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,IAAI,EAAE,CAExD"}
@@ -0,0 +1,6 @@
1
+ import * as Ast from "@unified-latex/unified-latex-types";
2
+ /**
3
+ * Parse the string into an AST.
4
+ */
5
+ export declare function parse(str: string): Ast.Root;
6
+ //# sourceMappingURL=parse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../libs/parse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAM1D;;GAEG;AACH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC,IAAI,CAE3C"}
@@ -0,0 +1,15 @@
1
+ import { Plugin } from "unified";
2
+ import * as Ast from "@unified-latex/unified-latex-types";
3
+ declare type PluginOptions = {
4
+ /**
5
+ * Whether the text will be parsed assuming math mode or not.
6
+ */
7
+ mode: "math" | "regular";
8
+ } | void;
9
+ /**
10
+ * Parse a string to a LaTeX AST with no post processing. For example,
11
+ * no macro arguments will be attached, etc.
12
+ */
13
+ export declare const unifiedLatexFromStringMinimal: Plugin<PluginOptions[], string, Ast.Root>;
14
+ export {};
15
+ //# sourceMappingURL=plugin-from-string-minimal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-from-string-minimal.d.ts","sourceRoot":"","sources":["../../libs/plugin-from-string-minimal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAU,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAG1D,aAAK,aAAa,GAAG;IACjB;;OAEG;IACH,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CAC5B,GAAG,IAAI,CAAC;AAET;;;GAGG;AACH,eAAO,MAAM,6BAA6B,EAAE,MAAM,CAC9C,aAAa,EAAE,EACf,MAAM,EACN,GAAG,CAAC,IAAI,CAcX,CAAC"}
@@ -0,0 +1,13 @@
1
+ import { Plugin } from "unified";
2
+ import * as Ast from "@unified-latex/unified-latex-types";
3
+ import { EnvInfoRecord, MacroInfoRecord } from "@unified-latex/unified-latex-types";
4
+ export declare type PluginOptions = {
5
+ mode?: "math" | "regular";
6
+ macros?: MacroInfoRecord;
7
+ environments?: EnvInfoRecord;
8
+ } | undefined;
9
+ /**
10
+ * Parse a string to a LaTeX AST.
11
+ */
12
+ export declare const unifiedLatexFromString: Plugin<PluginOptions[], string, Ast.Root>;
13
+ //# sourceMappingURL=plugin-from-string.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,14 @@
1
+ import * as Ast from "@unified-latex/unified-latex-types";
2
+ import { EnvInfoRecord, MacroInfoRecord } from "@unified-latex/unified-latex-types";
3
+ import { Plugin } from "unified";
4
+ declare type PluginOptions = {
5
+ environments: EnvInfoRecord;
6
+ macros: MacroInfoRecord;
7
+ } | undefined;
8
+ /**
9
+ * Unified plugin to process macros and environments. Any environments that contain math content
10
+ * are reparsed (if needed) in math mode.
11
+ */
12
+ export declare const unifiedLatexProcessMacrosAndEnvironmentsWithMathReparse: Plugin<PluginOptions[], Ast.Root, Ast.Root>;
13
+ export {};
14
+ //# sourceMappingURL=process-macros-and-environments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"process-macros-and-environments.d.ts","sourceRoot":"","sources":["../../libs/process-macros-and-environments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACpF,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAUjC,aAAK,aAAa,GACZ;IAAE,YAAY,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,eAAe,CAAA;CAAE,GACxD,SAAS,CAAC;AAEhB;;;GAGG;AACH,eAAO,MAAM,uDAAuD,EAAE,MAAM,CACxE,aAAa,EAAE,EACf,GAAG,CAAC,IAAI,EACR,GAAG,CAAC,IAAI,CAiFX,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { Plugin } from "unified";
2
+ import * as Ast from "@unified-latex/unified-latex-types";
3
+ declare type PluginOptions = {
4
+ /**
5
+ * List of environments whose body should be parsed in math mode
6
+ */
7
+ mathEnvs: string[];
8
+ /**
9
+ * List of macros whose bodies should be parsed in math mode
10
+ */
11
+ mathMacros: string[];
12
+ } | undefined;
13
+ /**
14
+ * Reparse math environments/macro contents that should have been parsed in math mode but weren't.
15
+ */
16
+ export declare const unifiedLatexReparseMath: Plugin<PluginOptions[], Ast.Root, Ast.Root>;
17
+ /**
18
+ * Construct the inner function for the `unifiedLatexReparseMath` plugin. This function should not be used by libraries.
19
+ */
20
+ export declare function unifiedLatexReparseMathConstructPlugin({ mathEnvs, mathMacros, }: {
21
+ mathEnvs: string[];
22
+ mathMacros: string[];
23
+ }): (tree: Ast.Root) => void;
24
+ export {};
25
+ //# sourceMappingURL=reparse-math.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reparse-math.d.ts","sourceRoot":"","sources":["../../libs/reparse-math.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,KAAK,GAAG,MAAM,oCAAoC,CAAC;AAM1D,aAAK,aAAa,GACZ;IACI;;OAEG;IACH,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB;;OAEG;IACH,UAAU,EAAE,MAAM,EAAE,CAAC;CACxB,GACD,SAAS,CAAC;AAEhB;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAM,CACxC,aAAa,EAAE,EACf,GAAG,CAAC,IAAI,EACR,GAAG,CAAC,IAAI,CAKX,CAAC;AAEF;;GAEG;AACH,wBAAgB,sCAAsC,CAAC,EACnD,QAAQ,EACR,UAAU,GACb,EAAE;IACC,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,EAAE,MAAM,EAAE,CAAC;CACxB,UAIiB,IAAI,IAAI,UA2BzB"}
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@unified-latex/unified-latex-util-parse",
3
+ "version": "1.0.0",
4
+ "description": "Tools for manipulating unified-latex ASTs",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "dependencies": {
8
+ "@unified-latex/unified-latex-types": "*",
9
+ "@unified-latex/unified-latex-builder": "*",
10
+ "@unified-latex/unified-latex-ctan": "*",
11
+ "@unified-latex/unified-latex-util-match": "*",
12
+ "@unified-latex/unified-latex-util-trim": "*",
13
+ "@unified-latex/unified-latex-util-print-raw": "*",
14
+ "@unified-latex/unified-latex-util-pegjs": "*",
15
+ "@unified-latex/unified-latex-util-render-info": "*",
16
+ "@unified-latex/unified-latex-util-arguments": "*",
17
+ "@unified-latex/unified-latex-util-visit": "*"
18
+ },
19
+ "files": [
20
+ "dist/**/*.ts",
21
+ "dist/**/*.js",
22
+ "dist/**/*.map",
23
+ "dist/**/*.json"
24
+ ],
25
+ "exports": {
26
+ ".": {
27
+ "import": "./dist/index.js",
28
+ "require": "./dist/index.cjs"
29
+ },
30
+ "./*js": "./dist/*js",
31
+ "./*": {
32
+ "import": "./dist/*.js",
33
+ "require": "./dist/*.cjs"
34
+ }
35
+ },
36
+ "scripts": {
37
+ "build": "npm run clean && mkdirp ./dist && npm run compile",
38
+ "clean": "rm -rf ./dist && rm -rf tsconfig.tsbuildinfo",
39
+ "compile": "tsc -b tsconfig.json & node build.js & wait",
40
+ "test": "jest"
41
+ },
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/siefkenj/unified-latex.git"
45
+ },
46
+ "keywords": [
47
+ "pegjs",
48
+ "latex",
49
+ "parser",
50
+ "prettier",
51
+ "unified-latex",
52
+ "unified"
53
+ ],
54
+ "author": "Jason Siefken",
55
+ "license": "MIT",
56
+ "bugs": {
57
+ "url": "https://github.com/siefkenj/unified-latex/issues"
58
+ },
59
+ "homepage": "https://github.com/siefkenj/unified-latex#readme",
60
+ "jest": {
61
+ "transformIgnorePatterns": [
62
+ "node_modules/(?!unified|bail|is-plain-obj|trough|vfile.*|unist.*|hast.*|property-information|html-void-elements|.*-separated-tokens|.*entities.*|ccount|rehype*|string-width|strip-ansi|ansi-regex|supports-color)"
63
+ ],
64
+ "transform": {
65
+ "\\.m?jsx?$": "esbuild-jest",
66
+ "latex.pegjs$": "<rootDir>/../../tests/pegjs-preprocessor-latex.js",
67
+ "\\.pegjs$": "<rootDir>/../../tests/pegjs-preprocessor.js",
68
+ "^.+\\.tsx?$": "ts-jest"
69
+ }
70
+ }
71
+ }