tex2typst 0.4.0 → 0.4.1
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/dist/index.js +153 -191
- package/dist/tex2typst.min.js +10 -11
- package/package.json +2 -2
- package/src/convert.ts +37 -13
- package/src/generic.ts +6 -6
- package/src/tex-parser.ts +19 -47
- package/src/tex-tokenizer.ts +1 -0
- package/src/tex-types.ts +1 -1
- package/src/typst-parser.ts +114 -160
- package/tests/cheat-sheet.test.ts +0 -42
- package/tests/cheat-sheet.toml +0 -304
- package/tests/example.ts +0 -15
- package/tests/general-symbols.test.ts +0 -22
- package/tests/general-symbols.toml +0 -755
- package/tests/integration-tex2typst.yaml +0 -89
- package/tests/struct-bidirection.yaml +0 -203
- package/tests/struct-tex2typst.yaml +0 -451
- package/tests/struct-typst2tex.yaml +0 -412
- package/tests/symbol.yml +0 -126
- package/tests/test-common.ts +0 -26
- package/tests/tex-parser.test.ts +0 -97
- package/tests/tex-to-typst.test.ts +0 -136
- package/tests/typst-parser.test.ts +0 -134
- package/tests/typst-to-tex.test.ts +0 -100
- /package/src/{util.ts → utils.ts} +0 -0
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
title: integration-tex2typst
|
|
2
|
-
cases:
|
|
3
|
-
- title: base of natural logarithm
|
|
4
|
-
tex: \mathrm{e} \overset{\text{def}}{=} \lim_{{n \to \infty}} \left(1 + \frac{1}{n}\right)^n
|
|
5
|
-
typst: upright(e) eq.def lim_(n -> infinity) (1 + 1/n)^n
|
|
6
|
-
- title: Euler's product formula
|
|
7
|
-
tex: \prod_{p} \frac{1}{1-p^{-s}} = \sum_{n=1}^{\infty} \frac{1}{n^s}
|
|
8
|
-
typst: product_p 1/(1 - p^(-s)) = sum_(n = 1)^infinity 1/(n^s)
|
|
9
|
-
- title: Fermat's little theorem
|
|
10
|
-
tex: a^{p-1} \equiv 1 \mod{p}
|
|
11
|
-
typst: a^(p - 1) equiv 1 mod p
|
|
12
|
-
- title: Maxwell's equations
|
|
13
|
-
tex: |-
|
|
14
|
-
\begin{aligned}
|
|
15
|
-
\nabla \times \boldsymbol{H} &= \boldsymbol{J} + \frac{\partial \boldsymbol{D}}{\partial t} \\
|
|
16
|
-
\nabla \times \boldsymbol{E} &= -\frac{\partial \boldsymbol{B}}{\partial t} \\
|
|
17
|
-
\nabla \cdot \boldsymbol{B} &= 0 \\
|
|
18
|
-
\nabla \cdot \boldsymbol{D} &= \rho
|
|
19
|
-
\end{aligned}
|
|
20
|
-
typst: |-
|
|
21
|
-
nabla times bold(H) &= bold(J) + (diff bold(D))/(diff t) \
|
|
22
|
-
nabla times bold(E) &= - (diff bold(B))/(diff t) \
|
|
23
|
-
nabla dot.op bold(B) &= 0 \
|
|
24
|
-
nabla dot.op bold(D) &= rho
|
|
25
|
-
- title: chemical equation example - bromoethane to ethanol
|
|
26
|
-
tex: \rm{CH_3CH_2Br} + \rm{OH}^- \longrightarrow \rm{CH_3CH_2OH} + \rm{Br}^-
|
|
27
|
-
typst: upright(C H_3 C H_2 B r) + upright(O H)^- --> upright(C H_3 C H_2 O H) + upright(B r)^-
|
|
28
|
-
- title: harmonic series
|
|
29
|
-
tex: \sum_{k=1}^n \frac{1}{k} = \ln n + \gamma + O\left(\frac{1}{n}\right)
|
|
30
|
-
typst: sum_(k = 1)^n 1/k = ln n + gamma + O(1/n)
|
|
31
|
-
- title: Euler's complex exponential formula
|
|
32
|
-
tex: \mathrm{e}^{\mathrm{i} x} = \cos x + \mathrm{i} \sin x
|
|
33
|
-
typst: upright(e)^(upright(i) x) = cos x + upright(i) sin x
|
|
34
|
-
- title: Gauss's divergence theorem
|
|
35
|
-
tex: \iiint_{\Omega} \operatorname{div}(\vec{F}) \mathrm{d}V = \oiint_{\partial \Omega} \vec{F} \cdot \mathrm{d}\vec{S}
|
|
36
|
-
typst: integral.triple_Omega op("div")(arrow(F)) dif V = integral.surf_(diff Omega) arrow(F) dot.op dif arrow(S)
|
|
37
|
-
- title: Stokes' theorem
|
|
38
|
-
tex: \iint_{\Sigma} \operatorname{curl}(\vec{F}) \cdot \mathrm{d}\vec{S} = \oint_{\partial \Sigma} \vec{F} \times \mathrm{d}\vec{l}
|
|
39
|
-
typst: integral.double_Sigma op("curl")(arrow(F)) dot.op dif arrow(S) = integral.cont_(diff Sigma) arrow(F) times dif arrow(l)
|
|
40
|
-
- title: Prime number theorem
|
|
41
|
-
tex: \pi(x) \sim \frac{x}{\log x}
|
|
42
|
-
typst: pi(x) ~ x/(log x)
|
|
43
|
-
- title: current-voltage characteristics of n-channel enhancement MOSFETs
|
|
44
|
-
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]
|
|
45
|
-
typst: i_D = mu_n C_"ox" W/L [(v_"GS" - V_t) v_"DS" - 1/2 v_"DS"^2]
|
|
46
|
-
- title: Black-Scholes formula for option pricing
|
|
47
|
-
tex: |-
|
|
48
|
-
\begin{aligned}
|
|
49
|
-
C &= N(d_1) S_t - N(d_2) K e^{-rt} \\
|
|
50
|
-
d_1 &= \frac{\ln \frac{S_t}{K} + (r + \frac{\sigma^2}{2}) t}{\sigma \sqrt{t}} \\
|
|
51
|
-
d_2 &= d_1 - \sigma\sqrt{t}
|
|
52
|
-
\end{aligned}
|
|
53
|
-
typst: |-
|
|
54
|
-
C &= N(d_1) S_t - N(d_2) K e^(-r t) \
|
|
55
|
-
d_1 &= (ln (S_t)/K +(r + (sigma^2)/2) t)/(sigma sqrt(t)) \
|
|
56
|
-
d_2 &= d_1 - sigma sqrt(t)
|
|
57
|
-
- title: Cauchy's integral formula
|
|
58
|
-
tex: f(z_0) = \frac{1}{2\pi \mathrm{i}} \oint_{C} \frac{f(z)}{z-z_0}\, \mathrm{d} z
|
|
59
|
-
typst: f(z_0) = 1/(2 pi upright(i)) integral.cont_C (f(z))/(z - z_0) thin dif z
|
|
60
|
-
- title: determinant of a Vandermonde matrix
|
|
61
|
-
tex: |-
|
|
62
|
-
\begin{vmatrix}
|
|
63
|
-
1 & 1 & \dots & 1 \\
|
|
64
|
-
x_1 & x_2 & \dots & x_n \\
|
|
65
|
-
x_1^2 & x_2^2 & \dots & x_n^2 \\
|
|
66
|
-
\vdots & \vdots & \ddots & \vdots \\
|
|
67
|
-
x_1^{n-1} & x_2^{n-1} & \dots & x_n^{n-1}
|
|
68
|
-
\end{vmatrix}
|
|
69
|
-
= \prod_{1 \leq i < j \leq n} (x_j - x_i)
|
|
70
|
-
# TODO: There should no spaces after x_n and x_n^2
|
|
71
|
-
typst: |-
|
|
72
|
-
mat(delim: "|", 1, 1, ..., 1;
|
|
73
|
-
x_1, x_2, ..., x_n;
|
|
74
|
-
x_1^2, x_2^2, ..., x_n^2;
|
|
75
|
-
dots.v, dots.v, dots.down, dots.v;
|
|
76
|
-
x_1^(n - 1), x_2^(n - 1), ..., x_n^(n - 1))
|
|
77
|
-
= product_(1 <= i < j <= n) (x_j - x_i)
|
|
78
|
-
- title: ReLU function
|
|
79
|
-
tex: |-
|
|
80
|
-
\operatorname{ReLU}(x) = \begin{cases}
|
|
81
|
-
x & \text{if } x > 0 \\
|
|
82
|
-
0 & \text{if } x \leq 0
|
|
83
|
-
\end{cases}
|
|
84
|
-
typst: |-
|
|
85
|
-
op("ReLU")(x) = cases(x & "if " x > 0,
|
|
86
|
-
0 & "if " x <= 0)
|
|
87
|
-
- title: attention mechanism
|
|
88
|
-
tex: \operatorname{Attention}(Q, K, V) = \operatorname{softmax}\left(\frac{QK^T}{\sqrt{d_k}}\right) V
|
|
89
|
-
typst: op("Attention")(Q, K, V) = op("softmax")((Q K^T)/sqrt(d_k)) V
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
title: Bidirectional conversion of structures
|
|
2
|
-
cases:
|
|
3
|
-
- title: a complex structure as script
|
|
4
|
-
# This doesn't actually need the extra brackets, but it is clearer!
|
|
5
|
-
tex: 'e_{f(x)}'
|
|
6
|
-
typst: e_(f(x))
|
|
7
|
-
- title: Nested scripts
|
|
8
|
-
tex: 'r_{s^+}'
|
|
9
|
-
typst: 'r_(s^+)'
|
|
10
|
-
- title: Text Functions
|
|
11
|
-
tex: '\text{diag}'
|
|
12
|
-
typst: '"diag"'
|
|
13
|
-
- title: Single Char Text
|
|
14
|
-
tex: \text{a}
|
|
15
|
-
typst: '"a"'
|
|
16
|
-
- title: Aligned
|
|
17
|
-
tex: |-
|
|
18
|
-
\begin{aligned}
|
|
19
|
-
a &= b \\
|
|
20
|
-
c &= d
|
|
21
|
-
\end{aligned}
|
|
22
|
-
typst: |-
|
|
23
|
-
a &= b \
|
|
24
|
-
c &= d
|
|
25
|
-
- title: An align mark & is at the beginning of a line
|
|
26
|
-
tex: |-
|
|
27
|
-
\begin{aligned}
|
|
28
|
-
& a &= b \\
|
|
29
|
-
& c &= d
|
|
30
|
-
\end{aligned}
|
|
31
|
-
typst: |-
|
|
32
|
-
& a &= b \
|
|
33
|
-
& c &= d
|
|
34
|
-
- title: matrix
|
|
35
|
-
tex: |-
|
|
36
|
-
m = \begin{matrix}
|
|
37
|
-
a & b \\
|
|
38
|
-
c & d \\
|
|
39
|
-
e & f
|
|
40
|
-
\end{matrix}
|
|
41
|
-
typst: |-
|
|
42
|
-
m = mat(delim: #none, a, b;
|
|
43
|
-
c, d;
|
|
44
|
-
e, f)
|
|
45
|
-
- title: pmatrix
|
|
46
|
-
tex: |-
|
|
47
|
-
m = \begin{pmatrix}
|
|
48
|
-
a & b \\
|
|
49
|
-
c & d
|
|
50
|
-
\end{pmatrix}
|
|
51
|
-
typst: |-
|
|
52
|
-
m = mat(a, b;
|
|
53
|
-
c, d)
|
|
54
|
-
- title: bmatrix
|
|
55
|
-
tex: |-
|
|
56
|
-
m = \begin{bmatrix}
|
|
57
|
-
a & b \\
|
|
58
|
-
c & d
|
|
59
|
-
\end{bmatrix}
|
|
60
|
-
typst: |-
|
|
61
|
-
m = mat(delim: "[", a, b;
|
|
62
|
-
c, d)
|
|
63
|
-
- title: Bmatrix
|
|
64
|
-
tex: |-
|
|
65
|
-
m = \begin{Bmatrix}
|
|
66
|
-
a & b \\
|
|
67
|
-
c & d
|
|
68
|
-
\end{Bmatrix}
|
|
69
|
-
typst: |-
|
|
70
|
-
m = mat(delim: "{", a, b;
|
|
71
|
-
c, d)
|
|
72
|
-
- title: vmatrix
|
|
73
|
-
tex: |-
|
|
74
|
-
m = \begin{vmatrix}
|
|
75
|
-
a & b \\
|
|
76
|
-
c & d
|
|
77
|
-
\end{vmatrix}
|
|
78
|
-
typst: |-
|
|
79
|
-
m = mat(delim: "|", a, b;
|
|
80
|
-
c, d)
|
|
81
|
-
- title: Vmatrix
|
|
82
|
-
tex: |-
|
|
83
|
-
m = \begin{Vmatrix}
|
|
84
|
-
a & b \\
|
|
85
|
-
c & d
|
|
86
|
-
\end{Vmatrix}
|
|
87
|
-
typst: |-
|
|
88
|
-
m = mat(delim: bar.v.double, a, b;
|
|
89
|
-
c, d)
|
|
90
|
-
- title: accent, symbol over variable
|
|
91
|
-
tex: \bar{y} \vec{x} \dot{y} \ddot{y} \tilde{a} \hat{a}
|
|
92
|
-
typst: macron(y) arrow(x) dot(y) dot.double(y) tilde(a) hat(a)
|
|
93
|
-
- title: underline, overline
|
|
94
|
-
tex: \underline{a} \overline{a} \underline{a + 1} \overline{a + 1}
|
|
95
|
-
typst: underline(a) overline(a) underline(a + 1) overline(a + 1)
|
|
96
|
-
- title: comment
|
|
97
|
-
tex: a + b % comment
|
|
98
|
-
typst: a + b // comment
|
|
99
|
-
- title: comment2
|
|
100
|
-
tex: a + b % comment % comment2
|
|
101
|
-
typst: a + b // comment % comment2
|
|
102
|
-
- title: comment3
|
|
103
|
-
tex: |-
|
|
104
|
-
a + b % co
|
|
105
|
-
c + d
|
|
106
|
-
e + f % co
|
|
107
|
-
g + h
|
|
108
|
-
typst: |-
|
|
109
|
-
a + b // co
|
|
110
|
-
c + d
|
|
111
|
-
e + f // co
|
|
112
|
-
g + h
|
|
113
|
-
- title: mod
|
|
114
|
-
tex: a^{p - 1} \equiv 1 \mod p
|
|
115
|
-
typst: a^(p - 1) equiv 1 mod p
|
|
116
|
-
- title: overset
|
|
117
|
-
tex: \overset{a}{+}
|
|
118
|
-
typst: limits(+)^a
|
|
119
|
-
- title: underset
|
|
120
|
-
tex: \underset{a}{+}
|
|
121
|
-
typst: limits(+)_a
|
|
122
|
-
- title: overset, special case 1
|
|
123
|
-
tex: \overset{\text{def}}{=}
|
|
124
|
-
typst: eq.def
|
|
125
|
-
- title: newline
|
|
126
|
-
tex: |-
|
|
127
|
-
a + b \\
|
|
128
|
-
c + d
|
|
129
|
-
typst: |-
|
|
130
|
-
a + b \
|
|
131
|
-
c + d
|
|
132
|
-
- title: leading sign
|
|
133
|
-
tex: -a
|
|
134
|
-
typst: -a
|
|
135
|
-
- title: Mathrm
|
|
136
|
-
tex: 'p_e = 1 - \mathrm{e}^{-t \lambda}'
|
|
137
|
-
typst: p_e = 1 - upright(e)^(-t lambda)
|
|
138
|
-
- title: decimals
|
|
139
|
-
tex: "3.14"
|
|
140
|
-
typst: "3.14"
|
|
141
|
-
- title: Cube root
|
|
142
|
-
tex: '\sqrt[3]{x}'
|
|
143
|
-
typst: root(3, x)
|
|
144
|
-
- title: floor and ceil
|
|
145
|
-
tex: \lfloor 1.2 \rfloor + \lceil 1.2 \rceil
|
|
146
|
-
typst: floor(1.2) + ceil(1.2)
|
|
147
|
-
- title: floor and ceil with overHigh
|
|
148
|
-
tex: \left \lfloor \frac{1}{2} \right \rfloor + \left \lceil \frac{1}{2} \right \rceil
|
|
149
|
-
typst: floor(1/2) + ceil(1/2)
|
|
150
|
-
# - title: norm
|
|
151
|
-
# tex: \|a \|^2
|
|
152
|
-
# typst: norm(a)^2
|
|
153
|
-
- title: norm with overHigh
|
|
154
|
-
tex: \left \|a + \frac{1}{3} \right \|^2
|
|
155
|
-
typst: norm(a + 1/3)^2
|
|
156
|
-
- title: left right angles
|
|
157
|
-
tex: \left\langle \frac{1}{2} \right\rangle
|
|
158
|
-
typst: lr(angle.l 1/2 angle.r)
|
|
159
|
-
- title: lparen rparen
|
|
160
|
-
tex: \left\lparen \frac{1}{3} \right\rparen
|
|
161
|
-
typst: lr(paren.l 1/3 paren.r)
|
|
162
|
-
- title: lbrace rbrace
|
|
163
|
-
tex: \left\lbrace \frac{1}{3} \right\rbrace
|
|
164
|
-
typst: lr(brace.l 1/3 brace.r)
|
|
165
|
-
- title: fractions as function argument
|
|
166
|
-
tex: g(\frac{1}{2})
|
|
167
|
-
typst: g(1/2)
|
|
168
|
-
- title: multiple arguments should join with a comma
|
|
169
|
-
tex: A(B(x, y))
|
|
170
|
-
typst: A(B(x, y))
|
|
171
|
-
- title: mathbb
|
|
172
|
-
tex: \mathbb{A} \mathbb{B} \mathbb{C} \mathbb{D} \mathbb{E} \mathbb{F} \mathbb{G} \mathbb{H} \mathbb{I} \mathbb{J} \mathbb{K} \mathbb{L} \mathbb{M} \mathbb{N} \mathbb{O} \mathbb{P} \mathbb{Q} \mathbb{R} \mathbb{S} \mathbb{T} \mathbb{U} \mathbb{V} \mathbb{W} \mathbb{X} \mathbb{Y} \mathbb{Z}
|
|
173
|
-
typst: AA BB CC DD EE FF GG HH II JJ KK LL MM NN OO PP QQ RR SS TT UU VV WW XX YY ZZ
|
|
174
|
-
- title: hspace
|
|
175
|
-
tex: \hspace{1cm}
|
|
176
|
-
typst: "#h(1cm)"
|
|
177
|
-
- title: leftright ()
|
|
178
|
-
tex: \left(a + \frac{1}{3} \right)
|
|
179
|
-
typst: (a + 1/3)
|
|
180
|
-
# - title: leftright {}
|
|
181
|
-
# tex: \left\{a + \frac{1}{3} \right\}
|
|
182
|
-
# typst: "{a + 1/3}"
|
|
183
|
-
- title: textcolor
|
|
184
|
-
tex: x = \textcolor{red}{a + y}
|
|
185
|
-
typst: "x = #text(fill: red)[$a + y$]"
|
|
186
|
-
- title: mathrel
|
|
187
|
-
tex: a \mathrel{X} b
|
|
188
|
-
typst: a class("relation", X) b
|
|
189
|
-
- title: mathbin
|
|
190
|
-
tex: a \mathbin{X} b
|
|
191
|
-
typst: a class("binary", X) b
|
|
192
|
-
- title: mathop
|
|
193
|
-
tex: a \mathop{X} b
|
|
194
|
-
typst: a class("large", X) b
|
|
195
|
-
- title: display style
|
|
196
|
-
tex: a = \displaystyle \sum_i x_i
|
|
197
|
-
typst: a = display(sum_i x_i)
|
|
198
|
-
- title: display style, case 3
|
|
199
|
-
tex: \displaystyle \lim_x F(x) = 0, \lim_x F(x) = 1
|
|
200
|
-
typst: display(lim_x F(x) = 0 comma lim_x F(x) = 1)
|
|
201
|
-
- title: display style, case 4
|
|
202
|
-
tex: \lim_x F(x) = 0, \displaystyle \lim_x F(x) = 1
|
|
203
|
-
typst: lim_x F(x) = 0, display(lim_x F(x) = 1)
|