@zyro-sec/latex 1.0.2 → 1.0.3

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/src/plugin.ts CHANGED
@@ -1,14 +1,14 @@
1
- import { Plugin } from "@zyro-sec/plugin/tui"
2
- import { createLatexCodeBlockRenderer } from "./markdown"
3
-
4
- export default Plugin.define({
5
- id: "opencode.latex",
6
- setup(context) {
7
- const render = createLatexCodeBlockRenderer(context.renderer, () => ({
8
- text: context.theme.text.base,
9
- subdued: context.theme.text.muted,
10
- }))
11
- context.markdown.registerCodeBlockRenderer("latex", render)
12
- context.markdown.registerCodeBlockRenderer("math", render)
13
- },
14
- })
1
+ import { Plugin } from "@zyro-sec/plugin/tui"
2
+ import { createLatexCodeBlockRenderer } from "./markdown"
3
+
4
+ export default Plugin.define({
5
+ id: "opencode.latex",
6
+ setup(context) {
7
+ const render = createLatexCodeBlockRenderer(context.renderer, () => ({
8
+ text: context.theme.text.base,
9
+ subdued: context.theme.text.muted,
10
+ }))
11
+ context.markdown.registerCodeBlockRenderer("latex", render)
12
+ context.markdown.registerCodeBlockRenderer("math", render)
13
+ },
14
+ })
package/src/render.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { layoutMath } from "./layout"
2
- import { parseLatex } from "./parser"
3
- import type { MathLayout, RenderLatexOptions } from "./types"
4
-
5
- export function renderLatex(source: string, options: RenderLatexOptions = {}): MathLayout {
6
- return layoutMath(parseLatex(source, options), options)
7
- }
8
-
9
- export function renderLatexToString(source: string, options: RenderLatexOptions = {}): string {
10
- return renderLatex(source, options).toString()
11
- }
1
+ import { layoutMath } from "./layout"
2
+ import { parseLatex } from "./parser"
3
+ import type { MathLayout, RenderLatexOptions } from "./types"
4
+
5
+ export function renderLatex(source: string, options: RenderLatexOptions = {}): MathLayout {
6
+ return layoutMath(parseLatex(source, options), options)
7
+ }
8
+
9
+ export function renderLatexToString(source: string, options: RenderLatexOptions = {}): string {
10
+ return renderLatex(source, options).toString()
11
+ }
package/src/symbols.ts CHANGED
@@ -1,315 +1,315 @@
1
- import type { SymbolRole } from "./types"
2
-
3
- export interface SymbolDefinition {
4
- value: string
5
- role?: SymbolRole
6
- }
7
-
8
- const ordinary: Record<string, string> = {
9
- alpha: "α",
10
- beta: "β",
11
- gamma: "γ",
12
- delta: "δ",
13
- epsilon: "ε",
14
- varepsilon: "ϵ",
15
- zeta: "ζ",
16
- eta: "η",
17
- theta: "θ",
18
- vartheta: "ϑ",
19
- iota: "ι",
20
- kappa: "κ",
21
- lambda: "λ",
22
- mu: "μ",
23
- nu: "ν",
24
- xi: "ξ",
25
- omicron: "ο",
26
- pi: "π",
27
- varpi: "ϖ",
28
- rho: "ρ",
29
- varrho: "ϱ",
30
- sigma: "σ",
31
- varsigma: "ς",
32
- tau: "τ",
33
- upsilon: "υ",
34
- phi: "ϕ",
35
- varphi: "φ",
36
- chi: "χ",
37
- psi: "ψ",
38
- omega: "ω",
39
- Gamma: "Γ",
40
- Delta: "Δ",
41
- Theta: "Θ",
42
- Lambda: "Λ",
43
- Xi: "Ξ",
44
- Pi: "Π",
45
- Sigma: "Σ",
46
- Upsilon: "Υ",
47
- Phi: "Φ",
48
- Psi: "Ψ",
49
- Omega: "Ω",
50
- infty: "∞",
51
- ell: "ℓ",
52
- hbar: "ℏ",
53
- imath: "ı",
54
- jmath: "ȷ",
55
- Re: "ℜ",
56
- Im: "ℑ",
57
- aleph: "ℵ",
58
- beth: "ℶ",
59
- gimel: "ℷ",
60
- daleth: "ℸ",
61
- partial: "∂",
62
- nabla: "∇",
63
- angle: "∠",
64
- measuredangle: "∡",
65
- triangle: "△",
66
- square: "□",
67
- lozenge: "◊",
68
- top: "⊤",
69
- bot: "⊥",
70
- emptyset: "∅",
71
- varnothing: "∅",
72
- forall: "∀",
73
- exists: "∃",
74
- nexists: "∄",
75
- neg: "¬",
76
- lnot: "¬",
77
- prime: "′",
78
- backprime: "‵",
79
- clubsuit: "♣",
80
- diamondsuit: "♢",
81
- heartsuit: "♡",
82
- spadesuit: "♠",
83
- checkmark: "✓",
84
- }
85
-
86
- const binary: Record<string, string> = {
87
- pm: "±",
88
- mp: "∓",
89
- times: "×",
90
- div: "÷",
91
- cdot: "·",
92
- ast: "∗",
93
- star: "⋆",
94
- circ: "∘",
95
- bullet: "∙",
96
- oplus: "⊕",
97
- ominus: "⊖",
98
- otimes: "⊗",
99
- oslash: "⊘",
100
- odot: "⊙",
101
- cap: "∩",
102
- cup: "∪",
103
- uplus: "⊎",
104
- sqcap: "⊓",
105
- sqcup: "⊔",
106
- vee: "∨",
107
- lor: "∨",
108
- wedge: "∧",
109
- land: "∧",
110
- setminus: "∖",
111
- wr: "≀",
112
- diamond: "⋄",
113
- bigtriangleup: "△",
114
- bigtriangledown: "▽",
115
- triangleleft: "◁",
116
- triangleright: "▷",
117
- }
118
-
119
- const relation: Record<string, string> = {
120
- equals: "=",
121
- neq: "≠",
122
- ne: "≠",
123
- equiv: "≡",
124
- approx: "≈",
125
- sim: "∼",
126
- simeq: "≃",
127
- cong: "≅",
128
- asymp: "≍",
129
- propto: "∝",
130
- lt: "<",
131
- gt: ">",
132
- le: "≤",
133
- leq: "≤",
134
- ge: "≥",
135
- geq: "≥",
136
- ll: "≪",
137
- gg: "≫",
138
- prec: "≺",
139
- succ: "≻",
140
- preceq: "⪯",
141
- succeq: "⪰",
142
- subset: "⊂",
143
- supset: "⊃",
144
- subseteq: "⊆",
145
- supseteq: "⊇",
146
- sqsubset: "⊏",
147
- sqsupset: "⊐",
148
- sqsubseteq: "⊑",
149
- sqsupseteq: "⊒",
150
- in: "∈",
151
- ni: "∋",
152
- notin: "∉",
153
- owns: "∋",
154
- vdash: "⊢",
155
- dashv: "⊣",
156
- models: "⊨",
157
- mid: "∣",
158
- parallel: "∥",
159
- perp: "⊥",
160
- smile: "⌣",
161
- frown: "⌢",
162
- }
163
-
164
- const arrows: Record<string, string> = {
165
- leftarrow: "←",
166
- gets: "←",
167
- rightarrow: "→",
168
- to: "→",
169
- leftrightarrow: "↔",
170
- Leftarrow: "⇐",
171
- Rightarrow: "⇒",
172
- Leftrightarrow: "⇔",
173
- mapsto: "↦",
174
- hookleftarrow: "↩",
175
- hookrightarrow: "↪",
176
- leftharpoonup: "↼",
177
- leftharpoondown: "↽",
178
- rightharpoonup: "⇀",
179
- rightharpoondown: "⇁",
180
- rightleftharpoons: "⇌",
181
- longleftarrow: "⟵",
182
- longrightarrow: "⟶",
183
- longleftrightarrow: "⟷",
184
- Longleftarrow: "⟸",
185
- Longrightarrow: "⟹",
186
- Longleftrightarrow: "⟺",
187
- longmapsto: "⟼",
188
- uparrow: "↑",
189
- downarrow: "↓",
190
- updownarrow: "↕",
191
- Uparrow: "⇑",
192
- Downarrow: "⇓",
193
- Updownarrow: "⇕",
194
- nearrow: "↗",
195
- searrow: "↘",
196
- swarrow: "↙",
197
- nwarrow: "↖",
198
- }
199
-
200
- const punctuation: Record<string, string> = {
201
- cdots: "⋯",
202
- ldots: "…",
203
- dots: "…",
204
- vdots: "⋮",
205
- ddots: "⋱",
206
- colon: ":",
207
- }
208
-
209
- export const symbolTable: Readonly<Record<string, SymbolDefinition>> = {
210
- ...Object.fromEntries(Object.entries(ordinary).map(([name, value]) => [name, { value, role: "ordinary" as const }])),
211
- ...Object.fromEntries(Object.entries(binary).map(([name, value]) => [name, { value, role: "binary" as const }])),
212
- ...Object.fromEntries(Object.entries(relation).map(([name, value]) => [name, { value, role: "relation" as const }])),
213
- ...Object.fromEntries(Object.entries(arrows).map(([name, value]) => [name, { value, role: "relation" as const }])),
214
- ...Object.fromEntries(
215
- Object.entries(punctuation).map(([name, value]) => [name, { value, role: "punctuation" as const }]),
216
- ),
217
- }
218
-
219
- export const largeOperators: Readonly<Record<string, string>> = {
220
- sum: "∑",
221
- prod: "∏",
222
- coprod: "∐",
223
- int: "∫",
224
- iint: "∬",
225
- iiint: "∭",
226
- oint: "∮",
227
- bigcap: "⋂",
228
- bigcup: "⋃",
229
- bigvee: "⋁",
230
- bigwedge: "⋀",
231
- bigoplus: "⨁",
232
- bigotimes: "⨂",
233
- bigodot: "⨀",
234
- }
235
-
236
- export const namedOperators = new Set([
237
- "arccos",
238
- "arcsin",
239
- "arctan",
240
- "arg",
241
- "cos",
242
- "cosh",
243
- "cot",
244
- "coth",
245
- "csc",
246
- "deg",
247
- "det",
248
- "dim",
249
- "exp",
250
- "gcd",
251
- "hom",
252
- "inf",
253
- "ker",
254
- "lg",
255
- "lim",
256
- "liminf",
257
- "limsup",
258
- "ln",
259
- "log",
260
- "max",
261
- "min",
262
- "mod",
263
- "Pr",
264
- "sec",
265
- "sin",
266
- "sinh",
267
- "sup",
268
- "tan",
269
- "tanh",
270
- ])
271
-
272
- export const delimiterTable: Readonly<Record<string, string>> = {
273
- "(": "(",
274
- ")": ")",
275
- "[": "[",
276
- "]": "]",
277
- "\\{": "{",
278
- "\\}": "}",
279
- "{": "{",
280
- "}": "}",
281
- "|": "│",
282
- "\\|": "║",
283
- vert: "│",
284
- Vert: "║",
285
- lvert: "│",
286
- rvert: "│",
287
- lVert: "║",
288
- rVert: "║",
289
- lbrace: "{",
290
- rbrace: "}",
291
- langle: "⟨",
292
- rangle: "⟩",
293
- lfloor: "⌊",
294
- rfloor: "⌋",
295
- lceil: "⌈",
296
- rceil: "⌉",
297
- ".": "",
298
- }
299
-
300
- export const spacingCommands: Readonly<Record<string, number>> = {
301
- // "\ " is the LaTeX control space: a backslash followed by a literal space.
302
- " ": 1,
303
- // A backslash before a tab, a carriage return, or a newline is the same control space.
304
- "\t": 1,
305
- "\r": 1,
306
- "\n": 1,
307
- ",": 0,
308
- ":": 1,
309
- ";": 1,
310
- "!": 0,
311
- quad: 2,
312
- qquad: 4,
313
- enspace: 1,
314
- thinspace: 0,
315
- }
1
+ import type { SymbolRole } from "./types"
2
+
3
+ export interface SymbolDefinition {
4
+ value: string
5
+ role?: SymbolRole
6
+ }
7
+
8
+ const ordinary: Record<string, string> = {
9
+ alpha: "α",
10
+ beta: "β",
11
+ gamma: "γ",
12
+ delta: "δ",
13
+ epsilon: "ε",
14
+ varepsilon: "ϵ",
15
+ zeta: "ζ",
16
+ eta: "η",
17
+ theta: "θ",
18
+ vartheta: "ϑ",
19
+ iota: "ι",
20
+ kappa: "κ",
21
+ lambda: "λ",
22
+ mu: "μ",
23
+ nu: "ν",
24
+ xi: "ξ",
25
+ omicron: "ο",
26
+ pi: "π",
27
+ varpi: "ϖ",
28
+ rho: "ρ",
29
+ varrho: "ϱ",
30
+ sigma: "σ",
31
+ varsigma: "ς",
32
+ tau: "τ",
33
+ upsilon: "υ",
34
+ phi: "ϕ",
35
+ varphi: "φ",
36
+ chi: "χ",
37
+ psi: "ψ",
38
+ omega: "ω",
39
+ Gamma: "Γ",
40
+ Delta: "Δ",
41
+ Theta: "Θ",
42
+ Lambda: "Λ",
43
+ Xi: "Ξ",
44
+ Pi: "Π",
45
+ Sigma: "Σ",
46
+ Upsilon: "Υ",
47
+ Phi: "Φ",
48
+ Psi: "Ψ",
49
+ Omega: "Ω",
50
+ infty: "∞",
51
+ ell: "ℓ",
52
+ hbar: "ℏ",
53
+ imath: "ı",
54
+ jmath: "ȷ",
55
+ Re: "ℜ",
56
+ Im: "ℑ",
57
+ aleph: "ℵ",
58
+ beth: "ℶ",
59
+ gimel: "ℷ",
60
+ daleth: "ℸ",
61
+ partial: "∂",
62
+ nabla: "∇",
63
+ angle: "∠",
64
+ measuredangle: "∡",
65
+ triangle: "△",
66
+ square: "□",
67
+ lozenge: "◊",
68
+ top: "⊤",
69
+ bot: "⊥",
70
+ emptyset: "∅",
71
+ varnothing: "∅",
72
+ forall: "∀",
73
+ exists: "∃",
74
+ nexists: "∄",
75
+ neg: "¬",
76
+ lnot: "¬",
77
+ prime: "′",
78
+ backprime: "‵",
79
+ clubsuit: "♣",
80
+ diamondsuit: "♢",
81
+ heartsuit: "♡",
82
+ spadesuit: "♠",
83
+ checkmark: "✓",
84
+ }
85
+
86
+ const binary: Record<string, string> = {
87
+ pm: "±",
88
+ mp: "∓",
89
+ times: "×",
90
+ div: "÷",
91
+ cdot: "·",
92
+ ast: "∗",
93
+ star: "⋆",
94
+ circ: "∘",
95
+ bullet: "∙",
96
+ oplus: "⊕",
97
+ ominus: "⊖",
98
+ otimes: "⊗",
99
+ oslash: "⊘",
100
+ odot: "⊙",
101
+ cap: "∩",
102
+ cup: "∪",
103
+ uplus: "⊎",
104
+ sqcap: "⊓",
105
+ sqcup: "⊔",
106
+ vee: "∨",
107
+ lor: "∨",
108
+ wedge: "∧",
109
+ land: "∧",
110
+ setminus: "∖",
111
+ wr: "≀",
112
+ diamond: "⋄",
113
+ bigtriangleup: "△",
114
+ bigtriangledown: "▽",
115
+ triangleleft: "◁",
116
+ triangleright: "▷",
117
+ }
118
+
119
+ const relation: Record<string, string> = {
120
+ equals: "=",
121
+ neq: "≠",
122
+ ne: "≠",
123
+ equiv: "≡",
124
+ approx: "≈",
125
+ sim: "∼",
126
+ simeq: "≃",
127
+ cong: "≅",
128
+ asymp: "≍",
129
+ propto: "∝",
130
+ lt: "<",
131
+ gt: ">",
132
+ le: "≤",
133
+ leq: "≤",
134
+ ge: "≥",
135
+ geq: "≥",
136
+ ll: "≪",
137
+ gg: "≫",
138
+ prec: "≺",
139
+ succ: "≻",
140
+ preceq: "⪯",
141
+ succeq: "⪰",
142
+ subset: "⊂",
143
+ supset: "⊃",
144
+ subseteq: "⊆",
145
+ supseteq: "⊇",
146
+ sqsubset: "⊏",
147
+ sqsupset: "⊐",
148
+ sqsubseteq: "⊑",
149
+ sqsupseteq: "⊒",
150
+ in: "∈",
151
+ ni: "∋",
152
+ notin: "∉",
153
+ owns: "∋",
154
+ vdash: "⊢",
155
+ dashv: "⊣",
156
+ models: "⊨",
157
+ mid: "∣",
158
+ parallel: "∥",
159
+ perp: "⊥",
160
+ smile: "⌣",
161
+ frown: "⌢",
162
+ }
163
+
164
+ const arrows: Record<string, string> = {
165
+ leftarrow: "←",
166
+ gets: "←",
167
+ rightarrow: "→",
168
+ to: "→",
169
+ leftrightarrow: "↔",
170
+ Leftarrow: "⇐",
171
+ Rightarrow: "⇒",
172
+ Leftrightarrow: "⇔",
173
+ mapsto: "↦",
174
+ hookleftarrow: "↩",
175
+ hookrightarrow: "↪",
176
+ leftharpoonup: "↼",
177
+ leftharpoondown: "↽",
178
+ rightharpoonup: "⇀",
179
+ rightharpoondown: "⇁",
180
+ rightleftharpoons: "⇌",
181
+ longleftarrow: "⟵",
182
+ longrightarrow: "⟶",
183
+ longleftrightarrow: "⟷",
184
+ Longleftarrow: "⟸",
185
+ Longrightarrow: "⟹",
186
+ Longleftrightarrow: "⟺",
187
+ longmapsto: "⟼",
188
+ uparrow: "↑",
189
+ downarrow: "↓",
190
+ updownarrow: "↕",
191
+ Uparrow: "⇑",
192
+ Downarrow: "⇓",
193
+ Updownarrow: "⇕",
194
+ nearrow: "↗",
195
+ searrow: "↘",
196
+ swarrow: "↙",
197
+ nwarrow: "↖",
198
+ }
199
+
200
+ const punctuation: Record<string, string> = {
201
+ cdots: "⋯",
202
+ ldots: "…",
203
+ dots: "…",
204
+ vdots: "⋮",
205
+ ddots: "⋱",
206
+ colon: ":",
207
+ }
208
+
209
+ export const symbolTable: Readonly<Record<string, SymbolDefinition>> = {
210
+ ...Object.fromEntries(Object.entries(ordinary).map(([name, value]) => [name, { value, role: "ordinary" as const }])),
211
+ ...Object.fromEntries(Object.entries(binary).map(([name, value]) => [name, { value, role: "binary" as const }])),
212
+ ...Object.fromEntries(Object.entries(relation).map(([name, value]) => [name, { value, role: "relation" as const }])),
213
+ ...Object.fromEntries(Object.entries(arrows).map(([name, value]) => [name, { value, role: "relation" as const }])),
214
+ ...Object.fromEntries(
215
+ Object.entries(punctuation).map(([name, value]) => [name, { value, role: "punctuation" as const }]),
216
+ ),
217
+ }
218
+
219
+ export const largeOperators: Readonly<Record<string, string>> = {
220
+ sum: "∑",
221
+ prod: "∏",
222
+ coprod: "∐",
223
+ int: "∫",
224
+ iint: "∬",
225
+ iiint: "∭",
226
+ oint: "∮",
227
+ bigcap: "⋂",
228
+ bigcup: "⋃",
229
+ bigvee: "⋁",
230
+ bigwedge: "⋀",
231
+ bigoplus: "⨁",
232
+ bigotimes: "⨂",
233
+ bigodot: "⨀",
234
+ }
235
+
236
+ export const namedOperators = new Set([
237
+ "arccos",
238
+ "arcsin",
239
+ "arctan",
240
+ "arg",
241
+ "cos",
242
+ "cosh",
243
+ "cot",
244
+ "coth",
245
+ "csc",
246
+ "deg",
247
+ "det",
248
+ "dim",
249
+ "exp",
250
+ "gcd",
251
+ "hom",
252
+ "inf",
253
+ "ker",
254
+ "lg",
255
+ "lim",
256
+ "liminf",
257
+ "limsup",
258
+ "ln",
259
+ "log",
260
+ "max",
261
+ "min",
262
+ "mod",
263
+ "Pr",
264
+ "sec",
265
+ "sin",
266
+ "sinh",
267
+ "sup",
268
+ "tan",
269
+ "tanh",
270
+ ])
271
+
272
+ export const delimiterTable: Readonly<Record<string, string>> = {
273
+ "(": "(",
274
+ ")": ")",
275
+ "[": "[",
276
+ "]": "]",
277
+ "\\{": "{",
278
+ "\\}": "}",
279
+ "{": "{",
280
+ "}": "}",
281
+ "|": "│",
282
+ "\\|": "║",
283
+ vert: "│",
284
+ Vert: "║",
285
+ lvert: "│",
286
+ rvert: "│",
287
+ lVert: "║",
288
+ rVert: "║",
289
+ lbrace: "{",
290
+ rbrace: "}",
291
+ langle: "⟨",
292
+ rangle: "⟩",
293
+ lfloor: "⌊",
294
+ rfloor: "⌋",
295
+ lceil: "⌈",
296
+ rceil: "⌉",
297
+ ".": "",
298
+ }
299
+
300
+ export const spacingCommands: Readonly<Record<string, number>> = {
301
+ // "\ " is the LaTeX control space: a backslash followed by a literal space.
302
+ " ": 1,
303
+ // A backslash before a tab, a carriage return, or a newline is the same control space.
304
+ "\t": 1,
305
+ "\r": 1,
306
+ "\n": 1,
307
+ ",": 0,
308
+ ":": 1,
309
+ ";": 1,
310
+ "!": 0,
311
+ quad: 2,
312
+ qquad: 4,
313
+ enspace: 1,
314
+ thinspace: 0,
315
+ }