@unified-latex/unified-latex 1.4.2 β 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/index.cjs +280 -124
- package/index.cjs.map +4 -4
- package/index.js +1 -1
- package/index.js.map +2 -2
- package/libs/unified-latex.d.ts +2 -1
- package/libs/unified-latex.d.ts.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ import the `.js` file. To explicitly access the commonjs export, import the `.cj
|
|
|
24
24
|
|
|
25
25
|
# Constants
|
|
26
26
|
|
|
27
|
-
| Name | Type
|
|
28
|
-
| :---------------------------- |
|
|
29
|
-
| `processLatexToAstViaUnified` | `() => Processor<Ast.Root, Ast.Root, Ast.Root, void>`
|
|
30
|
-
| `processLatexViaUnified` | `(options?: StringCompilerPluginOptions) => Processor<Ast.Root, Ast.Root, Ast.Root, string>` | Use `unified()` to a string to an `Ast.Ast` and then pretty-print it. |
|
|
27
|
+
| Name | Type | Description |
|
|
28
|
+
| :---------------------------- | :----------------------------------------------------------------------------------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
29
|
+
| `processLatexToAstViaUnified` | `() => Processor<Ast.Root, Ast.Root, Ast.Root, void>` | Use `unified()` to a string to an `Ast.Ast` and then return it. This function
will not print/pretty-print the `Ast.Ast` back to a string. |
|
|
30
|
+
| `processLatexViaUnified` | `(options?: StringCompilerPluginOptions & ParserPluginOptions) => Processor<Ast.Root, Ast.Root, Ast.Root, string>` | Use `unified()` to a string to an `Ast.Ast` and then pretty-print it. |
|
package/index.cjs
CHANGED
|
@@ -2302,21 +2302,26 @@ function index(value) {
|
|
|
2302
2302
|
return value && typeof value === "number" ? value : 1;
|
|
2303
2303
|
}
|
|
2304
2304
|
|
|
2305
|
-
// ../../node_modules/vfile-message/index.js
|
|
2305
|
+
// ../../node_modules/vfile-message/lib/index.js
|
|
2306
2306
|
var VFileMessage = class extends Error {
|
|
2307
2307
|
/**
|
|
2308
2308
|
* Create a message for `reason` at `place` from `origin`.
|
|
2309
2309
|
*
|
|
2310
2310
|
* When an error is passed in as `reason`, the `stack` is copied.
|
|
2311
2311
|
*
|
|
2312
|
-
* @param {string|Error|VFileMessage} reason
|
|
2313
|
-
* Reason for message.
|
|
2314
|
-
*
|
|
2315
|
-
*
|
|
2316
|
-
*
|
|
2317
|
-
*
|
|
2318
|
-
*
|
|
2312
|
+
* @param {string | Error | VFileMessage} reason
|
|
2313
|
+
* Reason for message, uses the stack and message of the error if given.
|
|
2314
|
+
*
|
|
2315
|
+
* > π **Note**: you should use markdown.
|
|
2316
|
+
* @param {Node | NodeLike | Position | Point | null | undefined} [place]
|
|
2317
|
+
* Place in file where the message occurred.
|
|
2318
|
+
* @param {string | null | undefined} [origin]
|
|
2319
|
+
* Place in code where the message originates (example:
|
|
2320
|
+
* `'my-package:my-rule'` or `'my-rule'`).
|
|
2321
|
+
* @returns
|
|
2322
|
+
* Instance of `VFileMessage`.
|
|
2319
2323
|
*/
|
|
2324
|
+
// To do: next major: expose `undefined` everywhere instead of `null`.
|
|
2320
2325
|
constructor(reason, place, origin) {
|
|
2321
2326
|
const parts = [null, null];
|
|
2322
2327
|
let position2 = {
|
|
@@ -2602,10 +2607,10 @@ function cwd() {
|
|
|
2602
2607
|
}
|
|
2603
2608
|
|
|
2604
2609
|
// ../../node_modules/vfile/lib/minurl.shared.js
|
|
2605
|
-
function isUrl(
|
|
2606
|
-
return
|
|
2607
|
-
|
|
2608
|
-
|
|
2610
|
+
function isUrl(fileUrlOrPath) {
|
|
2611
|
+
return fileUrlOrPath !== null && typeof fileUrlOrPath === "object" && // @ts-expect-error: indexable.
|
|
2612
|
+
fileUrlOrPath.href && // @ts-expect-error: indexable.
|
|
2613
|
+
fileUrlOrPath.origin;
|
|
2609
2614
|
}
|
|
2610
2615
|
|
|
2611
2616
|
// ../../node_modules/vfile/lib/minurl.browser.js
|
|
@@ -2657,25 +2662,30 @@ var VFile = class {
|
|
|
2657
2662
|
/**
|
|
2658
2663
|
* Create a new virtual file.
|
|
2659
2664
|
*
|
|
2660
|
-
*
|
|
2661
|
-
*
|
|
2662
|
-
*
|
|
2663
|
-
*
|
|
2665
|
+
* `options` is treated as:
|
|
2666
|
+
*
|
|
2667
|
+
* * `string` or `Buffer` β `{value: options}`
|
|
2668
|
+
* * `URL` β `{path: options}`
|
|
2669
|
+
* * `VFile` β shallow copies its data over to the new file
|
|
2670
|
+
* * `object` β all fields are shallow copied over to the new file
|
|
2664
2671
|
*
|
|
2665
2672
|
* Path related fields are set in the following order (least specific to
|
|
2666
2673
|
* most specific): `history`, `path`, `basename`, `stem`, `extname`,
|
|
2667
2674
|
* `dirname`.
|
|
2668
2675
|
*
|
|
2669
|
-
*
|
|
2670
|
-
*
|
|
2676
|
+
* You cannot set `dirname` or `extname` without setting either `history`,
|
|
2677
|
+
* `path`, `basename`, or `stem` too.
|
|
2671
2678
|
*
|
|
2672
|
-
* @param {Compatible} [value]
|
|
2679
|
+
* @param {Compatible | null | undefined} [value]
|
|
2680
|
+
* File value.
|
|
2681
|
+
* @returns
|
|
2682
|
+
* New instance.
|
|
2673
2683
|
*/
|
|
2674
2684
|
constructor(value) {
|
|
2675
2685
|
let options;
|
|
2676
2686
|
if (!value) {
|
|
2677
2687
|
options = {};
|
|
2678
|
-
} else if (typeof value === "string" || (
|
|
2688
|
+
} else if (typeof value === "string" || buffer(value)) {
|
|
2679
2689
|
options = { value };
|
|
2680
2690
|
} else if (isUrl(value)) {
|
|
2681
2691
|
options = { path: value };
|
|
@@ -2693,18 +2703,20 @@ var VFile = class {
|
|
|
2693
2703
|
let index2 = -1;
|
|
2694
2704
|
while (++index2 < order.length) {
|
|
2695
2705
|
const prop2 = order[index2];
|
|
2696
|
-
if (prop2 in options && options[prop2] !== void 0) {
|
|
2706
|
+
if (prop2 in options && options[prop2] !== void 0 && options[prop2] !== null) {
|
|
2697
2707
|
this[prop2] = prop2 === "history" ? [...options[prop2]] : options[prop2];
|
|
2698
2708
|
}
|
|
2699
2709
|
}
|
|
2700
2710
|
let prop;
|
|
2701
2711
|
for (prop in options) {
|
|
2702
|
-
if (!order.includes(prop))
|
|
2712
|
+
if (!order.includes(prop)) {
|
|
2703
2713
|
this[prop] = options[prop];
|
|
2714
|
+
}
|
|
2704
2715
|
}
|
|
2705
2716
|
}
|
|
2706
2717
|
/**
|
|
2707
2718
|
* Get the full path (example: `'~/index.min.js'`).
|
|
2719
|
+
*
|
|
2708
2720
|
* @returns {string}
|
|
2709
2721
|
*/
|
|
2710
2722
|
get path() {
|
|
@@ -2712,10 +2724,12 @@ var VFile = class {
|
|
|
2712
2724
|
}
|
|
2713
2725
|
/**
|
|
2714
2726
|
* Set the full path (example: `'~/index.min.js'`).
|
|
2727
|
+
*
|
|
2715
2728
|
* Cannot be nullified.
|
|
2716
2729
|
* You can set a file URL (a `URL` object with a `file:` protocol) which will
|
|
2717
2730
|
* be turned into a path with `url.fileURLToPath`.
|
|
2718
|
-
*
|
|
2731
|
+
*
|
|
2732
|
+
* @param {string | URL} path
|
|
2719
2733
|
*/
|
|
2720
2734
|
set path(path2) {
|
|
2721
2735
|
if (isUrl(path2)) {
|
|
@@ -2734,6 +2748,7 @@ var VFile = class {
|
|
|
2734
2748
|
}
|
|
2735
2749
|
/**
|
|
2736
2750
|
* Set the parent path (example: `'~'`).
|
|
2751
|
+
*
|
|
2737
2752
|
* Cannot be set if thereβs no `path` yet.
|
|
2738
2753
|
*/
|
|
2739
2754
|
set dirname(dirname2) {
|
|
@@ -2748,6 +2763,7 @@ var VFile = class {
|
|
|
2748
2763
|
}
|
|
2749
2764
|
/**
|
|
2750
2765
|
* Set basename (including extname) (`'index.min.js'`).
|
|
2766
|
+
*
|
|
2751
2767
|
* Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
|
|
2752
2768
|
* on windows).
|
|
2753
2769
|
* Cannot be nullified (use `file.path = file.dirname` instead).
|
|
@@ -2765,6 +2781,7 @@ var VFile = class {
|
|
|
2765
2781
|
}
|
|
2766
2782
|
/**
|
|
2767
2783
|
* Set the extname (including dot) (example: `'.js'`).
|
|
2784
|
+
*
|
|
2768
2785
|
* Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
|
|
2769
2786
|
* on windows).
|
|
2770
2787
|
* Cannot be set if thereβs no `path` yet.
|
|
@@ -2790,6 +2807,7 @@ var VFile = class {
|
|
|
2790
2807
|
}
|
|
2791
2808
|
/**
|
|
2792
2809
|
* Set the stem (basename w/o extname) (example: `'index.min'`).
|
|
2810
|
+
*
|
|
2793
2811
|
* Cannot contain path separators (`'/'` on unix, macOS, and browsers, `'\'`
|
|
2794
2812
|
* on windows).
|
|
2795
2813
|
* Cannot be nullified (use `file.path = file.dirname` instead).
|
|
@@ -2802,26 +2820,28 @@ var VFile = class {
|
|
|
2802
2820
|
/**
|
|
2803
2821
|
* Serialize the file.
|
|
2804
2822
|
*
|
|
2805
|
-
* @param {BufferEncoding} [encoding='utf8']
|
|
2806
|
-
*
|
|
2807
|
-
*
|
|
2823
|
+
* @param {BufferEncoding | null | undefined} [encoding='utf8']
|
|
2824
|
+
* Character encoding to understand `value` as when itβs a `Buffer`
|
|
2825
|
+
* (default: `'utf8'`).
|
|
2808
2826
|
* @returns {string}
|
|
2809
2827
|
* Serialized file.
|
|
2810
2828
|
*/
|
|
2811
2829
|
toString(encoding) {
|
|
2812
|
-
return (this.value || "").toString(encoding);
|
|
2830
|
+
return (this.value || "").toString(encoding || void 0);
|
|
2813
2831
|
}
|
|
2814
2832
|
/**
|
|
2815
|
-
*
|
|
2816
|
-
* associates it with the file by adding it to `vfile.messages` and setting
|
|
2817
|
-
* `message.file` to the current filepath.
|
|
2833
|
+
* Create a warning message associated with the file.
|
|
2818
2834
|
*
|
|
2819
|
-
*
|
|
2820
|
-
*
|
|
2821
|
-
*
|
|
2822
|
-
*
|
|
2823
|
-
*
|
|
2824
|
-
*
|
|
2835
|
+
* Its `fatal` is set to `false` and `file` is set to the current file path.
|
|
2836
|
+
* Its added to `file.messages`.
|
|
2837
|
+
*
|
|
2838
|
+
* @param {string | Error | VFileMessage} reason
|
|
2839
|
+
* Reason for message, uses the stack and message of the error if given.
|
|
2840
|
+
* @param {Node | NodeLike | Position | Point | null | undefined} [place]
|
|
2841
|
+
* Place in file where the message occurred.
|
|
2842
|
+
* @param {string | null | undefined} [origin]
|
|
2843
|
+
* Place in code where the message originates (example:
|
|
2844
|
+
* `'my-package:my-rule'` or `'my-rule'`).
|
|
2825
2845
|
* @returns {VFileMessage}
|
|
2826
2846
|
* Message.
|
|
2827
2847
|
*/
|
|
@@ -2836,15 +2856,18 @@ var VFile = class {
|
|
|
2836
2856
|
return message;
|
|
2837
2857
|
}
|
|
2838
2858
|
/**
|
|
2839
|
-
*
|
|
2840
|
-
*
|
|
2859
|
+
* Create an info message associated with the file.
|
|
2860
|
+
*
|
|
2861
|
+
* Its `fatal` is set to `null` and `file` is set to the current file path.
|
|
2862
|
+
* Its added to `file.messages`.
|
|
2841
2863
|
*
|
|
2842
|
-
* @param {string|Error|VFileMessage} reason
|
|
2843
|
-
*
|
|
2844
|
-
* @param {Node|NodeLike|Position|Point} [place]
|
|
2845
|
-
* Place where the message occurred
|
|
2846
|
-
* @param {string} [origin]
|
|
2847
|
-
*
|
|
2864
|
+
* @param {string | Error | VFileMessage} reason
|
|
2865
|
+
* Reason for message, uses the stack and message of the error if given.
|
|
2866
|
+
* @param {Node | NodeLike | Position | Point | null | undefined} [place]
|
|
2867
|
+
* Place in file where the message occurred.
|
|
2868
|
+
* @param {string | null | undefined} [origin]
|
|
2869
|
+
* Place in code where the message originates (example:
|
|
2870
|
+
* `'my-package:my-rule'` or `'my-rule'`).
|
|
2848
2871
|
* @returns {VFileMessage}
|
|
2849
2872
|
* Message.
|
|
2850
2873
|
*/
|
|
@@ -2854,19 +2877,24 @@ var VFile = class {
|
|
|
2854
2877
|
return message;
|
|
2855
2878
|
}
|
|
2856
2879
|
/**
|
|
2857
|
-
*
|
|
2858
|
-
*
|
|
2880
|
+
* Create a fatal error associated with the file.
|
|
2881
|
+
*
|
|
2882
|
+
* Its `fatal` is set to `true` and `file` is set to the current file path.
|
|
2883
|
+
* Its added to `file.messages`.
|
|
2859
2884
|
*
|
|
2860
2885
|
* > π **Note**: a fatal error means that a file is no longer processable.
|
|
2861
2886
|
*
|
|
2862
|
-
* @param {string|Error|VFileMessage} reason
|
|
2863
|
-
*
|
|
2864
|
-
* @param {Node|NodeLike|Position|Point} [place]
|
|
2865
|
-
* Place where the message occurred
|
|
2866
|
-
* @param {string} [origin]
|
|
2867
|
-
*
|
|
2887
|
+
* @param {string | Error | VFileMessage} reason
|
|
2888
|
+
* Reason for message, uses the stack and message of the error if given.
|
|
2889
|
+
* @param {Node | NodeLike | Position | Point | null | undefined} [place]
|
|
2890
|
+
* Place in file where the message occurred.
|
|
2891
|
+
* @param {string | null | undefined} [origin]
|
|
2892
|
+
* Place in code where the message originates (example:
|
|
2893
|
+
* `'my-package:my-rule'` or `'my-rule'`).
|
|
2868
2894
|
* @returns {never}
|
|
2869
2895
|
* Message.
|
|
2896
|
+
* @throws {VFileMessage}
|
|
2897
|
+
* Message.
|
|
2870
2898
|
*/
|
|
2871
2899
|
fail(reason, place, origin) {
|
|
2872
2900
|
const message = this.message(reason, place, origin);
|
|
@@ -2891,6 +2919,9 @@ function assertPath2(path2, name) {
|
|
|
2891
2919
|
throw new Error("Setting `" + name + "` requires `path` to be set too");
|
|
2892
2920
|
}
|
|
2893
2921
|
}
|
|
2922
|
+
function buffer(value) {
|
|
2923
|
+
return (0, import_is_buffer.default)(value);
|
|
2924
|
+
}
|
|
2894
2925
|
|
|
2895
2926
|
// ../../node_modules/unified/lib/index.js
|
|
2896
2927
|
var unified = base().freeze();
|
|
@@ -3273,8 +3304,8 @@ function _printRaw(node) {
|
|
|
3273
3304
|
case "argument":
|
|
3274
3305
|
return [node.openMark, ..._printRaw(node.content), node.closeMark];
|
|
3275
3306
|
case "comment":
|
|
3276
|
-
|
|
3277
|
-
|
|
3307
|
+
let suffix = node.suffixParbreak ? "" : linebreak;
|
|
3308
|
+
let leadingWhitespace = "";
|
|
3278
3309
|
if (node.sameline && node.leadingWhitespace) {
|
|
3279
3310
|
leadingWhitespace = " ";
|
|
3280
3311
|
}
|
|
@@ -3290,9 +3321,9 @@ function _printRaw(node) {
|
|
|
3290
3321
|
case "environment":
|
|
3291
3322
|
case "mathenv":
|
|
3292
3323
|
case "verbatim":
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3324
|
+
let env = _printRaw(node.env);
|
|
3325
|
+
let envStart = [ESCAPE + "begin{", ...env, "}"];
|
|
3326
|
+
let envEnd = [ESCAPE + "end{", ...env, "}"];
|
|
3296
3327
|
argsString = node.args == null ? [] : _printRaw(node.args);
|
|
3297
3328
|
return [
|
|
3298
3329
|
...envStart,
|
|
@@ -21340,31 +21371,14 @@ function gobbleSingleArgument(nodes, argSpec, startPos = 0) {
|
|
|
21340
21371
|
const openMark = argSpec.openBrace || "";
|
|
21341
21372
|
const closeMark = argSpec.closeBrace || "";
|
|
21342
21373
|
const acceptGroup = (argSpec.type === "mandatory" || argSpec.type === "optional") && openMark === "{" && closeMark === "}";
|
|
21343
|
-
function findBracePositions() {
|
|
21344
|
-
let openMarkPos = null;
|
|
21345
|
-
if (openMark) {
|
|
21346
|
-
openMarkPos = nodes.findIndex(
|
|
21347
|
-
(node, i) => i >= currPos && match.string(node, openMark)
|
|
21348
|
-
);
|
|
21349
|
-
if (openMarkPos < currPos) {
|
|
21350
|
-
openMarkPos = null;
|
|
21351
|
-
}
|
|
21352
|
-
}
|
|
21353
|
-
let closeMarkPos = null;
|
|
21354
|
-
if (openMarkPos != null) {
|
|
21355
|
-
closeMarkPos = nodes.findIndex(
|
|
21356
|
-
(node, i) => i >= openMarkPos + 1 && match.string(node, closeMark)
|
|
21357
|
-
);
|
|
21358
|
-
if (closeMarkPos < openMarkPos + 1) {
|
|
21359
|
-
closeMarkPos = null;
|
|
21360
|
-
}
|
|
21361
|
-
}
|
|
21362
|
-
return [openMarkPos, closeMarkPos];
|
|
21363
|
-
}
|
|
21364
21374
|
gobbleWhitespace();
|
|
21365
21375
|
const currNode = nodes[currPos];
|
|
21366
21376
|
if (currNode == null || match.comment(currNode) || match.parbreak(currNode)) {
|
|
21367
|
-
|
|
21377
|
+
const ret = {
|
|
21378
|
+
argument: argument2,
|
|
21379
|
+
nodesRemoved: 0
|
|
21380
|
+
};
|
|
21381
|
+
return ret;
|
|
21368
21382
|
}
|
|
21369
21383
|
switch (argSpec.type) {
|
|
21370
21384
|
case "mandatory":
|
|
@@ -21379,6 +21393,21 @@ function gobbleSingleArgument(nodes, argSpec, startPos = 0) {
|
|
|
21379
21393
|
});
|
|
21380
21394
|
currPos++;
|
|
21381
21395
|
break;
|
|
21396
|
+
} else {
|
|
21397
|
+
const bracePos2 = findBracePositions(
|
|
21398
|
+
nodes,
|
|
21399
|
+
currPos,
|
|
21400
|
+
openMark,
|
|
21401
|
+
closeMark
|
|
21402
|
+
);
|
|
21403
|
+
if (bracePos2) {
|
|
21404
|
+
argument2 = arg(nodes.slice(bracePos2[0] + 1, bracePos2[1]), {
|
|
21405
|
+
openMark,
|
|
21406
|
+
closeMark
|
|
21407
|
+
});
|
|
21408
|
+
currPos = bracePos2[1] + 1;
|
|
21409
|
+
break;
|
|
21410
|
+
}
|
|
21382
21411
|
}
|
|
21383
21412
|
case "optional":
|
|
21384
21413
|
if (acceptGroup && match.group(currNode)) {
|
|
@@ -21389,29 +21418,34 @@ function gobbleSingleArgument(nodes, argSpec, startPos = 0) {
|
|
|
21389
21418
|
currPos++;
|
|
21390
21419
|
break;
|
|
21391
21420
|
}
|
|
21392
|
-
|
|
21393
|
-
|
|
21394
|
-
|
|
21395
|
-
|
|
21396
|
-
|
|
21397
|
-
|
|
21398
|
-
|
|
21399
|
-
|
|
21400
|
-
|
|
21401
|
-
|
|
21421
|
+
const bracePos = findBracePositions(
|
|
21422
|
+
nodes,
|
|
21423
|
+
currPos,
|
|
21424
|
+
openMark,
|
|
21425
|
+
closeMark
|
|
21426
|
+
);
|
|
21427
|
+
if (bracePos) {
|
|
21428
|
+
argument2 = arg(nodes.slice(bracePos[0] + 1, bracePos[1]), {
|
|
21429
|
+
openMark,
|
|
21430
|
+
closeMark
|
|
21431
|
+
});
|
|
21432
|
+
currPos = bracePos[1] + 1;
|
|
21433
|
+
break;
|
|
21402
21434
|
}
|
|
21403
21435
|
break;
|
|
21404
21436
|
case "optionalStar":
|
|
21405
|
-
case "optionalToken":
|
|
21406
|
-
|
|
21407
|
-
|
|
21437
|
+
case "optionalToken": {
|
|
21438
|
+
const bracePos2 = findBracePositions(
|
|
21439
|
+
nodes,
|
|
21440
|
+
currPos,
|
|
21408
21441
|
argSpec.type === "optionalStar" ? "*" : argSpec.token
|
|
21409
|
-
)
|
|
21410
|
-
|
|
21411
|
-
|
|
21412
|
-
|
|
21442
|
+
);
|
|
21443
|
+
if (bracePos2) {
|
|
21444
|
+
argument2 = arg(currNode, { openMark: "", closeMark: "" });
|
|
21445
|
+
currPos = bracePos2[0] + 1;
|
|
21413
21446
|
}
|
|
21414
21447
|
break;
|
|
21448
|
+
}
|
|
21415
21449
|
case "until": {
|
|
21416
21450
|
if (argSpec.stopTokens.length > 1) {
|
|
21417
21451
|
console.warn(
|
|
@@ -21420,30 +21454,45 @@ function gobbleSingleArgument(nodes, argSpec, startPos = 0) {
|
|
|
21420
21454
|
break;
|
|
21421
21455
|
}
|
|
21422
21456
|
const rawToken = argSpec.stopTokens[0];
|
|
21423
|
-
const stopToken = rawToken === " " ? { type: "whitespace" } :
|
|
21424
|
-
let
|
|
21425
|
-
|
|
21426
|
-
|
|
21427
|
-
|
|
21428
|
-
|
|
21429
|
-
|
|
21430
|
-
|
|
21431
|
-
);
|
|
21432
|
-
break;
|
|
21433
|
-
}
|
|
21434
|
-
if (matchPos == null) {
|
|
21457
|
+
const stopToken = rawToken === " " ? { type: "whitespace" } : rawToken;
|
|
21458
|
+
let bracePos2 = findBracePositions(
|
|
21459
|
+
nodes,
|
|
21460
|
+
startPos,
|
|
21461
|
+
void 0,
|
|
21462
|
+
stopToken
|
|
21463
|
+
);
|
|
21464
|
+
if (!bracePos2) {
|
|
21435
21465
|
break;
|
|
21436
21466
|
}
|
|
21437
|
-
argument2 = arg(nodes.slice(startPos,
|
|
21467
|
+
argument2 = arg(nodes.slice(startPos, bracePos2[1]), {
|
|
21438
21468
|
openMark: "",
|
|
21439
21469
|
closeMark: rawToken
|
|
21440
21470
|
});
|
|
21441
|
-
currPos =
|
|
21471
|
+
currPos = bracePos2[1];
|
|
21442
21472
|
if (currPos < nodes.length) {
|
|
21443
21473
|
currPos++;
|
|
21444
21474
|
}
|
|
21445
21475
|
break;
|
|
21446
21476
|
}
|
|
21477
|
+
case "embellishment": {
|
|
21478
|
+
for (const token of argSpec.embellishmentTokens) {
|
|
21479
|
+
const bracePos2 = findBracePositions(nodes, currPos, token);
|
|
21480
|
+
if (!bracePos2) {
|
|
21481
|
+
continue;
|
|
21482
|
+
}
|
|
21483
|
+
let argNode = nodes[bracePos2[0] + 1];
|
|
21484
|
+
argument2 = arg(
|
|
21485
|
+
match.group(argNode) ? argNode.content : argNode,
|
|
21486
|
+
{
|
|
21487
|
+
openMark: token,
|
|
21488
|
+
closeMark: ""
|
|
21489
|
+
}
|
|
21490
|
+
);
|
|
21491
|
+
currPos = bracePos2[1] + 1;
|
|
21492
|
+
break;
|
|
21493
|
+
}
|
|
21494
|
+
break;
|
|
21495
|
+
}
|
|
21447
21496
|
default:
|
|
21448
21497
|
console.warn(
|
|
21449
21498
|
`Don't know how to find an argument of argspec type "${argSpec.type}"`
|
|
@@ -21453,8 +21502,84 @@ function gobbleSingleArgument(nodes, argSpec, startPos = 0) {
|
|
|
21453
21502
|
nodes.splice(startPos, nodesRemoved);
|
|
21454
21503
|
return { argument: argument2, nodesRemoved };
|
|
21455
21504
|
}
|
|
21456
|
-
function
|
|
21457
|
-
return
|
|
21505
|
+
function cloneStringNode(node, content) {
|
|
21506
|
+
return Object.assign({}, node, { content });
|
|
21507
|
+
}
|
|
21508
|
+
function findBracePositions(nodes, startPos, openMark, closeMark) {
|
|
21509
|
+
const currNode = nodes[startPos];
|
|
21510
|
+
let openMarkPos = startPos;
|
|
21511
|
+
let closeMarkPos = startPos;
|
|
21512
|
+
if (openMark) {
|
|
21513
|
+
if (!match.anyString(currNode)) {
|
|
21514
|
+
return;
|
|
21515
|
+
}
|
|
21516
|
+
const nodeContent = currNode.content;
|
|
21517
|
+
if (!nodeContent.startsWith(openMark)) {
|
|
21518
|
+
return;
|
|
21519
|
+
}
|
|
21520
|
+
openMarkPos = startPos;
|
|
21521
|
+
if (currNode.content.length > openMark.length) {
|
|
21522
|
+
const nodeContent2 = currNode.content;
|
|
21523
|
+
currNode.content = openMark;
|
|
21524
|
+
nodes.splice(
|
|
21525
|
+
openMarkPos + 1,
|
|
21526
|
+
0,
|
|
21527
|
+
cloneStringNode(currNode, nodeContent2.slice(openMark.length))
|
|
21528
|
+
);
|
|
21529
|
+
}
|
|
21530
|
+
closeMarkPos = openMarkPos + 1;
|
|
21531
|
+
}
|
|
21532
|
+
if (!closeMark) {
|
|
21533
|
+
const argNode = nodes[closeMarkPos];
|
|
21534
|
+
if (!argNode) {
|
|
21535
|
+
return;
|
|
21536
|
+
}
|
|
21537
|
+
if (match.anyString(argNode) && argNode.content.length > 1) {
|
|
21538
|
+
const argContent = argNode.content;
|
|
21539
|
+
argNode.content = argContent[0];
|
|
21540
|
+
nodes.splice(
|
|
21541
|
+
closeMarkPos + 1,
|
|
21542
|
+
0,
|
|
21543
|
+
cloneStringNode(argNode, argContent.slice(1))
|
|
21544
|
+
);
|
|
21545
|
+
}
|
|
21546
|
+
return [openMarkPos, closeMarkPos];
|
|
21547
|
+
}
|
|
21548
|
+
closeMarkPos = scan(nodes, closeMark, {
|
|
21549
|
+
startIndex: closeMarkPos,
|
|
21550
|
+
allowSubstringMatches: true
|
|
21551
|
+
});
|
|
21552
|
+
if (closeMarkPos === null) {
|
|
21553
|
+
return;
|
|
21554
|
+
}
|
|
21555
|
+
const closingNode = nodes[closeMarkPos];
|
|
21556
|
+
if (match.anyString(closingNode) && typeof closeMark === "string") {
|
|
21557
|
+
const closingNodeContent = closingNode.content;
|
|
21558
|
+
let closeMarkIndex = closingNodeContent.indexOf(closeMark);
|
|
21559
|
+
if (closingNodeContent.length > closeMark.length) {
|
|
21560
|
+
closingNode.content = closeMark;
|
|
21561
|
+
const prev = closingNodeContent.slice(0, closeMarkIndex);
|
|
21562
|
+
const next = closingNodeContent.slice(
|
|
21563
|
+
closeMarkIndex + closeMark.length
|
|
21564
|
+
);
|
|
21565
|
+
if (prev) {
|
|
21566
|
+
nodes.splice(
|
|
21567
|
+
closeMarkPos,
|
|
21568
|
+
0,
|
|
21569
|
+
cloneStringNode(closingNode, prev)
|
|
21570
|
+
);
|
|
21571
|
+
closeMarkPos++;
|
|
21572
|
+
}
|
|
21573
|
+
if (next) {
|
|
21574
|
+
nodes.splice(
|
|
21575
|
+
closeMarkPos + 1,
|
|
21576
|
+
0,
|
|
21577
|
+
cloneStringNode(closingNode, next)
|
|
21578
|
+
);
|
|
21579
|
+
}
|
|
21580
|
+
}
|
|
21581
|
+
}
|
|
21582
|
+
return [openMarkPos, closeMarkPos];
|
|
21458
21583
|
}
|
|
21459
21584
|
function gobbleArguments(nodes, argSpec, startPos = 0) {
|
|
21460
21585
|
if (typeof argSpec === "function") {
|
|
@@ -21466,20 +21591,50 @@ function gobbleArguments(nodes, argSpec, startPos = 0) {
|
|
|
21466
21591
|
const args = [];
|
|
21467
21592
|
let nodesRemoved = 0;
|
|
21468
21593
|
for (const spec of argSpec) {
|
|
21469
|
-
|
|
21470
|
-
|
|
21471
|
-
|
|
21472
|
-
|
|
21473
|
-
|
|
21474
|
-
|
|
21475
|
-
|
|
21476
|
-
|
|
21594
|
+
if (spec.type === "embellishment") {
|
|
21595
|
+
const remainingTokens = new Set(spec.embellishmentTokens);
|
|
21596
|
+
const argForToken = Object.fromEntries(
|
|
21597
|
+
spec.embellishmentTokens.map((t) => [t, emptyArg()])
|
|
21598
|
+
);
|
|
21599
|
+
let { argument: argument2, nodesRemoved: removed } = gobbleSingleArgument(
|
|
21600
|
+
nodes,
|
|
21601
|
+
embellishmentSpec(remainingTokens),
|
|
21602
|
+
startPos
|
|
21603
|
+
);
|
|
21604
|
+
while (argument2) {
|
|
21605
|
+
const token = argument2.openMark;
|
|
21606
|
+
remainingTokens.delete(token);
|
|
21607
|
+
argForToken[token] = argument2;
|
|
21608
|
+
nodesRemoved += removed;
|
|
21609
|
+
const newSpec = embellishmentSpec(remainingTokens);
|
|
21610
|
+
({ argument: argument2, nodesRemoved: removed } = gobbleSingleArgument(
|
|
21611
|
+
nodes,
|
|
21612
|
+
newSpec,
|
|
21613
|
+
startPos
|
|
21614
|
+
));
|
|
21615
|
+
}
|
|
21616
|
+
args.push(...spec.embellishmentTokens.map((t) => argForToken[t]));
|
|
21477
21617
|
} else {
|
|
21478
|
-
|
|
21618
|
+
const { argument: argument2, nodesRemoved: removed } = gobbleSingleArgument(
|
|
21619
|
+
nodes,
|
|
21620
|
+
spec,
|
|
21621
|
+
startPos
|
|
21622
|
+
);
|
|
21623
|
+
args.push(argument2 || emptyArg());
|
|
21624
|
+
nodesRemoved += removed;
|
|
21479
21625
|
}
|
|
21480
21626
|
}
|
|
21481
21627
|
return { args, nodesRemoved };
|
|
21482
21628
|
}
|
|
21629
|
+
function embellishmentSpec(tokens) {
|
|
21630
|
+
return {
|
|
21631
|
+
type: "embellishment",
|
|
21632
|
+
embellishmentTokens: [...tokens]
|
|
21633
|
+
};
|
|
21634
|
+
}
|
|
21635
|
+
function emptyArg() {
|
|
21636
|
+
return arg([], { openMark: "", closeMark: "" });
|
|
21637
|
+
}
|
|
21483
21638
|
function attachMacroArgsInArray(nodes, macros17) {
|
|
21484
21639
|
let currIndex;
|
|
21485
21640
|
const isRelevantMacro = match.createMacroMatcher(macros17);
|
|
@@ -21699,7 +21854,7 @@ var macros4 = {
|
|
|
21699
21854
|
var environments4 = {};
|
|
21700
21855
|
var macros5 = {
|
|
21701
21856
|
// Special
|
|
21702
|
-
"\\": { signature: "!s !o" },
|
|
21857
|
+
"\\": { signature: "!s !o", renderInfo: { breakAfter: true } },
|
|
21703
21858
|
_: { signature: "m", escapeToken: "" },
|
|
21704
21859
|
"^": { signature: "m", escapeToken: "" },
|
|
21705
21860
|
// \newcommand arg signature from https://www.texdev.net/2020/08/19/the-good-the-bad-and-the-ugly-creating-document-commands
|
|
@@ -22443,8 +22598,9 @@ var macros11 = {
|
|
|
22443
22598
|
};
|
|
22444
22599
|
var environments11 = {};
|
|
22445
22600
|
(function() {
|
|
22446
|
-
if (typeof globalThis === "object")
|
|
22601
|
+
if (typeof globalThis === "object") {
|
|
22447
22602
|
return;
|
|
22603
|
+
}
|
|
22448
22604
|
Object.defineProperty(Object.prototype, "__magic__", {
|
|
22449
22605
|
get: function() {
|
|
22450
22606
|
return this;
|
|
@@ -38496,7 +38652,7 @@ var processor = unified().use(unifiedLatexStringCompiler, { pretty: true }).free
|
|
|
38496
38652
|
|
|
38497
38653
|
// libs/unified-latex.ts
|
|
38498
38654
|
var processLatexViaUnified = (options) => {
|
|
38499
|
-
return unified().use(unifiedLatexFromString).use(
|
|
38655
|
+
return unified().use(unifiedLatexFromString, options).use(
|
|
38500
38656
|
unifiedLatexStringCompiler,
|
|
38501
38657
|
Object.assign({ pretty: true }, options)
|
|
38502
38658
|
);
|