@unified-latex/unified-latex-cli 1.8.2 → 1.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +33473 -31992
- package/index.cjs.map +1 -1
- package/index.js +760 -721
- package/index.js.map +1 -1
- package/package.json +12 -12
- package/unified-latex-cli.mjs +760 -721
package/unified-latex-cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { unified } from "unified";
|
|
3
|
-
import {
|
|
3
|
+
import { parse, unifiedLatexFromString } from "@unified-latex/unified-latex-util-parse";
|
|
4
4
|
import { unifiedLatexStringCompiler } from "@unified-latex/unified-latex-util-to-string";
|
|
5
5
|
import process from "node:process";
|
|
6
6
|
import stream from "node:stream";
|
|
@@ -16,7 +16,7 @@ import minimist from "minimist";
|
|
|
16
16
|
import json5 from "json5";
|
|
17
17
|
import { fault } from "fault";
|
|
18
18
|
import { lints } from "@unified-latex/unified-latex-lint";
|
|
19
|
-
import {
|
|
19
|
+
import { expandMacros, expandMacrosExcludingDefinitions, listNewcommands, newcommandMacroToName, newcommandMacroToSpec, newcommandMacroToSubstitutionAst } from "@unified-latex/unified-latex-util-macros";
|
|
20
20
|
import { listPackages } from "@unified-latex/unified-latex-util-packages";
|
|
21
21
|
import { printRaw } from "@unified-latex/unified-latex-util-print-raw";
|
|
22
22
|
import { attachMacroArgs } from "@unified-latex/unified-latex-util-arguments";
|
|
@@ -24,776 +24,815 @@ import rehypeStringify from "rehype-stringify";
|
|
|
24
24
|
import Prettier from "prettier";
|
|
25
25
|
import remarkStringify from "remark-stringify";
|
|
26
26
|
import fs from "node:fs";
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
27
|
+
//#region libs/unified-latex.ts
|
|
28
|
+
/**
|
|
29
|
+
* Use `unified()` to a string to an `Ast.Ast` and then pretty-print it.
|
|
30
|
+
*/
|
|
31
|
+
var processLatexViaUnified = (options) => {
|
|
32
|
+
return unified().use(unifiedLatexFromString, Object.assign({
|
|
33
|
+
environments: {},
|
|
34
|
+
macros: {}
|
|
35
|
+
}, options)).use(unifiedLatexStringCompiler, Object.assign({
|
|
36
|
+
pretty: true,
|
|
37
|
+
forceNewlineEnding: true
|
|
38
|
+
}, options));
|
|
35
39
|
};
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
type: "boolean",
|
|
241
|
-
default: true
|
|
242
|
-
}
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region libs/lints/index.ts
|
|
42
|
+
var availableLints = Object.fromEntries(Object.values(lints).map((lint) => [lint.name.replace(/^unified-latex-lint:/, ""), lint]));
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region libs/unified-args/schema.ts
|
|
45
|
+
var schema = [
|
|
46
|
+
{
|
|
47
|
+
long: "help",
|
|
48
|
+
description: "Output usage information",
|
|
49
|
+
short: "h",
|
|
50
|
+
type: "boolean",
|
|
51
|
+
default: false
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
long: "version",
|
|
55
|
+
description: "Output version number",
|
|
56
|
+
short: "v",
|
|
57
|
+
type: "boolean",
|
|
58
|
+
default: false
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
long: "output",
|
|
62
|
+
description: "Specify output location",
|
|
63
|
+
short: "o",
|
|
64
|
+
value: "[path]"
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
long: "rc-path",
|
|
68
|
+
description: "Specify configuration file",
|
|
69
|
+
short: "r",
|
|
70
|
+
type: "string",
|
|
71
|
+
value: "<path>"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
long: "ignore-path",
|
|
75
|
+
description: "Specify ignore file",
|
|
76
|
+
short: "i",
|
|
77
|
+
type: "string",
|
|
78
|
+
value: "<path>"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
long: "ext",
|
|
82
|
+
description: "Specify extensions",
|
|
83
|
+
type: "string",
|
|
84
|
+
value: "<extensions>"
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
long: "lint",
|
|
88
|
+
description: `Lint rules to apply. Use multiple times to specify multiple lints. Available rules: ${Object.keys(availableLints).join(", ")}`,
|
|
89
|
+
short: "l",
|
|
90
|
+
type: "string",
|
|
91
|
+
value: "<rule>"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
long: "lint-all",
|
|
95
|
+
description: `Apply all available lint rules`,
|
|
96
|
+
type: "boolean",
|
|
97
|
+
default: false
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
long: "fix-all",
|
|
101
|
+
description: "Apply fixes for all applied lints",
|
|
102
|
+
type: "boolean",
|
|
103
|
+
default: false
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
long: "watch",
|
|
107
|
+
description: "Watch for changes and reprocess",
|
|
108
|
+
short: "w",
|
|
109
|
+
type: "boolean",
|
|
110
|
+
default: false
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
long: "macro",
|
|
114
|
+
description: "Attach arguments of the specified macro (by default, unrecognized macros are parsed as having no arguments). Accepts a string of the form `\\newcommand{<name>}[<num args>]{<body>}` or a JSON string `{name: <name>, signature: <xparse argument signature>, body: <macro body>}`",
|
|
115
|
+
short: "m",
|
|
116
|
+
type: "string",
|
|
117
|
+
value: "<rule>"
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
long: "expand-macro",
|
|
121
|
+
description: "Expand the specified macro. Accepts a string of the form `\\newcommand{<name>}[<num args>]{<body>}` or a JSON string `{name: <name>, signature: <xparse argument signature>, body: <macro body>}`",
|
|
122
|
+
short: "e",
|
|
123
|
+
type: "string",
|
|
124
|
+
value: "<rule>"
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
long: "expand-document-macro",
|
|
128
|
+
description: "Expand the specified macro which is defined in the document. You can use --stats to list all macros defined in the document.",
|
|
129
|
+
short: "d",
|
|
130
|
+
type: "string",
|
|
131
|
+
value: "<name>"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
long: "frail",
|
|
135
|
+
description: "Exit with 1 on warnings",
|
|
136
|
+
type: "boolean",
|
|
137
|
+
default: false
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
long: "tree",
|
|
141
|
+
description: "Specify input and output as syntax tree",
|
|
142
|
+
type: "boolean",
|
|
143
|
+
default: false
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
long: "report",
|
|
147
|
+
description: "Specify reporter",
|
|
148
|
+
type: "string",
|
|
149
|
+
value: "<reporter>"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
long: "file-path",
|
|
153
|
+
description: "Specify path to process as",
|
|
154
|
+
type: "string",
|
|
155
|
+
value: "<path>"
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
long: "ignore-path-resolve-from",
|
|
159
|
+
description: "Resolve patterns in `ignore-path` from its directory or cwd",
|
|
160
|
+
type: "string",
|
|
161
|
+
value: "dir|cwd",
|
|
162
|
+
default: "dir"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
long: "ignore-pattern",
|
|
166
|
+
description: "Specify ignore patterns",
|
|
167
|
+
type: "string",
|
|
168
|
+
value: "<globs>"
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
long: "silently-ignore",
|
|
172
|
+
description: "Do not fail when given ignored files",
|
|
173
|
+
type: "boolean"
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
long: "tree-in",
|
|
177
|
+
description: "Specify input as syntax tree",
|
|
178
|
+
type: "boolean"
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
long: "tree-out",
|
|
182
|
+
description: "Output syntax tree",
|
|
183
|
+
type: "boolean"
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
long: "inspect",
|
|
187
|
+
description: "Output formatted syntax tree",
|
|
188
|
+
type: "boolean"
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
long: "stats",
|
|
192
|
+
description: "Show information about the processed file",
|
|
193
|
+
type: "boolean",
|
|
194
|
+
default: false
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
long: "stats-json",
|
|
198
|
+
description: "Show information about the processed file and output the information as JSON",
|
|
199
|
+
type: "boolean",
|
|
200
|
+
default: false
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
long: "html",
|
|
204
|
+
description: "Convert the output to HTML. Note, for math to render properly, you will need to add a library like MathJax or KaTeX to your HTMl source; you should also expand/replace any macros not recognized by the converter",
|
|
205
|
+
type: "boolean",
|
|
206
|
+
default: false
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
long: "markdown",
|
|
210
|
+
description: "Convert the output to Markdown. Markdown output uses Github-flavored Markdown to support math",
|
|
211
|
+
type: "boolean",
|
|
212
|
+
default: false
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
long: "pretext",
|
|
216
|
+
description: "Convert the output to PreTeXt. Note, you should expand/replace any macros not recognized by the converter",
|
|
217
|
+
type: "boolean",
|
|
218
|
+
default: false
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
long: "stdout",
|
|
222
|
+
description: "[Don't] write the processed file's contents to stdout",
|
|
223
|
+
type: "boolean",
|
|
224
|
+
truelike: true
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
long: "color",
|
|
228
|
+
description: "Specify color in report",
|
|
229
|
+
type: "boolean",
|
|
230
|
+
default: true
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
long: "config",
|
|
234
|
+
description: "Search for configuration files",
|
|
235
|
+
type: "boolean",
|
|
236
|
+
default: true
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
long: "ignore",
|
|
240
|
+
description: "Search for ignore files",
|
|
241
|
+
type: "boolean",
|
|
242
|
+
default: true
|
|
243
|
+
}
|
|
243
244
|
];
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region libs/macros/parse-macro-expansion.ts
|
|
247
|
+
/**
|
|
248
|
+
* Parse a macro specification given on the command line as either a "\newcommand" string
|
|
249
|
+
* or a JSON object specifying `name`, `signature`, and `body`.
|
|
250
|
+
*/
|
|
244
251
|
function parseMacroExpansion(def) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
parsedSpec.signature = parsedSpec.signature || "";
|
|
264
|
-
return {
|
|
265
|
-
name: parsedSpec.name,
|
|
266
|
-
signature: parsedSpec.signature,
|
|
267
|
-
body: parse(parsedSpec.body).content
|
|
268
|
-
};
|
|
252
|
+
if (def.startsWith("\\")) {
|
|
253
|
+
const macro = parse(def).content[0];
|
|
254
|
+
const name = newcommandMacroToName(macro);
|
|
255
|
+
if (!name) throw new Error(`Could extract macro definition from "${def}"; expected the macro to be defined via \\newcommand or similar syntax`);
|
|
256
|
+
return {
|
|
257
|
+
name,
|
|
258
|
+
signature: newcommandMacroToSpec(macro),
|
|
259
|
+
body: newcommandMacroToSubstitutionAst(macro)
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
const parsedSpec = json5.parse(def);
|
|
263
|
+
if (parsedSpec.name == null || parsedSpec.body == null) throw new Error(`Expected a "name" field and a "body" field to be defined on ${def}`);
|
|
264
|
+
parsedSpec.signature = parsedSpec.signature || "";
|
|
265
|
+
return {
|
|
266
|
+
name: parsedSpec.name,
|
|
267
|
+
signature: parsedSpec.signature,
|
|
268
|
+
body: parse(parsedSpec.body).content
|
|
269
|
+
};
|
|
269
270
|
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region libs/unified-args/options.ts
|
|
273
|
+
var own = {}.hasOwnProperty;
|
|
274
|
+
/**
|
|
275
|
+
* Schema for `minimist`.
|
|
276
|
+
*/
|
|
277
|
+
var minischema = {
|
|
278
|
+
unknown: handleUnknownArgument,
|
|
279
|
+
default: {},
|
|
280
|
+
alias: {},
|
|
281
|
+
string: [],
|
|
282
|
+
boolean: []
|
|
277
283
|
};
|
|
278
|
-
|
|
279
|
-
while (++index < schema.length)
|
|
280
|
-
|
|
281
|
-
|
|
284
|
+
var index = -1;
|
|
285
|
+
while (++index < schema.length) addEach(schema[index]);
|
|
286
|
+
/**
|
|
287
|
+
* Parse CLI options.
|
|
288
|
+
*/
|
|
282
289
|
function options(flags, configuration) {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
statsJson: config.statsJson,
|
|
358
|
-
expandMacro: normalizeToArray(config.expandMacro).map(
|
|
359
|
-
parseMacroExpansion
|
|
360
|
-
),
|
|
361
|
-
expandDocumentMacro: normalizeToArray(
|
|
362
|
-
config.expandDocumentMacro
|
|
363
|
-
),
|
|
364
|
-
macro: normalizeToArray(config.macro).map(
|
|
365
|
-
parseMacroExpansion
|
|
366
|
-
),
|
|
367
|
-
html: config.html,
|
|
368
|
-
markdown: config.markdown,
|
|
369
|
-
pretext: config.pretext
|
|
370
|
-
};
|
|
290
|
+
const extension = configuration.extensions[0];
|
|
291
|
+
const name = configuration.name;
|
|
292
|
+
const config = toCamelCase(minimist(flags, minischema));
|
|
293
|
+
let index = -1;
|
|
294
|
+
while (++index < schema.length) {
|
|
295
|
+
const option = schema[index];
|
|
296
|
+
if (option.type === "string" && config[option.long] === "") throw fault("Missing value:%s", inspect(option).join(" "));
|
|
297
|
+
}
|
|
298
|
+
const ext = commaSeparated(config.ext);
|
|
299
|
+
const report = reporter(config.report);
|
|
300
|
+
const help = [
|
|
301
|
+
inspectAll(schema),
|
|
302
|
+
"",
|
|
303
|
+
"Examples:",
|
|
304
|
+
"",
|
|
305
|
+
" # Process `input." + extension + "`",
|
|
306
|
+
" $ " + name + " input." + extension + " -o output." + extension,
|
|
307
|
+
"",
|
|
308
|
+
" # Pipe",
|
|
309
|
+
" $ " + name + " < input." + extension + " > output." + extension,
|
|
310
|
+
"",
|
|
311
|
+
" # Rewrite all applicable files",
|
|
312
|
+
" $ " + name + " . -o",
|
|
313
|
+
"",
|
|
314
|
+
" # Lint files and display the lint output (but not the processed file)",
|
|
315
|
+
" $ " + name + " . --lint-all --no-stdout"
|
|
316
|
+
].join("\n");
|
|
317
|
+
const settings = parseSettings(config.setting);
|
|
318
|
+
if (config.html && config.statsJson) throw new Error("Both --html and --stats-json were specified; only one may be used at a time.");
|
|
319
|
+
return {
|
|
320
|
+
helpMessage: help,
|
|
321
|
+
cwd: configuration.cwd,
|
|
322
|
+
processor: configuration.processor,
|
|
323
|
+
help: config.help,
|
|
324
|
+
version: config.version,
|
|
325
|
+
files: config._ || config[""],
|
|
326
|
+
filePath: config.filePath,
|
|
327
|
+
watch: config.watch,
|
|
328
|
+
extensions: ext.length === 0 ? configuration.extensions : ext,
|
|
329
|
+
output: config.output,
|
|
330
|
+
out: config.stdout,
|
|
331
|
+
tree: config.tree,
|
|
332
|
+
treeIn: config.treeIn,
|
|
333
|
+
treeOut: config.treeOut,
|
|
334
|
+
inspect: config.inspect,
|
|
335
|
+
rcName: configuration.rcName,
|
|
336
|
+
packageField: configuration.packageField,
|
|
337
|
+
rcPath: config.rcPath,
|
|
338
|
+
detectConfig: config.config,
|
|
339
|
+
settings,
|
|
340
|
+
ignoreName: configuration.ignoreName,
|
|
341
|
+
ignorePath: config.ignorePath,
|
|
342
|
+
ignorePathResolveFrom: config.ignorePathResolveFrom,
|
|
343
|
+
ignorePatterns: commaSeparated(config.ignorePattern),
|
|
344
|
+
silentlyIgnore: config.silentlyIgnore,
|
|
345
|
+
detectIgnore: config.ignore,
|
|
346
|
+
pluginPrefix: configuration.pluginPrefix,
|
|
347
|
+
plugins: [],
|
|
348
|
+
lints: normalizeLints(config.lint, config),
|
|
349
|
+
reporter: report[0],
|
|
350
|
+
reporterOptions: report[1],
|
|
351
|
+
color: config.color,
|
|
352
|
+
silent: config.silent,
|
|
353
|
+
quiet: config.quiet,
|
|
354
|
+
frail: config.frail,
|
|
355
|
+
stats: config.stats,
|
|
356
|
+
statsJson: config.statsJson,
|
|
357
|
+
expandMacro: normalizeToArray(config.expandMacro).map(parseMacroExpansion),
|
|
358
|
+
expandDocumentMacro: normalizeToArray(config.expandDocumentMacro),
|
|
359
|
+
macro: normalizeToArray(config.macro).map(parseMacroExpansion),
|
|
360
|
+
html: config.html,
|
|
361
|
+
markdown: config.markdown,
|
|
362
|
+
pretext: config.pretext
|
|
363
|
+
};
|
|
371
364
|
}
|
|
372
365
|
function addEach(option) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
}
|
|
378
|
-
if (option.short) {
|
|
379
|
-
minischema.alias[option.short] = option.long;
|
|
380
|
-
}
|
|
366
|
+
const value = option.default;
|
|
367
|
+
minischema.default[option.long] = value === void 0 ? null : value;
|
|
368
|
+
if (option.type && option.type in minischema) minischema[option.type].push(option.long);
|
|
369
|
+
if (option.short) minischema.alias[option.short] = option.long;
|
|
381
370
|
}
|
|
371
|
+
/**
|
|
372
|
+
* Parse `extensions`.
|
|
373
|
+
*/
|
|
382
374
|
function commaSeparated(value) {
|
|
383
|
-
|
|
375
|
+
return normalizeToArray(value).flatMap((d) => splitOnComma(d));
|
|
384
376
|
}
|
|
377
|
+
/**
|
|
378
|
+
* Normalize the specified lints
|
|
379
|
+
*/
|
|
385
380
|
function normalizeLints(value, config) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
if (params) {
|
|
396
|
-
Object.assign(params, { fix: true });
|
|
397
|
-
} else {
|
|
398
|
-
params = { fix: true };
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
return [value2[0], params];
|
|
402
|
-
})
|
|
403
|
-
);
|
|
404
|
-
return result;
|
|
381
|
+
const normalized = normalizeToArray(value).map(splitOnEquals);
|
|
382
|
+
validateLintNames(normalized);
|
|
383
|
+
if (config.lintAll) normalized.push(...Object.keys(availableLints).map((v) => [v]));
|
|
384
|
+
return Object.fromEntries(normalized.map((value) => {
|
|
385
|
+
let params = value[1] ? parseConfig(value[1], {}) : void 0;
|
|
386
|
+
if (config.fixAll) if (params) Object.assign(params, { fix: true });
|
|
387
|
+
else params = { fix: true };
|
|
388
|
+
return [value[0], params];
|
|
389
|
+
}));
|
|
405
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* Parse `reporter`: only one is accepted.
|
|
393
|
+
*/
|
|
406
394
|
function reporter(value) {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
value2[1] ? parseConfig(value2[1], {}) : void 0
|
|
410
|
-
]);
|
|
411
|
-
return all[all.length - 1] || [];
|
|
395
|
+
const all = normalizeToArray(value).map(splitOnEquals).map((value) => [value[0], value[1] ? parseConfig(value[1], {}) : void 0]);
|
|
396
|
+
return all[all.length - 1] || [];
|
|
412
397
|
}
|
|
398
|
+
/**
|
|
399
|
+
* Parse `settings`.
|
|
400
|
+
*/
|
|
413
401
|
function parseSettings(value) {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
}
|
|
419
|
-
return cache;
|
|
402
|
+
const normalized = normalizeToArray(value);
|
|
403
|
+
const cache = {};
|
|
404
|
+
for (const value of normalized) parseConfig(value, cache);
|
|
405
|
+
return cache;
|
|
420
406
|
}
|
|
407
|
+
/**
|
|
408
|
+
* Parse configuration.
|
|
409
|
+
*/
|
|
421
410
|
function parseConfig(value, cache) {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
// Fix position
|
|
432
|
-
exception.message.replace(/at(?= position)/, "around")
|
|
433
|
-
);
|
|
434
|
-
}
|
|
435
|
-
for (flag in flags) {
|
|
436
|
-
if (own.call(flags, flag)) {
|
|
437
|
-
cache[flag] = flags[flag];
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
return cache;
|
|
411
|
+
let flags;
|
|
412
|
+
let flag;
|
|
413
|
+
try {
|
|
414
|
+
flags = toCamelCase(parseJSON(value));
|
|
415
|
+
} catch (error) {
|
|
416
|
+
throw fault("Cannot parse `%s` as JSON: %s", value, error.message.replace(/at(?= position)/, "around"));
|
|
417
|
+
}
|
|
418
|
+
for (flag in flags) if (own.call(flags, flag)) cache[flag] = flags[flag];
|
|
419
|
+
return cache;
|
|
441
420
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
return true;
|
|
421
|
+
/**
|
|
422
|
+
* Handle an unknown flag.
|
|
423
|
+
*/
|
|
424
|
+
function validateLintNames(lints) {
|
|
425
|
+
for (const lint of lints) {
|
|
426
|
+
const name = lint[0];
|
|
427
|
+
if (!availableLints[name]) throw fault("Unknown lint rule `%s`, available rules are:\n%s", name, " " + Object.keys(availableLints).join("\n "));
|
|
428
|
+
}
|
|
429
|
+
return true;
|
|
455
430
|
}
|
|
431
|
+
/**
|
|
432
|
+
* Handle an unknown flag.
|
|
433
|
+
*/
|
|
456
434
|
function handleUnknownArgument(flag) {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
while (++index2 < found.length) {
|
|
470
|
-
const key = found[index2];
|
|
471
|
-
if (!knownKeys.has(key)) {
|
|
472
|
-
throw fault(
|
|
473
|
-
"Unknown short option `-%s`, expected:\n%s",
|
|
474
|
-
key,
|
|
475
|
-
inspectAll(known)
|
|
476
|
-
);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
return true;
|
|
435
|
+
if (flag.charAt(0) === "-") {
|
|
436
|
+
if (flag.charAt(1) === "-") throw fault("Unknown option `%s`, expected:\n%s", flag, inspectAll(schema));
|
|
437
|
+
const found = flag.slice(1).split("");
|
|
438
|
+
const known = schema.filter((d) => d.short);
|
|
439
|
+
const knownKeys = new Set(known.map((d) => d.short));
|
|
440
|
+
let index = -1;
|
|
441
|
+
while (++index < found.length) {
|
|
442
|
+
const key = found[index];
|
|
443
|
+
if (!knownKeys.has(key)) throw fault("Unknown short option `-%s`, expected:\n%s", key, inspectAll(known));
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
return true;
|
|
481
447
|
}
|
|
482
|
-
|
|
483
|
-
|
|
448
|
+
/**
|
|
449
|
+
* Inspect all `options`.
|
|
450
|
+
*/
|
|
451
|
+
function inspectAll(options) {
|
|
452
|
+
return table(options.map((d) => inspect(d)));
|
|
484
453
|
}
|
|
454
|
+
/**
|
|
455
|
+
* Inspect one `option`.
|
|
456
|
+
*/
|
|
485
457
|
function inspect(option) {
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
458
|
+
let description = option.description;
|
|
459
|
+
let long = option.long;
|
|
460
|
+
if (option.default === true || option.truelike) {
|
|
461
|
+
description += " (on by default)";
|
|
462
|
+
long = "[no-]" + long;
|
|
463
|
+
}
|
|
464
|
+
return [
|
|
465
|
+
"",
|
|
466
|
+
option.short ? "-" + option.short : "",
|
|
467
|
+
"--" + long + (option.value ? " " + option.value : ""),
|
|
468
|
+
description
|
|
469
|
+
];
|
|
498
470
|
}
|
|
471
|
+
/**
|
|
472
|
+
* Normalize `value`.
|
|
473
|
+
*/
|
|
499
474
|
function normalizeToArray(value) {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
if (typeof value === "string") {
|
|
504
|
-
return [value];
|
|
505
|
-
}
|
|
506
|
-
return value;
|
|
475
|
+
if (!value) return [];
|
|
476
|
+
if (typeof value === "string") return [value];
|
|
477
|
+
return value;
|
|
507
478
|
}
|
|
508
479
|
function splitOnEquals(value) {
|
|
509
|
-
|
|
480
|
+
return value.split("=");
|
|
510
481
|
}
|
|
511
482
|
function splitOnComma(value) {
|
|
512
|
-
|
|
483
|
+
return value.split(",");
|
|
513
484
|
}
|
|
485
|
+
/**
|
|
486
|
+
* Transform the keys on an object to camel-case, recursively.
|
|
487
|
+
*/
|
|
514
488
|
function toCamelCase(object) {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
result[camelcase(key)] = value;
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
return result;
|
|
489
|
+
const result = {};
|
|
490
|
+
let key;
|
|
491
|
+
for (key in object) if (own.call(object, key)) {
|
|
492
|
+
let value = object[key];
|
|
493
|
+
if (value && typeof value === "object" && !Array.isArray(value)) value = toCamelCase(value);
|
|
494
|
+
result[camelcase(key)] = value;
|
|
495
|
+
}
|
|
496
|
+
return result;
|
|
527
497
|
}
|
|
498
|
+
/**
|
|
499
|
+
* Parse a (lazy?) JSON config.
|
|
500
|
+
*/
|
|
528
501
|
function parseJSON(value) {
|
|
529
|
-
|
|
502
|
+
return json5.parse("{" + value + "}");
|
|
530
503
|
}
|
|
504
|
+
//#endregion
|
|
505
|
+
//#region libs/stats/enclosing-position.ts
|
|
506
|
+
/**
|
|
507
|
+
* Find the smallest `position` object that contains all `nodes`.
|
|
508
|
+
*/
|
|
531
509
|
function enclosingPosition(nodes) {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
510
|
+
let start = {
|
|
511
|
+
line: 1,
|
|
512
|
+
column: 1,
|
|
513
|
+
offset: 0
|
|
514
|
+
};
|
|
515
|
+
let end = {
|
|
516
|
+
line: 1,
|
|
517
|
+
column: 1,
|
|
518
|
+
offset: 0
|
|
519
|
+
};
|
|
520
|
+
for (const node of nodes) {
|
|
521
|
+
var _node$position, _node$position3;
|
|
522
|
+
if (Number((_node$position = node.position) === null || _node$position === void 0 ? void 0 : _node$position.start.offset) < Number(start.offset)) {
|
|
523
|
+
var _node$position2;
|
|
524
|
+
start = (_node$position2 = node.position) === null || _node$position2 === void 0 ? void 0 : _node$position2.start;
|
|
525
|
+
}
|
|
526
|
+
if (Number((_node$position3 = node.position) === null || _node$position3 === void 0 ? void 0 : _node$position3.end.offset) > Number(end.offset)) {
|
|
527
|
+
var _node$position4;
|
|
528
|
+
end = (_node$position4 = node.position) === null || _node$position4 === void 0 ? void 0 : _node$position4.end;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
return {
|
|
532
|
+
start,
|
|
533
|
+
end
|
|
534
|
+
};
|
|
544
535
|
}
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
enclosingPosition(newcommands.map((c) => c.definition))
|
|
559
|
-
);
|
|
560
|
-
}
|
|
561
|
-
};
|
|
536
|
+
//#endregion
|
|
537
|
+
//#region libs/stats/index.ts
|
|
538
|
+
/**
|
|
539
|
+
* Plugin that reports statistics on the contents of LaTeX files.
|
|
540
|
+
*/
|
|
541
|
+
var statsPlugin = function() {
|
|
542
|
+
return (tree, file) => {
|
|
543
|
+
const packages = listPackages(tree);
|
|
544
|
+
const packageNames = packages.map((s) => printRaw(s));
|
|
545
|
+
if (packages.length > 0) file.info(`Found ${packages.length} imported packages: ${packageNames.join(", ")}`);
|
|
546
|
+
const newcommands = listNewcommands(tree);
|
|
547
|
+
if (newcommands.length > 0) file.info(`Found ${newcommands.length} defined commands: ${newcommands.map((c) => `\\${c.name}`).join(", ")}`, enclosingPosition(newcommands.map((c) => c.definition)));
|
|
548
|
+
};
|
|
562
549
|
};
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
550
|
+
/**
|
|
551
|
+
* Plugin that reports statistics on the contents of LaTeX files and replaces the file output with a JSON
|
|
552
|
+
* representation of the statistics.
|
|
553
|
+
*/
|
|
554
|
+
var statsJsonPlugin = function() {
|
|
555
|
+
this.Compiler = (tree, file) => {
|
|
556
|
+
file.extname = ".json";
|
|
557
|
+
file.basename += "-stats";
|
|
558
|
+
const packages = listPackages(tree).map((s) => printRaw(s));
|
|
559
|
+
const newcommands = listNewcommands(tree).map((c) => ({
|
|
560
|
+
name: c.name,
|
|
561
|
+
signature: c.signature,
|
|
562
|
+
body: printRaw(c.body),
|
|
563
|
+
definition: printRaw(c.definition)
|
|
564
|
+
}));
|
|
565
|
+
return JSON.stringify({
|
|
566
|
+
packages,
|
|
567
|
+
newcommands
|
|
568
|
+
}, null, 4) + "\n";
|
|
569
|
+
};
|
|
576
570
|
};
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
571
|
+
//#endregion
|
|
572
|
+
//#region libs/macros/expand-macros-plugin.ts
|
|
573
|
+
/**
|
|
574
|
+
* Plugin that expands the specified macros.
|
|
575
|
+
*/
|
|
576
|
+
var expandMacrosPlugin = function(options) {
|
|
577
|
+
const { macros = [] } = options || {};
|
|
578
|
+
const macroInfo = Object.fromEntries(macros.map((m) => [m.name, { signature: m.signature }]));
|
|
579
|
+
return (tree) => {
|
|
580
|
+
attachMacroArgs(tree, macroInfo);
|
|
581
|
+
expandMacros(tree, macros);
|
|
582
|
+
};
|
|
586
583
|
};
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
584
|
+
//#endregion
|
|
585
|
+
//#region libs/macros/attach-macro-args-plugin.ts
|
|
586
|
+
/**
|
|
587
|
+
* Plugin that attaches the arguments of the specified macros.
|
|
588
|
+
*/
|
|
589
|
+
var attachMacroArgsPlugin = function(options) {
|
|
590
|
+
const { macros = [] } = options || {};
|
|
591
|
+
const macroInfo = Object.fromEntries(macros.map((m) => [m.name, { signature: m.signature }]));
|
|
592
|
+
return (tree) => {
|
|
593
|
+
attachMacroArgs(tree, macroInfo);
|
|
594
|
+
};
|
|
595
595
|
};
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
596
|
+
//#endregion
|
|
597
|
+
//#region libs/html/format.ts
|
|
598
|
+
/**
|
|
599
|
+
* Plugin that pretty-prints HTML.
|
|
600
|
+
*/
|
|
601
|
+
var prettyPrintHtmlPlugin = function() {
|
|
602
|
+
const processor = unified().use(rehypeStringify);
|
|
603
|
+
this.Compiler = (tree, file) => {
|
|
604
|
+
file.extname = ".html";
|
|
605
|
+
const html = processor.stringify(tree, file);
|
|
606
|
+
try {
|
|
607
|
+
return Prettier.format(html, {
|
|
608
|
+
parser: "html",
|
|
609
|
+
useTabs: true
|
|
610
|
+
});
|
|
611
|
+
} catch {}
|
|
612
|
+
return html;
|
|
613
|
+
};
|
|
607
614
|
};
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
615
|
+
//#endregion
|
|
616
|
+
//#region libs/macros/expand-document-macros-plugin.ts
|
|
617
|
+
/**
|
|
618
|
+
* Plugin that expands the specified macros by name. These macros must be defined in the document via
|
|
619
|
+
* `\newcommand...` or equivalent.
|
|
620
|
+
*/
|
|
621
|
+
var expandDocumentMacrosPlugin = function(options) {
|
|
622
|
+
const { macros = [] } = options || {};
|
|
623
|
+
const macrosSet = new Set(macros);
|
|
624
|
+
return (tree) => {
|
|
625
|
+
const macros = listNewcommands(tree).filter((s) => macrosSet.has(s.name));
|
|
626
|
+
attachMacroArgs(tree, Object.fromEntries(macros.map((m) => [m.name, { signature: m.signature }])));
|
|
627
|
+
expandMacrosExcludingDefinitions(tree, macros);
|
|
628
|
+
};
|
|
620
629
|
};
|
|
621
|
-
|
|
622
|
-
|
|
630
|
+
//#endregion
|
|
631
|
+
//#region libs/unified-args/index.ts
|
|
632
|
+
var ttyStream = Object.assign(new stream.Readable(), { isTTY: true });
|
|
633
|
+
var exitStatus = 0;
|
|
623
634
|
process.on("exit", onexit);
|
|
624
635
|
process.on("uncaughtException", fail);
|
|
636
|
+
/**
|
|
637
|
+
* Start the CLI.
|
|
638
|
+
*
|
|
639
|
+
* @param {Options} cliConfig
|
|
640
|
+
*/
|
|
625
641
|
function unifiedArgs(cliConfig) {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
};
|
|
740
|
-
function clean() {
|
|
741
|
-
if (watcher) {
|
|
742
|
-
watcher.close();
|
|
743
|
-
watcher = void 0;
|
|
744
|
-
}
|
|
745
|
-
}
|
|
746
|
-
function subscribe(context) {
|
|
747
|
-
var _a;
|
|
748
|
-
watcher = chokidar.watch(((_a = context.fileSet) == null ? void 0 : _a.origins) || [], {
|
|
749
|
-
cwd: config.cwd != null ? "" + config.cwd : config.cwd,
|
|
750
|
-
ignoreInitial: true
|
|
751
|
-
}).on("error", done).on("change", (filePath) => {
|
|
752
|
-
config.files = [filePath];
|
|
753
|
-
engine(config, done);
|
|
754
|
-
});
|
|
755
|
-
process.on("SIGINT", onsigint);
|
|
756
|
-
function onsigint() {
|
|
757
|
-
process.stderr.write("\n", noop);
|
|
758
|
-
clean();
|
|
759
|
-
if (output === true) {
|
|
760
|
-
config.output = output;
|
|
761
|
-
config.watch = false;
|
|
762
|
-
engine(config, done);
|
|
763
|
-
}
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
engine(config, done);
|
|
642
|
+
let config;
|
|
643
|
+
let watcher;
|
|
644
|
+
let output;
|
|
645
|
+
try {
|
|
646
|
+
config = options(process.argv.slice(2), cliConfig);
|
|
647
|
+
} catch (error) {
|
|
648
|
+
return fail(error, true);
|
|
649
|
+
}
|
|
650
|
+
const processorOptions = {
|
|
651
|
+
macros: {},
|
|
652
|
+
environments: {}
|
|
653
|
+
};
|
|
654
|
+
const originalProcessor = config.processor;
|
|
655
|
+
config.processor = () => originalProcessor(processorOptions);
|
|
656
|
+
if (config.help) {
|
|
657
|
+
process.stdout.write([
|
|
658
|
+
"Usage: " + cliConfig.name + " [options] [path | glob ...]",
|
|
659
|
+
"",
|
|
660
|
+
" " + cliConfig.description,
|
|
661
|
+
"",
|
|
662
|
+
"Options:",
|
|
663
|
+
"",
|
|
664
|
+
config.helpMessage,
|
|
665
|
+
""
|
|
666
|
+
].join("\n"), noop);
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
669
|
+
if (config.version) {
|
|
670
|
+
process.stdout.write(cliConfig.version + "\n", noop);
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
if (config.watch) {
|
|
674
|
+
output = config.output;
|
|
675
|
+
config.streamIn = ttyStream;
|
|
676
|
+
config.out = false;
|
|
677
|
+
process.stderr.write(chalk.bold("Watching...") + " (press CTRL+C to exit)\n", noop);
|
|
678
|
+
if (output === true) {
|
|
679
|
+
config.output = false;
|
|
680
|
+
process.stderr.write(chalk.yellow("Note") + ": Ignoring `--output` until exit.\n", noop);
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
if (config.lints) for (const [lintName, lintArgs] of Object.entries(config.lints)) {
|
|
684
|
+
const lint = availableLints[lintName];
|
|
685
|
+
if (!lint) throw new Error(`Could not find lint named "${lintName}"; available lints are ${Object.keys(availableLints).join(", ")}`);
|
|
686
|
+
config.plugins.push([lint, lintArgs]);
|
|
687
|
+
}
|
|
688
|
+
if (config.stats) config.plugins.push([statsPlugin]);
|
|
689
|
+
if (config.macro.length > 0) config.plugins.push([attachMacroArgsPlugin, { macros: config.macro }]);
|
|
690
|
+
if (config.expandMacro.length > 0) {
|
|
691
|
+
processorOptions.macros = Object.assign(processorOptions.macros || {}, Object.fromEntries(config.expandMacro.map((m) => [m.name, { signature: m.signature }])));
|
|
692
|
+
config.plugins.push([expandMacrosPlugin, { macros: config.expandMacro }]);
|
|
693
|
+
}
|
|
694
|
+
if (config.expandDocumentMacro.length > 0) config.plugins.push([expandDocumentMacrosPlugin, { macros: config.expandDocumentMacro }]);
|
|
695
|
+
if (config.statsJson) config.plugins.push([statsJsonPlugin]);
|
|
696
|
+
if (config.html) {
|
|
697
|
+
config.plugins.push([unifiedLatexToHast]);
|
|
698
|
+
config.plugins.push([prettyPrintHtmlPlugin]);
|
|
699
|
+
}
|
|
700
|
+
if (config.markdown) {
|
|
701
|
+
config.plugins.push([unifiedLatexToMdast]);
|
|
702
|
+
config.plugins.push([remarkStringify]);
|
|
703
|
+
}
|
|
704
|
+
if (config.pretext) {
|
|
705
|
+
config.plugins.push([unifiedLatexToPretext]);
|
|
706
|
+
config.plugins.push([prettyPrintHtmlPlugin]);
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Handle complete run.
|
|
710
|
+
*
|
|
711
|
+
* @type {EngineCallback}
|
|
712
|
+
*/
|
|
713
|
+
const done = function done(error, code, context) {
|
|
714
|
+
if (error) {
|
|
715
|
+
clean();
|
|
716
|
+
fail(error);
|
|
717
|
+
} else {
|
|
718
|
+
exitStatus = code || 0;
|
|
719
|
+
if (config.watch && !watcher && context) subscribe(context);
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
function clean() {
|
|
723
|
+
if (watcher) {
|
|
724
|
+
watcher.close();
|
|
725
|
+
watcher = void 0;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Subscribe a chokidar watcher to all processed files.
|
|
730
|
+
*/
|
|
731
|
+
function subscribe(context) {
|
|
732
|
+
var _context$fileSet;
|
|
733
|
+
watcher = chokidar.watch(((_context$fileSet = context.fileSet) === null || _context$fileSet === void 0 ? void 0 : _context$fileSet.origins) || [], {
|
|
734
|
+
cwd: config.cwd != null ? "" + config.cwd : config.cwd,
|
|
735
|
+
ignoreInitial: true
|
|
736
|
+
}).on("error", done).on("change", (filePath) => {
|
|
737
|
+
config.files = [filePath];
|
|
738
|
+
engine(config, done);
|
|
739
|
+
});
|
|
740
|
+
process.on("SIGINT", onsigint);
|
|
741
|
+
/**
|
|
742
|
+
* Handle a SIGINT.
|
|
743
|
+
*/
|
|
744
|
+
function onsigint() {
|
|
745
|
+
process.stderr.write("\n", noop);
|
|
746
|
+
clean();
|
|
747
|
+
if (output === true) {
|
|
748
|
+
config.output = output;
|
|
749
|
+
config.watch = false;
|
|
750
|
+
engine(config, done);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
engine(config, done);
|
|
767
755
|
}
|
|
756
|
+
/**
|
|
757
|
+
* Print an error, optionally with stack.
|
|
758
|
+
*
|
|
759
|
+
* @param {Error} error
|
|
760
|
+
* @param {boolean} [pretty=false]
|
|
761
|
+
*/
|
|
768
762
|
function fail(error, pretty) {
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
763
|
+
const message = String((pretty ? error : error.stack) || error);
|
|
764
|
+
exitStatus = 1;
|
|
765
|
+
process.stderr.write(message.trim() + "\n", noop);
|
|
772
766
|
}
|
|
773
767
|
function onexit() {
|
|
774
|
-
|
|
775
|
-
}
|
|
776
|
-
function noop() {
|
|
768
|
+
process.exit(exitStatus);
|
|
777
769
|
}
|
|
778
|
-
|
|
770
|
+
function noop() {}
|
|
771
|
+
//#endregion
|
|
772
|
+
//#region index.ts
|
|
773
|
+
var version = "unknown (could not read version from package.json)";
|
|
779
774
|
try {
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
encoding: "utf8"
|
|
783
|
-
})
|
|
784
|
-
);
|
|
785
|
-
version = packageJson.version;
|
|
786
|
-
} catch {
|
|
787
|
-
}
|
|
775
|
+
version = JSON.parse(fs.readFileSync(new URL("data:application/json;base64,ewogICAgIm5hbWUiOiAiQHVuaWZpZWQtbGF0ZXgvdW5pZmllZC1sYXRleC1jbGkiLAogICAgInZlcnNpb24iOiAiMS44LjQiLAogICAgImRlc2NyaXB0aW9uIjogIkNvbW1hbmQgbGluZSBpbnRlcmZhY2UgdG8gY29tbW9uIHVuaWZpZWQtbGF0ZXggb3B0aW9ucyIsCiAgICAibWFpbiI6ICJkaXN0L2luZGV4LmpzIiwKICAgICJ0eXBlIjogIm1vZHVsZSIsCiAgICAiYmluIjogewogICAgICAgICJ1bmlmaWVkLWxhdGV4IjogIi4vdW5pZmllZC1sYXRleC1jbGkubWpzIgogICAgfSwKICAgICJkZXBlbmRlbmNpZXMiOiB7CiAgICAgICAgIkB0eXBlcy9oYXN0IjogIl4yLjMuOSIsCiAgICAgICAgIkB1bmlmaWVkLWxhdGV4L3VuaWZpZWQtbGF0ZXgtbGludCI6ICJeMS44LjQiLAogICAgICAgICJAdW5pZmllZC1sYXRleC91bmlmaWVkLWxhdGV4LXRvLWhhc3QiOiAiXjEuOC40IiwKICAgICAgICAiQHVuaWZpZWQtbGF0ZXgvdW5pZmllZC1sYXRleC10by1tZGFzdCI6ICJeMS44LjQiLAogICAgICAgICJAdW5pZmllZC1sYXRleC91bmlmaWVkLWxhdGV4LXRvLXByZXRleHQiOiAiXjEuOC40IiwKICAgICAgICAiQHVuaWZpZWQtbGF0ZXgvdW5pZmllZC1sYXRleC10eXBlcyI6ICJeMS44LjQiLAogICAgICAgICJAdW5pZmllZC1sYXRleC91bmlmaWVkLWxhdGV4LXV0aWwtYXJndW1lbnRzIjogIl4xLjguNCIsCiAgICAgICAgIkB1bmlmaWVkLWxhdGV4L3VuaWZpZWQtbGF0ZXgtdXRpbC1tYWNyb3MiOiAiXjEuOC40IiwKICAgICAgICAiQHVuaWZpZWQtbGF0ZXgvdW5pZmllZC1sYXRleC11dGlsLXBhY2thZ2VzIjogIl4xLjguNCIsCiAgICAgICAgIkB1bmlmaWVkLWxhdGV4L3VuaWZpZWQtbGF0ZXgtdXRpbC1wYXJzZSI6ICJeMS44LjQiLAogICAgICAgICJAdW5pZmllZC1sYXRleC91bmlmaWVkLWxhdGV4LXV0aWwtcHJpbnQtcmF3IjogIl4xLjguNCIsCiAgICAgICAgIkB1bmlmaWVkLWxhdGV4L3VuaWZpZWQtbGF0ZXgtdXRpbC10by1zdHJpbmciOiAiXjEuOC40IiwKICAgICAgICAiY2FtZWxjYXNlIjogIl43LjAuMSIsCiAgICAgICAgImNoYWxrIjogIl41LjIuMCIsCiAgICAgICAgImNob2tpZGFyIjogIl4zLjUuMyIsCiAgICAgICAgImZhdWx0IjogIl4yLjAuMSIsCiAgICAgICAgImhhc3RzY3JpcHQiOiAiXjcuMi4wIiwKICAgICAgICAianNvbjUiOiAiXjIuMi4zIiwKICAgICAgICAibWluaW1pc3QiOiAiXjEuMi43IiwKICAgICAgICAicHJldHRpZXIiOiAiXjIuOC44IiwKICAgICAgICAicmVoeXBlLXN0cmluZ2lmeSI6ICJeOS4wLjQiLAogICAgICAgICJyZW1hcmstc3RyaW5naWZ5IjogIl4xMC4wLjMiLAogICAgICAgICJ0ZXh0LXRhYmxlIjogIl4wLjIuMCIsCiAgICAgICAgInVuaWZpZWQiOiAiXjEwLjEuMiIsCiAgICAgICAgInVuaWZpZWQtZW5naW5lIjogIl4xMC4xLjAiCiAgICB9LAogICAgImZpbGVzIjogWwogICAgICAgICJkaXN0LyoqLyoudHMiLAogICAgICAgICJkaXN0LyoqLyouanMiLAogICAgICAgICJkaXN0LyoqLyoubWFwIiwKICAgICAgICAiZGlzdC8qKi8qLmpzb24iCiAgICBdLAogICAgImV4cG9ydHMiOiB7CiAgICAgICAgIi4iOiB7CiAgICAgICAgICAgICJwcmVidWlsdCI6ICIuL2Rpc3QvaW5kZXguanMiLAogICAgICAgICAgICAiaW1wb3J0IjogIi4vaW5kZXgudHMiLAogICAgICAgICAgICAicmVxdWlyZSI6ICIuL2Rpc3QvaW5kZXguY2pzIgogICAgICAgIH0sCiAgICAgICAgIi4vKmpzIjogIi4vZGlzdC8qanMiLAogICAgICAgICIuLyoiOiB7CiAgICAgICAgICAgICJwcmVidWlsdCI6ICIuL2Rpc3QvKi5qcyIsCiAgICAgICAgICAgICJpbXBvcnQiOiAiLi8qLnRzIiwKICAgICAgICAgICAgInJlcXVpcmUiOiAiLi9kaXN0LyouY2pzIgogICAgICAgIH0KICAgIH0sCiAgICAic2NyaXB0cyI6IHsKICAgICAgICAiYnVpbGQiOiAibnBtIHJ1biBjbGVhbiAmJiBta2RpcnAgLi9kaXN0ICYmIG5wbSBydW4gY29tcGlsZSIsCiAgICAgICAgImNsZWFuIjogInJpbXJhZiAuL2Rpc3QiLAogICAgICAgICJjb21waWxlIjogIndpcmVpdCIsCiAgICAgICAgImNvbXBpbGU6Y2pzIjogIndpcmVpdCIsCiAgICAgICAgImNvbXBpbGU6ZXNtIjogIndpcmVpdCIsCiAgICAgICAgImNvbXBpbGU6ZXhlY3V0YWJsZSI6ICJlY2hvICcjIS91c3IvYmluL2VudiBub2RlJyA+IGRpc3QvdW5pZmllZC1sYXRleC1jbGkubWpzICYmIGNhdCBkaXN0L2luZGV4LmpzID4+IGRpc3QvdW5pZmllZC1sYXRleC1jbGkubWpzIiwKICAgICAgICAicGFja2FnZSI6ICJub2RlIC4uLy4uL3NjcmlwdHMvbWFrZS1wYWNrYWdlLm1qcyIsCiAgICAgICAgInB1Ymxpc2giOiAiY2QgZGlzdCAmJiBucG0gcHVibGlzaCIsCiAgICAgICAgInRlc3QiOiAidml0ZXN0IgogICAgfSwKICAgICJ3aXJlaXQiOiB7CiAgICAgICAgImNvbXBpbGUiOiB7CiAgICAgICAgICAgICJjb21tYW5kIjogIm5wbSBydW4gY29tcGlsZTpleGVjdXRhYmxlIiwKICAgICAgICAgICAgImRlcGVuZGVuY2llcyI6IFsKICAgICAgICAgICAgICAgICJjb21waWxlOmNqcyIsCiAgICAgICAgICAgICAgICAiY29tcGlsZTplc20iCiAgICAgICAgICAgIF0KICAgICAgICB9LAogICAgICAgICJjb21waWxlOmNqcyI6IHsKICAgICAgICAgICAgImNvbW1hbmQiOiAidml0ZSBidWlsZCAtLW1vZGUgY29tbW9uanMiLAogICAgICAgICAgICAiZmlsZXMiOiBbCiAgICAgICAgICAgICAgICAiaW5kZXgudHMiLAogICAgICAgICAgICAgICAgImxpYnMvKiovKi50cyIsCiAgICAgICAgICAgICAgICAibGlicy8qKi8qLmpzb24iLAogICAgICAgICAgICAgICAgInRzY29uZmlnLmpzb24iLAogICAgICAgICAgICAgICAgInZpdGUuY29uZmlnLnRzIgogICAgICAgICAgICBdLAogICAgICAgICAgICAib3V0cHV0IjogWwogICAgICAgICAgICAgICAgImRpc3QvKiovKi5janMqIgogICAgICAgICAgICBdLAogICAgICAgICAgICAiZGVwZW5kZW5jaWVzIjogWwogICAgICAgICAgICAgICAgImRlcHMiCiAgICAgICAgICAgIF0KICAgICAgICB9LAogICAgICAgICJjb21waWxlOmVzbSI6IHsKICAgICAgICAgICAgImNvbW1hbmQiOiAidml0ZSBidWlsZCIsCiAgICAgICAgICAgICJmaWxlcyI6IFsKICAgICAgICAgICAgICAgICJpbmRleC50cyIsCiAgICAgICAgICAgICAgICAibGlicy8qKi8qLnRzIiwKICAgICAgICAgICAgICAgICJsaWJzLyoqLyouanNvbiIsCiAgICAgICAgICAgICAgICAidHNjb25maWcuanNvbiIsCiAgICAgICAgICAgICAgICAidml0ZS5jb25maWcudHMiCiAgICAgICAgICAgIF0sCiAgICAgICAgICAgICJvdXRwdXQiOiBbCiAgICAgICAgICAgICAgICAiZGlzdC8qKi8qLmpzKiIsCiAgICAgICAgICAgICAgICAiZGlzdC8qKi8qLmpzb24iLAogICAgICAgICAgICAgICAgImRpc3QvKiovKi5kLnRzIiwKICAgICAgICAgICAgICAgICJkaXN0LyoqLyoubWQiCiAgICAgICAgICAgIF0sCiAgICAgICAgICAgICJkZXBlbmRlbmNpZXMiOiBbCiAgICAgICAgICAgICAgICAiZGVwcyIKICAgICAgICAgICAgXQogICAgICAgIH0sCiAgICAgICAgImRlcHMiOiB7CiAgICAgICAgICAgICJkZXBlbmRlbmNpZXMiOiBbCiAgICAgICAgICAgICAgICAiLi4vdW5pZmllZC1sYXRleC1saW50OmNvbXBpbGUiLAogICAgICAgICAgICAgICAgIi4uL3VuaWZpZWQtbGF0ZXgtdG8taGFzdDpjb21waWxlIiwKICAgICAgICAgICAgICAgICIuLi91bmlmaWVkLWxhdGV4LXRvLW1kYXN0OmNvbXBpbGUiLAogICAgICAgICAgICAgICAgIi4uL3VuaWZpZWQtbGF0ZXgtdHlwZXM6Y29tcGlsZSIsCiAgICAgICAgICAgICAgICAiLi4vdW5pZmllZC1sYXRleC11dGlsLWFyZ3VtZW50czpjb21waWxlIiwKICAgICAgICAgICAgICAgICIuLi91bmlmaWVkLWxhdGV4LXV0aWwtbWFjcm9zOmNvbXBpbGUiLAogICAgICAgICAgICAgICAgIi4uL3VuaWZpZWQtbGF0ZXgtdXRpbC1wYWNrYWdlczpjb21waWxlIiwKICAgICAgICAgICAgICAgICIuLi91bmlmaWVkLWxhdGV4LXV0aWwtcGFyc2U6Y29tcGlsZSIsCiAgICAgICAgICAgICAgICAiLi4vdW5pZmllZC1sYXRleC11dGlsLXByaW50LXJhdzpjb21waWxlIiwKICAgICAgICAgICAgICAgICIuLi91bmlmaWVkLWxhdGV4LXV0aWwtdG8tc3RyaW5nOmNvbXBpbGUiCiAgICAgICAgICAgIF0KICAgICAgICB9CiAgICB9LAogICAgInJlcG9zaXRvcnkiOiB7CiAgICAgICAgInR5cGUiOiAiZ2l0IiwKICAgICAgICAidXJsIjogImdpdCtodHRwczovL2dpdGh1Yi5jb20vc2llZmtlbmovdW5pZmllZC1sYXRleC5naXQiCiAgICB9LAogICAgImtleXdvcmRzIjogWwogICAgICAgICJwZWdqcyIsCiAgICAgICAgImxhdGV4IiwKICAgICAgICAicGFyc2VyIiwKICAgICAgICAicHJldHRpZXIiLAogICAgICAgICJ1bmlmaWVkLWxhdGV4IiwKICAgICAgICAidW5pZmllZCIKICAgIF0sCiAgICAiYXV0aG9yIjogIkphc29uIFNpZWZrZW4iLAogICAgImxpY2Vuc2UiOiAiTUlUIiwKICAgICJidWdzIjogewogICAgICAgICJ1cmwiOiAiaHR0cHM6Ly9naXRodWIuY29tL3NpZWZrZW5qL3VuaWZpZWQtbGF0ZXgvaXNzdWVzIgogICAgfSwKICAgICJob21lcGFnZSI6ICJodHRwczovL2dpdGh1Yi5jb20vc2llZmtlbmovdW5pZmllZC1sYXRleCNyZWFkbWUiLAogICAgInByaXZhdGUiOiB0cnVlLAogICAgImRldkRlcGVuZGVuY2llcyI6IHsKICAgICAgICAiQHR5cGVzL2Nyb3NzLXNwYXduIjogIl42LjAuNiIsCiAgICAgICAgImNyb3NzLXNwYXduIjogIl43LjAuMyIsCiAgICAgICAgInNvdXJjZS1tYXAtc3VwcG9ydCI6ICJeMC41LjIxIgogICAgfQp9Cg==", "" + import.meta.url), { encoding: "utf8" })).version;
|
|
776
|
+
} catch {}
|
|
788
777
|
unifiedArgs({
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
778
|
+
processor: processLatexViaUnified,
|
|
779
|
+
name: "unified-latex",
|
|
780
|
+
description: "LaTeX processor powered by unified-latex",
|
|
781
|
+
version,
|
|
782
|
+
extensions: ["tex"],
|
|
783
|
+
ignoreName: ".unifiedlatexignore",
|
|
784
|
+
packageField: "unifiedLatexConfig",
|
|
785
|
+
rcName: ".unifiedlatexrc",
|
|
786
|
+
pluginPrefix: "@unified-latex/"
|
|
798
787
|
});
|
|
799
|
-
|
|
788
|
+
/**
|
|
789
|
+
* ## What is this?
|
|
790
|
+
*
|
|
791
|
+
* Command line interface to common `unified-latex` functions.
|
|
792
|
+
*
|
|
793
|
+
* ## When should I use this?
|
|
794
|
+
*
|
|
795
|
+
* If you want to reformat, process, or gather statistic on LaTeX files from the command line.
|
|
796
|
+
*
|
|
797
|
+
* ## Examples
|
|
798
|
+
*
|
|
799
|
+
* Reformat and pretty-print a file
|
|
800
|
+
*
|
|
801
|
+
* ```bash
|
|
802
|
+
* unified-latex input.tex -o output.tex
|
|
803
|
+
* ```
|
|
804
|
+
*
|
|
805
|
+
* List all commands defined via `\newcommand` and friends (and hide the file output).
|
|
806
|
+
*
|
|
807
|
+
* ```bash
|
|
808
|
+
* unified-latex input.tex --no-stdout --stats
|
|
809
|
+
* ```
|
|
810
|
+
*
|
|
811
|
+
* Expand the definition of the macro `\foo{...}`, which takes one argument.
|
|
812
|
+
*
|
|
813
|
+
* ```bash
|
|
814
|
+
* unified-latex input.tex -e "\\newcommand{foo}[1]{FOO(#1)}"
|
|
815
|
+
* ```
|
|
816
|
+
*
|
|
817
|
+
* View the parsed AST.
|
|
818
|
+
*
|
|
819
|
+
* ```bash
|
|
820
|
+
* unified-latex input.tex --inspect
|
|
821
|
+
* ```
|
|
822
|
+
*
|
|
823
|
+
* Convert the file to HTML. (Note, you will need to include and configure a library like _MathJax_ or _KaTeX_ to render
|
|
824
|
+
* any math in the resulting HTML. Warnings are provided for macros that aren't recognized by the converter.)
|
|
825
|
+
*
|
|
826
|
+
* ```bash
|
|
827
|
+
* unified-latex input.tex -o output.html --html
|
|
828
|
+
* ```
|
|
829
|
+
*
|
|
830
|
+
* Lint all tex files in the current directory and watch for changes.
|
|
831
|
+
*
|
|
832
|
+
* ```bash
|
|
833
|
+
* unified-latex . --no-stdout --lint-all --watch
|
|
834
|
+
* ```
|
|
835
|
+
*/
|
|
836
|
+
//#endregion
|
|
837
|
+
|
|
838
|
+
//# sourceMappingURL=index.js.map
|