@zyro-sec/latex 0.0.0-stage → 1.0.2
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/package.json +26 -4
- package/src/layout.test.ts +87 -0
- package/src/layout.ts +673 -0
- package/src/limits.ts +40 -0
- package/src/markdown.test.ts +267 -0
- package/src/markdown.ts +116 -0
- package/src/parser-render.test.ts +23 -0
- package/src/parser.test.ts +298 -0
- package/src/parser.ts +598 -0
- package/src/plugin.ts +14 -0
- package/src/render.test.ts +87 -0
- package/src/render.ts +11 -0
- package/src/root.test.ts +69 -0
- package/src/symbols.ts +315 -0
- package/src/types.ts +97 -0
- package/tsconfig.json +10 -0
- package/README.md +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
2
3
|
"name": "@zyro-sec/latex",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
4
|
+
"version": "1.0.2",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
"./markdown": "./src/markdown.ts",
|
|
8
|
+
"./plugin": "./src/plugin.ts"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "bun test --timeout 30000 --only-failures",
|
|
12
|
+
"typecheck": "bun check --no-script",
|
|
13
|
+
"typecheck:tsc": "tsc --noEmit"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@zyro-sec/plugin": "^1.0.2",
|
|
17
|
+
"@opentui/core": "0.9.9",
|
|
18
|
+
"string-width": "7.2.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@tsconfig/bun": "1.0.9",
|
|
22
|
+
"@types/bun": "1.4.3",
|
|
23
|
+
"@typescript/native": "npm:typescript@7.1.0-beta"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { layoutMath } from "./layout"
|
|
3
|
+
import { renderLatexToString } from "./render"
|
|
4
|
+
|
|
5
|
+
const text = (value: string) => ({ type: "text" as const, value })
|
|
6
|
+
|
|
7
|
+
describe("structured math layout", () => {
|
|
8
|
+
test.each([
|
|
9
|
+
String.raw`\sqrt{x}`,
|
|
10
|
+
String.raw`\begin{pmatrix}a&b\\c&d\end{pmatrix}`,
|
|
11
|
+
String.raw`\underbrace{abcd}`,
|
|
12
|
+
String.raw`\overbrace{abcd}`,
|
|
13
|
+
String.raw`\sum`,
|
|
14
|
+
])("empty scripts do not change geometry: %s", (source) => {
|
|
15
|
+
for (const scripts of ["^{}", "_{}", "^{}_{}"]) {
|
|
16
|
+
expect(renderLatexToString(source + scripts)).toBe(renderLatexToString(source))
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
test("centers annotations over even-width brace junctions", () => {
|
|
21
|
+
expect(renderLatexToString(String.raw`\overbrace{abcd}^{n}`)).toBe([" n", "╭┴─╮", "abcd"].join("\n"))
|
|
22
|
+
expect(renderLatexToString(String.raw`\underbrace{abcd}_{n}`)).toBe(["abcd", "╰┬─╯", " n"].join("\n"))
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test("raises powers above tall matrix delimiters", () => {
|
|
26
|
+
expect(renderLatexToString(String.raw`\begin{pmatrix}a&b\\c&d\end{pmatrix}^2`)).toBe(
|
|
27
|
+
[" 2", "⎛a b⎞", "⎜ ⎟", "⎝c d⎠"].join("\n"),
|
|
28
|
+
)
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test("keeps piecewise values left-aligned", () => {
|
|
32
|
+
expect(renderLatexToString(String.raw`\begin{cases}x & x>0\\x^2+1 & x\le0\end{cases}`)).toBe(
|
|
33
|
+
["⎧x x > 0", "⎨", "⎩x² + 1 x ≤ 0"].join("\n"),
|
|
34
|
+
)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test("honors array column alignment and continuous separators", () => {
|
|
38
|
+
expect(
|
|
39
|
+
layoutMath({
|
|
40
|
+
type: "matrix",
|
|
41
|
+
environment: "array",
|
|
42
|
+
columns: "l|r",
|
|
43
|
+
rows: [
|
|
44
|
+
[text("a"), text("wide")],
|
|
45
|
+
[text("long"), text("b")],
|
|
46
|
+
],
|
|
47
|
+
}).toString(),
|
|
48
|
+
).toBe(["a │ wide", " │", "long │ b"].join("\n"))
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
test("preserves edge rules and double array separators", () => {
|
|
52
|
+
expect(
|
|
53
|
+
layoutMath({
|
|
54
|
+
type: "matrix",
|
|
55
|
+
environment: "array",
|
|
56
|
+
columns: "|l||r|",
|
|
57
|
+
rows: [
|
|
58
|
+
[text("a"), text("b")],
|
|
59
|
+
[text("long"), text("c")],
|
|
60
|
+
],
|
|
61
|
+
}).toString(),
|
|
62
|
+
).toBe(["│ a ││ b │", "│ ││ │", "│ long ││ c │"].join("\n"))
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test.each(["left", "right"] as const)("aligns continued-fraction numerators to the %s", (numeratorAlign) => {
|
|
66
|
+
const layout = layoutMath({
|
|
67
|
+
type: "fraction",
|
|
68
|
+
numerator: text("1"),
|
|
69
|
+
denominator: text("12345"),
|
|
70
|
+
bar: true,
|
|
71
|
+
numeratorAlign,
|
|
72
|
+
})
|
|
73
|
+
expect(layout.toString()).toBe([numeratorAlign === "left" ? " 1" : " 1", "───────", " 12345"].join("\n"))
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
test.each(["over", "under"] as const)("stretches %s braces and places annotations outside them", (position) => {
|
|
77
|
+
const layout = layoutMath({
|
|
78
|
+
type: "scripts",
|
|
79
|
+
base: { type: "brace", body: text("a + b + c"), position },
|
|
80
|
+
...(position === "over" ? { superscript: text("n") } : { subscript: text("n") }),
|
|
81
|
+
})
|
|
82
|
+
expect(layout.toString()).toBe(
|
|
83
|
+
(position === "over" ? [" n", "╭───┴───╮", "a + b + c"] : ["a + b + c", "╰───┬───╯", " n"]).join("\n"),
|
|
84
|
+
)
|
|
85
|
+
expect(layout.baseline).toBe(position === "over" ? 2 : 0)
|
|
86
|
+
})
|
|
87
|
+
})
|