tex2typst 0.4.0 → 0.5.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.
@@ -1,451 +0,0 @@
1
- # Some test cases are from https://github.com/curvenote/tex-to-typst/blob/1d0b121d162911f1c99b47171939e30656f49270/tests/math.yml (MIT License)
2
- title: struct-tex2typst
3
- cases:
4
- - title: redundant spaces should be ignored
5
- tex: 'p ( x ) = \frac{e^{-\lambda}\lambda^{x}}{ x ! }'
6
- typst: p(x) = (e^(-lambda) lambda^x)/(x!)
7
- - title: Simplified brackets
8
- tex: 'e_f(x)'
9
- typst: e_f (x)
10
- - title: Comma inside function
11
- tex: '\boldsymbol{j_x, j_y}'
12
- typst: 'bold(j_x comma j_y)'
13
-
14
- - title: Nested functions
15
- tex: '\boldsymbol{m}_\text{ref}'
16
- typst: 'bold(m)_"ref"'
17
- - title: left and right brackets, not overHigh
18
- tex: '\left[\boldsymbol{A} \right) \left\{b \right)'
19
- typst: 'lr([bold(A))) lr({b))'
20
- - title: dot as right bracket
21
- tex: '\left\{ \frac{a}{b} \right.'
22
- typst: 'lr(\{ a/b)'
23
- - title: dot as left bracket
24
- tex: '\left. \frac{a}{b} \right\}'
25
- typst: 'lr(a/b })'
26
- - title: left. and right.
27
- tex: '\left. \frac{a}{b} \right.'
28
- typst: 'lr(a/b)'
29
- - title: lr
30
- tex: \left|a + \frac{1}{3} \right|^2
31
- typst: lr(|a + 1/3|)^2
32
- - title: biglr
33
- tex: \bigl|a + \frac{1}{3} \bigr|^2
34
- typst: "|a + 1/3 |^2"
35
- - title: bigm
36
- tex: \dfrac{d}{dx}x^2\bigm{|}_{x=2}
37
- typst: frac(d, d x) x^2 |_(x = 2)
38
- - title: intop
39
- tex: \intop_0^\infty x \text{d} x
40
- typst: limits(integral)_0^infinity x "d" x
41
- - title: bigglr
42
- tex: \biggl|a + \frac{1}{3} \biggr|^2
43
- typst: "|a + 1/3 |^2"
44
- - title: symmetry left right
45
- tex: \left\{ a \right\} \left( b \right) \left[ c \right]
46
- typst: '{a}(b) [c]'
47
- - title: symmetry bigl bigr
48
- tex: \bigl\{ a \bigr\} \bigl( b \bigr) \bigl[ c \bigr]
49
- typst: '{a}(b) [c]'
50
- - title: symmetry biggl biggr
51
- tex: \biggl\{ a \biggr\} \biggl( b \biggr) \biggl[ c \biggr]
52
- typst: '{a}(b) [c]'
53
- - title: symmetry Biggl Biggr
54
- tex: \Biggl\{ a \Biggr\} \Biggl( b \Biggr) \Biggl[ c \Biggr]
55
- typst: '{a}(b) [c]'
56
- - title: paired delimiter commands
57
- tex: \left(\bigl[\biggl\{a\biggr\}\bigr]\right)
58
- typst: '([ {a}])'
59
- - title: operatorname
60
- tex: '\operatorname{diag} \text{diag}'
61
- typst: 'op("diag") "diag"'
62
- - title: operatorname1
63
- tex: '\operatorname{a}'
64
- typst: op("a")
65
- - title: scripts
66
- tex: '\boldsymbol{k}_{Av} \boldsymbol{k}^{Av}'
67
- typst: 'bold(k)_(A v) bold(k)^(A v)'
68
- - title: scripts
69
- tex: |-
70
- \boldsymbol{D}
71
- \\
72
- \boldsymbol{G}_{z}
73
- typst: |-
74
- bold(D)
75
- \
76
- bold(G)_z
77
- - title: Complex equations with nested over/under braces
78
- tex: |-
79
- \begin{align*}
80
- \overbrace{
81
- \left[
82
- \frac{1}{\Delta t}
83
- \frac{\partial \boldsymbol{\theta}^{n+1}}{\partial\boldsymbol{\psi}^{n+1}}
84
- -\boldsymbol{D}
85
- \text{diag}\left( \boldsymbol{G} \boldsymbol{\psi}^{n+1} \right)
86
- \frac{\partial \boldsymbol{k}_{Av}}{\partial\boldsymbol{\psi}^{n+1}}
87
- -\boldsymbol{D}
88
- \text{diag}\left( \boldsymbol{k}_{Av}(\boldsymbol{\psi}^{n+1},\boldsymbol{m}) \right)
89
- \boldsymbol{G}
90
- - \boldsymbol{G}_{z}
91
- \frac{\partial \boldsymbol{k}_{Av}}{\partial\boldsymbol{\psi}^{n+1}}
92
- \right]
93
- }^{\boldsymbol{A}_0(\boldsymbol{\psi}^{n+1})}
94
- \frac{\partial \boldsymbol{\psi}^{n+1}}{\partial\boldsymbol{m}}
95
- \nonumber\\
96
- +
97
- \underbrace{
98
- \left[
99
- -\frac{1}{\Delta t}
100
- \frac{\partial \boldsymbol{\theta}^n}{\partial\boldsymbol{\psi}^n}
101
- \right]
102
- }_{\boldsymbol{A}_{-1}(\boldsymbol{\psi}^n)}
103
- \frac{\partial \boldsymbol{\psi}^n}{\partial\boldsymbol{m}}
104
- =
105
- \underbrace{
106
- \left[
107
- -\boldsymbol{D}
108
- \text{diag}\left( \boldsymbol{G} \boldsymbol{\psi}^{n+1} \right)
109
- \frac{\partial \boldsymbol{k}_{Av}}{\partial\boldsymbol{m}}
110
- -\boldsymbol{G}_{z}
111
- \frac{\partial \boldsymbol{k}_{Av}}{\partial\boldsymbol{m}}
112
- \right]
113
- }_{\boldsymbol{B}(\psi^{n+1})}&
114
- \end{align*}
115
- typst: |-
116
- overbrace(
117
- [
118
- 1/(Delta t)
119
- (diff bold(theta)^(n + 1))/(diff bold(psi)^(n + 1))
120
- - bold(D)
121
- "diag"(bold(G) bold(psi)^(n + 1))
122
- (diff bold(k)_(A v))/(diff bold(psi)^(n + 1))
123
- - bold(D)
124
- "diag"(bold(k)_(A v) (bold(psi)^(n + 1) comma bold(m)))
125
- bold(G)
126
- - bold(G)_z
127
- (diff bold(k)_(A v))/(diff bold(psi)^(n + 1))
128
- ]
129
- , bold(A)_0 (bold(psi)^(n + 1)))
130
- (diff bold(psi)^(n + 1))/(diff bold(m))
131
- \
132
- +
133
- underbrace(
134
- [
135
- - 1/(Delta t)
136
- (diff bold(theta)^n)/(diff bold(psi)^n)
137
- ]
138
- , bold(A)_(-1) (bold(psi)^n))
139
- (diff bold(psi)^n)/(diff bold(m))
140
- =
141
- underbrace(
142
- [
143
- -bold(D)
144
- "diag"(bold(G) bold(psi)^(n + 1))
145
- (diff bold(k)_(A v))/(diff bold(m))
146
- - bold(G)_z
147
- (diff bold(k)_(A v))/(diff bold(m))
148
- ]
149
- , bold(B)(psi^(n + 1))) &
150
- - title: leading underscore
151
- tex: _2
152
- typst: '#none_2'
153
- - title: leading power
154
- tex: '^{\text{st}}'
155
- typst: '#none^"st"'
156
- - title: greater than
157
- tex: 'a \ge b'
158
- typst: a >= b
159
- - title: greater than (preferShorthands=false)
160
- tex: 'a \ge b'
161
- typst: a gt.eq b
162
- preferShorthands: false
163
- - title: ddot
164
- tex: 'q, \dot{q}, \ddot{q}'
165
- typst: q, dot(q), dot.double(q)
166
- - title: mat
167
- tex: 'x(t) = \left[ \begin{array}{c} q(t) & x \\ \dot{q}(t) & x \end{array}\right]'
168
- typst: 'x(t) = [mat(delim: #none, align: #center, q(t), x; dot(q)(t), x)]'
169
- - title: brackets
170
- tex: '\frac{1}{\tau(X_2)}'
171
- typst: '1/(tau(X_2))'
172
- - title: bar and nested bb
173
- tex: '\mathbb{\bar{R}}'
174
- typst: 'bb(macron(R))'
175
- - title: Underscore with no content
176
- tex: 'P_{}^{1}'
177
- typst: 'P_()^1'
178
- - title: Simple overbrace
179
- tex: '\overbrace{a}^{b}'
180
- typst: 'overbrace(a, b)'
181
- - title: underbrace
182
- tex: '\underbrace{a}_{b}'
183
- typst: underbrace(a, b)
184
- - title: Test
185
- tex: a^{b^{n+1}}
186
- typst: a^(b^(n + 1))
187
- - title: Test2
188
- tex: a+b^1 + \frac{2}{3} + \overbrace{123}^{b}
189
- typst: a + b^1 + 2/3 + overbrace(123, b)
190
- - title: Symbols
191
- tex: '\alpha \nabla \partial'
192
- typst: alpha nabla diff
193
- - title: Align
194
- tex: |-
195
- \begin{align*}
196
- a &= b \\
197
- c &= d
198
- \end{align*}
199
- typst: |-
200
- a &= b \
201
- c &= d
202
- - title: Matrix cells are groups
203
- tex: |-
204
- m = \begin{matrix}
205
- a &= b \\
206
- c &= d
207
- \end{matrix}
208
- typst: |-
209
- m = mat(delim: #none, a, = b;
210
- c, = d)
211
- - title: An align mark & is at the beginning of a line
212
- tex: |-
213
- \begin{matrix}
214
- &a &= b \\
215
- &c &= d
216
- \end{matrix}
217
- typst: |-
218
- mat(delim: #none, , a, = b;
219
- , c, = d)
220
- - title: Array
221
- tex: |-
222
- \begin{array}{cc}
223
- a & b \\
224
- c & d
225
- \end{array}
226
- typst: |-
227
- mat(delim: #none, align: #center, a, b;
228
- c, d)
229
- - title: Array with vertical line
230
- tex: |-
231
- \begin{array}{c|c|c}
232
- a & b & c \\
233
- c & d & e
234
- \end{array}
235
- typst: |-
236
- mat(delim: #none, augment: #(vline: (1, 2)), align: #center, a, b, c;
237
- c, d, e)
238
- - title: Array with single vertical line
239
- tex: |-
240
- \begin{array}{c|cc}
241
- a & b & c \\
242
- c & d & e
243
- \end{array}
244
- typst: |-
245
- mat(delim: #none, augment: #1, align: #center, a, b, c;
246
- c, d, e)
247
- # should not mistakenly ignore `{x}` in `\begin{matrix} {x} ... \end{matrix}`
248
- - title: should not parse arg if envName is not one of array, subarray
249
- tex: \begin{matrix} {x} & {y} \\ {z} & {w} \end{matrix}
250
- typst: "mat(delim: #none, x, y; z, w)"
251
- - title: Test3
252
- tex: \boldsymbol{x}
253
- typst: bold(x)
254
- - title: Test4
255
- tex: a^2 + b^2 = c^2
256
- typst: a^2 + b^2 = c^2
257
- - title: Euler Complex Exponential
258
- tex: e^{i\theta} = \cos \theta + i \sin \theta
259
- typst: e^(i theta) = cos theta + i sin theta
260
- - title: Euler Product
261
- tex: \prod_{p} \frac{1}{1-p^{-s}}= \sum_{n=1}^{\infty} \frac{1}{n^s}
262
- typst: product_p 1/(1 - p^(-s)) = sum_(n = 1)^infinity 1/(n^s)
263
- - title: Test5
264
- tex: "{a+b}^2"
265
- typst: (a + b)^2
266
- - title: Test6
267
- tex: 1 + {a + b} + c
268
- typst: 1 + a + b + c
269
- - title: Test7
270
- tex: (a + b)^2
271
- typst: (a + b)^2
272
- - title: leading minus sign
273
- tex: a^{-s}
274
- typst: a^(-s)
275
- - title: Test8
276
- tex: \sqrt{\frac{1}{x^2 + y^2}}
277
- typst: sqrt(1/(x^2 + y^2))
278
- - title: basic prime case
279
- tex: y'
280
- typst: y'
281
- - title: has both prime and subscript
282
- tex: y_1' + y'_2 + y_{a_1}' + {\theta}_1'
283
- typst: y'_1 + y'_2 + y'_(a_1) + theta'_1
284
-
285
- - title: space before or after script
286
- tex: \lim _{x \to 0} \sum_{i=1} ^ n
287
- typst: lim_(x -> 0) sum_(i = 1)^n
288
- - title: spaces around text
289
- tex: i_D = \mu_n C_\text{ox} \frac{W}{L} \left[ (v_\text{GS} - V_t)v_\text{DS} - \frac{1}{2} v_\text{DS}^2 \right]
290
- typst: i_D = mu_n C_"ox" W/L [(v_"GS" - V_t) v_"DS" - 1/2 v_"DS"^2]
291
- - title: base is group wrapped in brackets
292
- tex: e = \lim_{{n \to \infty}} \left(1 + \frac{1}{n}\right)^n
293
- typst: e = lim_(n -> infinity) (1 + 1/n)^n
294
-
295
- - title: oo
296
- tex: \infty
297
- typst: oo
298
- inftyToOo: true
299
- - title: overrightarrow
300
- tex: \overrightarrow{AB}
301
- typst: arrow(A B)
302
- - title: overleftarrow
303
- tex: \overleftarrow{AB}
304
- typst: accent(A B, <-)
305
- - title: Horizontal space symbols
306
- tex: "\\, \\: \\; \\quad \\!"
307
- typst: "thin med thick quad #h(-math.thin.amount)"
308
- - title: cases1
309
- tex: |-
310
- \begin{cases}
311
- x^2, & \text{if } x \geq 0 \\
312
- -x, & \text{if } x < 0
313
- \end{cases}
314
- typst: |-
315
- cases(x^2 comma & "if " x >= 0,
316
- - x comma & "if " x < 0)
317
- - title: cases2
318
- tex: |-
319
- A_{ij} =
320
- \begin{cases}
321
- 1, & \text{if } i = j \\
322
- 0, & \text{otherwise}
323
- \end{cases}
324
- typst: |-
325
- A_(i j) =
326
- cases(1 comma & "if " i = j,
327
- 0 comma & "otherwise")
328
- - title: cases3
329
- tex: |-
330
- P(X = x) =
331
- \begin{cases}
332
- \frac{1}{n}, & x \in \{1,2,\dots,n\} \\
333
- 0, & \text{otherwise}
334
- \end{cases}
335
- typst: |-
336
- P(X = x) =
337
- cases(1/n comma & x in {1 comma 2 comma ... comma n},
338
- 0 comma & "otherwise")
339
- - title: cases4
340
- tex: |-
341
- f(x) =
342
- \begin{cases}
343
- x^2 + 1, & \text{if } x < -1 \\
344
- \sin x + x^2, & \text{if } -1 \leq x \leq 1 \\
345
- \sqrt{x}, & \text{if } x > 1
346
- \end{cases}
347
- typst: |-
348
- f(x) =
349
- cases(x^2 + 1 comma & "if " x < - 1,
350
- sin x + x^2 comma & "if " - 1 <= x <= 1,
351
- sqrt(x) comma & "if " x > 1)
352
- - title: cases5
353
- tex: |-
354
- \begin{align*}
355
- f(x) &=
356
- \begin{cases}
357
- x^2, & x \geq 0 \\
358
- -x, & x < 0
359
- \end{cases} \\
360
- g(x) &=
361
- \begin{cases}
362
- \sin x, & x < \pi \\
363
- 0, & x \geq \pi
364
- \end{cases}
365
- \end{align*}
366
-
367
- typst: |-
368
- f(x) &=
369
- cases(x^2 comma & x >= 0,
370
- - x comma & x < 0) \
371
- g(x) &=
372
- cases(sin x comma & x < pi,
373
- 0 comma & x >= pi)
374
- - title: frac1
375
- tex: \frac ab
376
- typst: a/b
377
- - title: frac2
378
- tex: \frac 12
379
- typst: 1/2
380
- - title: frac3
381
- tex: \frac 12
382
- typst: 1/2
383
- - title: frac4
384
- tex: \frac12
385
- typst: 1/2
386
- - title: frac5
387
- tex: \frac{12}{34}
388
- typst: 12/34
389
- - title: frac6
390
- tex: \frac123
391
- typst: 1/2 3
392
- - title: frac7
393
- tex: \frac {12}3
394
- typst: 12/3
395
- # this test the lexer's regex. Old bad implementation translated it to "yen 2 0 00 \$ 3000"
396
- - title: yen
397
- tex: \yen 2000 > \$ 3000
398
- typst: yen 2000 > \$ 3000
399
- # this test the typst writer. Old bad implementation translated it to "X/Y/2"
400
- - title: frac of frac
401
- tex: \frac{X}{\frac{Y}{2}}
402
- typst: X/(Y/2)
403
- - title: Don't escape commas inside a lr()
404
- tex: \left| f(a, b) \right|
405
- typst: lr(|f(a, b)|)
406
- - title: Backslash space
407
- tex: a \ b
408
- typst: a med b
409
- # this test the typst formatter. Old bad implementation translated it to "C(x y)/z"
410
- - title: parenthesis in fraction
411
- tex: C \frac{xy}{z}
412
- typst: C (x y)/z
413
- # this test the typst formatter. Old bad implementation translated it to "1/3(x + y)"
414
- - title: parenthesis after fraction
415
- tex: \frac{1}{3} (x + y)
416
- typst: 1/3 (x + y)
417
- - title: substack
418
- tex: \sum_{\substack{0 \leq i \leq m \\ 0 < j < n}} P(i, j)
419
- typst: sum_(0 <= i <= m \ 0 < j < n) P(i, j)
420
- - title: subarray-l
421
- tex: \sum_{\begin{subarray}{l} 0 \leq i \leq m \\ 0 < j < n \end{subarray}} P(i, j)
422
- typst: sum_(& 0 <= i <= m \ & 0 < j < n) P(i, j)
423
- - title: subarray
424
- tex: \sum_{\begin{subarray}{c} 0 \leq i \leq m \\ 0 < j < n \end{subarray}} P(i, j)
425
- typst: sum_(0 <= i <= m \ 0 < j < n) P(i, j)
426
- - title: subarray-r
427
- tex: \sum_{\begin{subarray}{r} 0 \leq i \leq m \\ 0 < j < n \end{subarray}} P(i, j)
428
- typst: sum_(0 <= i <= m & \ 0 < j < n &) P(i, j)
429
- - title: subarray-with-rr &
430
- tex: \sum_{\begin{subarray}{rr} a & b \\ c & d \end{subarray}} P(i, j)
431
- typst: sum_(a & b \ c & d) P(i, j)
432
- - title: command set
433
- tex: \set{a, b, c}
434
- typst: "{a, b, c}"
435
- - title: command set, empty
436
- tex: \set{}
437
- typst: "{}"
438
- - title: command displaylines is ignored
439
- tex: |-
440
- \displaylines{
441
- E = mc^2 \\
442
- F = ma \\
443
- P = IV
444
- }
445
- typst: |-
446
- E = m c^2 \
447
- F = m a \
448
- P = I V
449
- - title: command mathinner is ignored
450
- tex: ab\mathinner{\text{inside}}cd
451
- typst: a b "inside" c d