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