@intentic/fileq 1.430.0 → 1.432.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/NOTICE +58 -1
- package/README.md +29 -1
- package/bin/fileq-rg-pre +6 -2
- package/dist/app.d.ts.map +1 -1
- package/dist/app.js +4 -1
- package/dist/app.js.map +1 -1
- package/dist/commands/check.command.d.ts.map +1 -1
- package/dist/commands/check.command.js +12 -5
- package/dist/commands/check.command.js.map +1 -1
- package/dist/commands/derive.command.d.ts.map +1 -1
- package/dist/commands/derive.command.js +3 -2
- package/dist/commands/derive.command.js.map +1 -1
- package/dist/commands/read.command.d.ts.map +1 -1
- package/dist/commands/read.command.js +42 -7
- package/dist/commands/read.command.js.map +1 -1
- package/dist/commands/render.command.d.ts.map +1 -1
- package/dist/commands/render.command.js +23 -10
- package/dist/commands/render.command.js.map +1 -1
- package/dist/lib/derivers/docx-math-symbols.d.ts +14 -0
- package/dist/lib/derivers/docx-math-symbols.d.ts.map +1 -0
- package/dist/lib/derivers/docx-math-symbols.js +160 -0
- package/dist/lib/derivers/docx-math-symbols.js.map +1 -0
- package/dist/lib/derivers/docx-math.d.ts +15 -0
- package/dist/lib/derivers/docx-math.d.ts.map +1 -0
- package/dist/lib/derivers/docx-math.js +252 -0
- package/dist/lib/derivers/docx-math.js.map +1 -0
- package/dist/lib/derivers/docx.d.ts.map +1 -1
- package/dist/lib/derivers/docx.js +3 -2
- package/dist/lib/derivers/docx.js.map +1 -1
- package/dist/lib/derivers/pdf-furniture.d.ts.map +1 -1
- package/dist/lib/derivers/pdf-furniture.js +3 -0
- package/dist/lib/derivers/pdf-furniture.js.map +1 -1
- package/dist/lib/derivers/pdf-tables.d.ts +9 -0
- package/dist/lib/derivers/pdf-tables.d.ts.map +1 -0
- package/dist/lib/derivers/pdf-tables.js +319 -0
- package/dist/lib/derivers/pdf-tables.js.map +1 -0
- package/dist/lib/derivers/pdf.d.ts.map +1 -1
- package/dist/lib/derivers/pdf.js +77 -38
- package/dist/lib/derivers/pdf.js.map +1 -1
- package/dist/lib/ocr-slots.d.ts +8 -0
- package/dist/lib/ocr-slots.d.ts.map +1 -0
- package/dist/lib/ocr-slots.js +35 -0
- package/dist/lib/ocr-slots.js.map +1 -0
- package/dist/skill.d.ts.map +1 -1
- package/dist/skill.js +7 -2
- package/dist/skill.js.map +1 -1
- package/package.json +7 -7
- package/src/app.ts +4 -1
- package/src/cli.integration.test.ts +30 -8
- package/src/commands/check.command.ts +20 -5
- package/src/commands/derive.command.ts +3 -2
- package/src/commands/read.command.ts +56 -8
- package/src/commands/render.command.ts +33 -11
- package/src/derivers.integration.test.ts +131 -11
- package/src/lib/derivers/docx-math-symbols.ts +197 -0
- package/src/lib/derivers/docx-math.test.ts +131 -0
- package/src/lib/derivers/docx-math.ts +355 -0
- package/src/lib/derivers/docx.ts +5 -3
- package/src/lib/derivers/image.ts +2 -2
- package/src/lib/derivers/pdf-furniture.test.ts +9 -0
- package/src/lib/derivers/pdf-furniture.ts +5 -0
- package/src/lib/derivers/pdf-tables.test.ts +292 -0
- package/src/lib/derivers/pdf-tables.ts +465 -0
- package/src/lib/derivers/pdf.ts +94 -40
- package/src/lib/ocr-slots.integration.test.ts +64 -0
- package/src/lib/ocr-slots.ts +61 -0
- package/src/lib/sidecar.ts +1 -1
- package/src/render.integration.test.ts +5 -4
- package/src/skill.ts +10 -5
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// The symbol tables docx-math.ts converts Office Math with. Ported from markitdown's
|
|
2
|
+
// packages/markitdown/src/markitdown/converter_utils/docx/math/latex_dict.py (https://github.com/microsoft/markitdown,
|
|
3
|
+
// MIT, Copyright (c) Microsoft Corporation), itself adapted from dwml's dwml/latex_dict.py
|
|
4
|
+
// (https://github.com/xiilei/dwml, Apache-2.0, by xilei; ../../../NOTICE). Kept: every mapping and markitdown's fixes to them
|
|
5
|
+
// (U+20EE is \underleftarrow, the math italic h is U+210E). Changed: a template is a macro name applied as
|
|
6
|
+
// `\macro{…}` rather than a str.format string, so no table entry can carry an unbalanced brace.
|
|
7
|
+
|
|
8
|
+
/** Characters LaTeX reads as syntax, escaped with a backslash when they come from an equation's text. */
|
|
9
|
+
export const LATEX_SPECIALS = new Set(["{", "}", "_", "^", "#", "&", "$", "%", "~"]);
|
|
10
|
+
|
|
11
|
+
/** Accent and over/under characters (`m:chr` of an accent, bar or group character) to the macro that sets them. */
|
|
12
|
+
export const ACCENTS: ReadonlyMap<string, string> = new Map([
|
|
13
|
+
// Top accents
|
|
14
|
+
["\u0300", "\\grave"],
|
|
15
|
+
["\u0301", "\\acute"],
|
|
16
|
+
["\u0302", "\\hat"],
|
|
17
|
+
["\u0303", "\\tilde"],
|
|
18
|
+
["\u0304", "\\bar"],
|
|
19
|
+
["\u0305", "\\overbar"],
|
|
20
|
+
["\u0306", "\\breve"],
|
|
21
|
+
["\u0307", "\\dot"],
|
|
22
|
+
["\u0308", "\\ddot"],
|
|
23
|
+
["\u0309", "\\ovhook"],
|
|
24
|
+
["\u030a", "\\ocirc"],
|
|
25
|
+
["\u030c", "\\check"],
|
|
26
|
+
["\u0310", "\\candra"],
|
|
27
|
+
["\u0312", "\\oturnedcomma"],
|
|
28
|
+
["\u0315", "\\ocommatopright"],
|
|
29
|
+
["\u031a", "\\droang"],
|
|
30
|
+
["\u0338", "\\not"],
|
|
31
|
+
["\u20d0", "\\leftharpoonaccent"],
|
|
32
|
+
["\u20d1", "\\rightharpoonaccent"],
|
|
33
|
+
["\u20d2", "\\vertoverlay"],
|
|
34
|
+
["\u20d6", "\\overleftarrow"],
|
|
35
|
+
["\u20d7", "\\vec"],
|
|
36
|
+
["\u20db", "\\dddot"],
|
|
37
|
+
["\u20dc", "\\ddddot"],
|
|
38
|
+
["\u20e1", "\\overleftrightarrow"],
|
|
39
|
+
["\u20e7", "\\annuity"],
|
|
40
|
+
["\u20e9", "\\widebridgeabove"],
|
|
41
|
+
["\u20f0", "\\asteraccent"],
|
|
42
|
+
// Bottom accents
|
|
43
|
+
["\u0330", "\\wideutilde"],
|
|
44
|
+
["\u0331", "\\underbar"],
|
|
45
|
+
["\u20e8", "\\threeunderdot"],
|
|
46
|
+
["\u20ec", "\\underrightharpoondown"],
|
|
47
|
+
["\u20ed", "\\underleftharpoondown"],
|
|
48
|
+
["\u20ee", "\\underleftarrow"],
|
|
49
|
+
["\u20ef", "\\underrightarrow"],
|
|
50
|
+
// Over and under groups
|
|
51
|
+
["\u23b4", "\\overbracket"],
|
|
52
|
+
["\u23dc", "\\overparen"],
|
|
53
|
+
["\u23de", "\\overbrace"],
|
|
54
|
+
["\u23b5", "\\underbracket"],
|
|
55
|
+
["\u23dd", "\\underparen"],
|
|
56
|
+
["\u23df", "\\underbrace"],
|
|
57
|
+
]);
|
|
58
|
+
|
|
59
|
+
/** An accent with no `m:chr` is a hat; a group character with none is an underbrace. */
|
|
60
|
+
export const DEFAULT_ACCENT = "\\hat";
|
|
61
|
+
export const DEFAULT_GROUP_CHR = "\\underbrace";
|
|
62
|
+
|
|
63
|
+
/** A bar's `m:pos`; with none it is an overline. */
|
|
64
|
+
export const BAR_POSITIONS: ReadonlyMap<string, string> = new Map([
|
|
65
|
+
["top", "\\overline"],
|
|
66
|
+
["bot", "\\underline"],
|
|
67
|
+
]);
|
|
68
|
+
export const DEFAULT_BAR = "\\overline";
|
|
69
|
+
|
|
70
|
+
/** Big operators (`m:chr` of an n-ary); an n-ary with no `m:chr` is an integral, as Word draws it. */
|
|
71
|
+
export const BIG_OPERATORS: ReadonlyMap<string, string> = new Map([
|
|
72
|
+
["\u2140", "\\Bbbsum"],
|
|
73
|
+
["\u220f", "\\prod"],
|
|
74
|
+
["\u2210", "\\coprod"],
|
|
75
|
+
["\u2211", "\\sum"],
|
|
76
|
+
["\u222b", "\\int"],
|
|
77
|
+
["\u22c0", "\\bigwedge"],
|
|
78
|
+
["\u22c1", "\\bigvee"],
|
|
79
|
+
["\u22c2", "\\bigcap"],
|
|
80
|
+
["\u22c3", "\\bigcup"],
|
|
81
|
+
["\u2a00", "\\bigodot"],
|
|
82
|
+
["\u2a01", "\\bigoplus"],
|
|
83
|
+
["\u2a02", "\\bigotimes"],
|
|
84
|
+
]);
|
|
85
|
+
export const DEFAULT_BIG_OPERATOR = "\\int";
|
|
86
|
+
|
|
87
|
+
// Mathematical italic letters back to ASCII. Lowercase has a hole at U+1D455: that letter is U+210E (Planck's h).
|
|
88
|
+
const italic = (first: number, letters: string, skip?: number): [string, string][] =>
|
|
89
|
+
[...letters].flatMap((letter, index): [string, string][] => (first + index === skip ? [] : [[String.fromCodePoint(first + index), letter]]));
|
|
90
|
+
|
|
91
|
+
const GREEK = [
|
|
92
|
+
"alpha",
|
|
93
|
+
"beta",
|
|
94
|
+
"gamma",
|
|
95
|
+
"delta",
|
|
96
|
+
"epsilon",
|
|
97
|
+
"zeta",
|
|
98
|
+
"eta",
|
|
99
|
+
"theta",
|
|
100
|
+
"iota",
|
|
101
|
+
"kappa",
|
|
102
|
+
"lambda",
|
|
103
|
+
"mu",
|
|
104
|
+
"nu",
|
|
105
|
+
"xi",
|
|
106
|
+
"omicron",
|
|
107
|
+
"pi",
|
|
108
|
+
"rho",
|
|
109
|
+
"varsigma",
|
|
110
|
+
"sigma",
|
|
111
|
+
"tau",
|
|
112
|
+
"upsilon",
|
|
113
|
+
"phi",
|
|
114
|
+
"chi",
|
|
115
|
+
"psi",
|
|
116
|
+
"omega",
|
|
117
|
+
"partial",
|
|
118
|
+
"varepsilon",
|
|
119
|
+
"vartheta",
|
|
120
|
+
"varkappa",
|
|
121
|
+
"varphi",
|
|
122
|
+
"varrho",
|
|
123
|
+
"varpi",
|
|
124
|
+
];
|
|
125
|
+
|
|
126
|
+
/** Characters of an equation's text to LaTeX; a macro keeps a trailing space so the next letter cannot extend it. */
|
|
127
|
+
export const SYMBOLS: ReadonlyMap<string, string> = new Map<string, string>([
|
|
128
|
+
// Mathematical italic Greek, U+1D6FC onwards
|
|
129
|
+
...GREEK.map((name, index): [string, string] => [String.fromCodePoint(0x1d6fc + index), `\\${name} `]),
|
|
130
|
+
// Arrows and relations
|
|
131
|
+
["\u2190", "\\leftarrow "],
|
|
132
|
+
["\u2191", "\\uparrow "],
|
|
133
|
+
["\u2192", "\\rightarrow "],
|
|
134
|
+
["\u2193", "\\downarrow "],
|
|
135
|
+
["\u2194", "\\leftrightarrow "],
|
|
136
|
+
["\u2195", "\\updownarrow "],
|
|
137
|
+
["\u2196", "\\nwarrow "],
|
|
138
|
+
["\u2197", "\\nearrow "],
|
|
139
|
+
["\u2198", "\\searrow "],
|
|
140
|
+
["\u2199", "\\swarrow "],
|
|
141
|
+
["\u22ee", "\\vdots "],
|
|
142
|
+
["\u22ef", "\\cdots "],
|
|
143
|
+
["\u22f0", "\\adots "],
|
|
144
|
+
["\u22f1", "\\ddots "],
|
|
145
|
+
["\u2260", "\\ne "],
|
|
146
|
+
["\u2264", "\\leq "],
|
|
147
|
+
["\u2265", "\\geq "],
|
|
148
|
+
["\u2266", "\\leqq "],
|
|
149
|
+
["\u2267", "\\geqq "],
|
|
150
|
+
["\u2268", "\\lneqq "],
|
|
151
|
+
["\u2269", "\\gneqq "],
|
|
152
|
+
["\u226a", "\\ll "],
|
|
153
|
+
["\u226b", "\\gg "],
|
|
154
|
+
["\u2208", "\\in "],
|
|
155
|
+
["\u2209", "\\notin "],
|
|
156
|
+
["\u220b", "\\ni "],
|
|
157
|
+
["\u220c", "\\nni "],
|
|
158
|
+
["\u221e", "\\infty "],
|
|
159
|
+
["\u00b1", "\\pm "],
|
|
160
|
+
["\u2213", "\\mp "],
|
|
161
|
+
// Mathematical italic Latin
|
|
162
|
+
...italic(0x1d434, "ABCDEFGHIJKLMNOPQRSTUVWXYZ"),
|
|
163
|
+
...italic(0x1d44e, "abcdefghijklmnopqrstuvwxyz", 0x1d455),
|
|
164
|
+
["\u210e", "h"],
|
|
165
|
+
// The invisible function-application, times, separator and plus operators carry nothing a reader sees.
|
|
166
|
+
["\u2061", ""],
|
|
167
|
+
["\u2062", ""],
|
|
168
|
+
["\u2063", ""],
|
|
169
|
+
["\u2064", ""],
|
|
170
|
+
]);
|
|
171
|
+
|
|
172
|
+
/** Function names (`m:fName`) with a LaTeX operator of their own; any other name is set with \operatorname. */
|
|
173
|
+
export const FUNCTIONS: ReadonlyMap<string, string> = new Map([
|
|
174
|
+
...["sin", "cos", "tan", "arcsin", "arccos", "arctan", "sinh", "cosh", "tanh", "coth", "sec", "csc", "log", "ln", "exp"].map(
|
|
175
|
+
(name): [string, string] => [name, `\\${name}`],
|
|
176
|
+
),
|
|
177
|
+
...["det", "gcd", "lim", "max", "min", "sup", "inf", "dim", "ker", "hom", "deg", "arg"].map((name): [string, string] => [name, `\\${name}`]),
|
|
178
|
+
["arccot", "\\operatorname{arccot}"],
|
|
179
|
+
["lcm", "\\operatorname{lcm}"],
|
|
180
|
+
]);
|
|
181
|
+
|
|
182
|
+
/** Lower-limit objects (`m:limLow`) whose base is one of these are set as that operator with a subscript. */
|
|
183
|
+
export const LIMIT_OPERATORS: ReadonlyMap<string, string> = new Map([
|
|
184
|
+
["lim", "\\lim"],
|
|
185
|
+
["max", "\\max"],
|
|
186
|
+
["min", "\\min"],
|
|
187
|
+
]);
|
|
188
|
+
|
|
189
|
+
/** A fraction's `m:type` to how it is set; with none it is a stacked \frac. */
|
|
190
|
+
export const FRACTIONS: ReadonlyMap<string, (num: string, den: string) => string> = new Map([
|
|
191
|
+
["bar", (num: string, den: string) => `\\frac{${num}}{${den}}`],
|
|
192
|
+
["skw", (num: string, den: string) => `^{${num}}/_{${den}}`],
|
|
193
|
+
["noBar", (num: string, den: string) => `\\genfrac{}{}{0pt}{}{${num}}{${den}}`],
|
|
194
|
+
["lin", (num: string, den: string) => `{${num}}/{${den}}`],
|
|
195
|
+
]);
|
|
196
|
+
|
|
197
|
+
export const LINE_BREAK = "\\\\";
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { parseXml } from "../check/xml-tree.js";
|
|
2
|
+
import { ACCENTS } from "./docx-math-symbols.js";
|
|
3
|
+
import { escapeLatex, ommlToLatex, withEquationsAsLatex } from "./docx-math.js";
|
|
4
|
+
|
|
5
|
+
// The cases of markitdown's tests/test_docx_math.py, test_docx_omml.py, test_docx_math_symbols.py and
|
|
6
|
+
// test_docx_math_accents.py (MIT, Copyright (c) Microsoft Corporation), against this port, plus the objects those
|
|
7
|
+
// tests leave out.
|
|
8
|
+
|
|
9
|
+
const MATH = "http://schemas.openxmlformats.org/officeDocument/2006/math";
|
|
10
|
+
const WORD = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
|
|
11
|
+
|
|
12
|
+
const latex = (inner: string): string => ommlToLatex(parseXml(`<m:oMath xmlns:m="${MATH}">${inner}</m:oMath>`));
|
|
13
|
+
const run = (text: string): string => `<m:r><m:t>${text}</m:t></m:r>`;
|
|
14
|
+
const accent = (char: string): string => latex(`<m:acc><m:accPr><m:chr m:val="${char}"/></m:accPr><m:e>${run("x")}</m:e></m:acc>`);
|
|
15
|
+
const func = (...nameRuns: string[]): string => latex(`<m:func><m:fName>${nameRuns.map(run).join("")}</m:fName><m:e>${run("x")}</m:e></m:func>`);
|
|
16
|
+
|
|
17
|
+
describe("ommlToLatex: markitdown's cases", () => {
|
|
18
|
+
test("a known function is its LaTeX operator, an unknown one \\operatorname", () => {
|
|
19
|
+
expect(func("log")).toBe("\\log(x)");
|
|
20
|
+
expect(func("customFunc")).toBe("\\operatorname{customFunc}(x)");
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("a function name Word split across runs is joined before it is looked up", () => {
|
|
24
|
+
expect(func("custom", "Func")).toBe("\\operatorname{customFunc}(x)");
|
|
25
|
+
expect(func("si", "n")).toBe("\\sin(x)");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test("a run without text is empty, not a failure, and does not cost its neighbours", () => {
|
|
29
|
+
expect(latex("<m:r><m:rPr/></m:r>")).toBe("");
|
|
30
|
+
expect(latex(run("x"))).toBe("x");
|
|
31
|
+
expect(latex(`<m:sSub><m:e>${run("l")}</m:e><m:sub><m:r><m:rPr/></m:r>${run("1")}</m:sub></m:sSub>`)).toBe("l_{1}");
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("the arrow accents share one naming scheme, U+20EE included", () => {
|
|
35
|
+
expect(accent("⃖")).toBe("\\overleftarrow{x}");
|
|
36
|
+
expect(accent("⃯")).toBe("\\underrightarrow{x}");
|
|
37
|
+
expect(accent("⃮")).toBe("\\underleftarrow{x}");
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("caron and ring above, which once carried an extra brace, convert like any accent", () => {
|
|
41
|
+
expect(accent("̌")).toBe("\\check{x}");
|
|
42
|
+
expect(accent("̊")).toBe("\\ocirc{x}");
|
|
43
|
+
expect(accent("̂")).toBe("\\hat{x}");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("every accent is a bare macro, so none can unbalance the braces it is applied with", () => {
|
|
47
|
+
expect([...ACCENTS.values()].filter((macro) => !/^\\[a-z]+$/i.test(macro))).toEqual([]);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("every math italic Latin letter, h at U+210E included, reads as plain ASCII", () => {
|
|
51
|
+
const upper = [..."ABCDEFGHIJKLMNOPQRSTUVWXYZ"].map((letter, index): [string, string] => [String.fromCodePoint(0x1d434 + index), letter]);
|
|
52
|
+
const lower = [..."abcdefghijklmnopqrstuvwxyz"].map((letter, index): [string, string] => [
|
|
53
|
+
letter === "h" ? "ℎ" : String.fromCodePoint(0x1d44e + index),
|
|
54
|
+
letter,
|
|
55
|
+
]);
|
|
56
|
+
const leaked = [...upper, ...lower].filter(([char, letter]) => latex(run(char)) !== letter);
|
|
57
|
+
expect(leaked).toEqual([]);
|
|
58
|
+
expect(latex(run("ℎ(\u{1d465})=\u{1d454}(\u{1d465})"))).toBe("h(x)=g(x)");
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
describe("ommlToLatex: the other objects", () => {
|
|
63
|
+
test("fractions, by type", () => {
|
|
64
|
+
const fraction = (type: string): string =>
|
|
65
|
+
latex(`<m:f><m:fPr>${type === "" ? "" : `<m:type m:val="${type}"/>`}</m:fPr><m:num>${run("a")}</m:num><m:den>${run("b")}</m:den></m:f>`);
|
|
66
|
+
expect(fraction("")).toBe("\\frac{a}{b}");
|
|
67
|
+
expect(fraction("lin")).toBe("{a}/{b}");
|
|
68
|
+
expect(fraction("skw")).toBe("^{a}/_{b}");
|
|
69
|
+
expect(fraction("noBar")).toBe("\\genfrac{}{}{0pt}{}{a}{b}");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("scripts, radicals and big operators", () => {
|
|
73
|
+
expect(latex(`<m:sSup><m:e>${run("10")}</m:e><m:sup>${run("-6")}</m:sup></m:sSup>`)).toBe("10^{-6}");
|
|
74
|
+
expect(latex(`<m:sSubSup><m:e>${run("x")}</m:e><m:sub>${run("i")}</m:sub><m:sup>${run("2")}</m:sup></m:sSubSup>`)).toBe("x_{i}^{2}");
|
|
75
|
+
expect(latex(`<m:rad><m:radPr><m:degHide m:val="1"/></m:radPr><m:deg/><m:e>${run("x")}</m:e></m:rad>`)).toBe("\\sqrt{x}");
|
|
76
|
+
expect(latex(`<m:rad><m:deg>${run("3")}</m:deg><m:e>${run("x")}</m:e></m:rad>`)).toBe("\\sqrt[3]{x}");
|
|
77
|
+
const sum = `<m:nary><m:naryPr><m:chr m:val="∑"/></m:naryPr><m:sub>${run("i=1")}</m:sub><m:sup>${run("n")}</m:sup><m:e>${run("x")}</m:e></m:nary>`;
|
|
78
|
+
expect(latex(sum)).toBe("\\sum_{i=1}^{n}x");
|
|
79
|
+
// Word leaves out m:chr for its default operator, the integral; a letter after it must not extend its name.
|
|
80
|
+
expect(latex(`<m:nary><m:naryPr/><m:e>${run("f")}</m:e></m:nary>`)).toBe("\\int f");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("delimiters keep every argument, joined by their separator", () => {
|
|
84
|
+
expect(latex(`<m:d><m:dPr/><m:e>${run("x")}</m:e></m:d>`)).toBe("\\left(x\\right)");
|
|
85
|
+
expect(latex(`<m:d><m:dPr><m:begChr m:val="["/><m:endChr m:val=""/></m:dPr><m:e>${run("0,1")}</m:e></m:d>`)).toBe("\\left[0,1\\right.");
|
|
86
|
+
expect(latex(`<m:d><m:dPr><m:sepChr m:val=","/></m:dPr><m:e>${run("a")}</m:e><m:e>${run("b")}</m:e></m:d>`)).toBe("\\left(a,b\\right)");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("limits, matrices and equation arrays", () => {
|
|
90
|
+
const limit = `<m:limLow><m:e>${run("lim")}</m:e><m:lim>${run("n→∞")}</m:lim></m:limLow>`;
|
|
91
|
+
expect(latex(limit)).toBe("\\lim_{n\\to \\infty }");
|
|
92
|
+
expect(latex(`<m:limLow><m:e>${run("x")}</m:e><m:lim>${run("k")}</m:lim></m:limLow>`)).toBe("\\underset{k}{x}");
|
|
93
|
+
const matrix = `<m:m><m:mr><m:e>${run("a")}</m:e><m:e>${run("b")}</m:e></m:mr><m:mr><m:e>${run("c")}</m:e><m:e>${run("d")}</m:e></m:mr></m:m>`;
|
|
94
|
+
expect(latex(matrix)).toBe("\\begin{matrix}a&b\\\\c&d\\end{matrix}");
|
|
95
|
+
expect(latex(`<m:eqArr><m:e>${run("x=1")}</m:e><m:e>${run("y=2")}</m:e></m:eqArr>`)).toBe("\\begin{array}{c}x=1\\\\y=2\\end{array}");
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test("LaTeX's own syntax characters in an equation's text are escaped once", () => {
|
|
99
|
+
expect(latex(run("50% of $x"))).toBe("50\\% of \\$x");
|
|
100
|
+
expect(escapeLatex("a_b \\_c")).toBe("a\\_b \\_c");
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const part = (body: string, mathPrefix = "m"): string =>
|
|
105
|
+
`<?xml version="1.0"?><w:document xmlns:w="${WORD}" xmlns:${mathPrefix}="${MATH}"><w:body>${body}</w:body></w:document>`;
|
|
106
|
+
|
|
107
|
+
describe("withEquationsAsLatex", () => {
|
|
108
|
+
test("an inline equation becomes a run of $…$ where it stood", () => {
|
|
109
|
+
const xml = part(`<w:p><w:r><w:t xml:space="preserve">For </w:t></w:r><m:oMath>${run("m")}${run("=1")}</m:oMath><w:r><w:t>,</w:t></w:r></w:p>`);
|
|
110
|
+
const { xml: rewritten, equations } = withEquationsAsLatex(xml);
|
|
111
|
+
expect(equations).toBe(1);
|
|
112
|
+
expect(rewritten).toContain('<w:r><w:t xml:space="preserve">For </w:t></w:r><w:r><w:t xml:space="preserve">$m=1$</w:t></w:r><w:r><w:t>,</w:t></w:r>');
|
|
113
|
+
expect(rewritten).not.toContain("oMath");
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("each equation of a display paragraph becomes $$…$$ inside that paragraph, a line break between them", () => {
|
|
117
|
+
const xml = part(`<w:p><m:oMathPara><m:oMathParaPr/><m:oMath>${run("a")}</m:oMath><m:oMath>${run("b<c")}</m:oMath></m:oMathPara></w:p>`);
|
|
118
|
+
const { xml: rewritten, equations } = withEquationsAsLatex(xml);
|
|
119
|
+
expect(equations).toBe(2);
|
|
120
|
+
expect(rewritten).toContain(
|
|
121
|
+
'<w:p><w:r><w:t xml:space="preserve">$$a$$</w:t></w:r><w:r><w:br/></w:r><w:r><w:t xml:space="preserve">$$b<c$$</w:t></w:r></w:p>',
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("the document's own prefixes are honoured, and a part with no Office Math comes back as it was", () => {
|
|
126
|
+
const renamed = part(`<w:p><mm:oMath><mm:r><mm:t>x</mm:t></mm:r></mm:oMath></w:p>`, "mm");
|
|
127
|
+
expect(withEquationsAsLatex(renamed).xml).toContain('<w:t xml:space="preserve">$x$</w:t>');
|
|
128
|
+
const plain = `<w:document xmlns:w="${WORD}"><w:body><w:p><w:r><w:t>m=1</w:t></w:r></w:p></w:body></w:document>`;
|
|
129
|
+
expect(withEquationsAsLatex(plain)).toEqual({ xml: plain, equations: 0 });
|
|
130
|
+
});
|
|
131
|
+
});
|