Skip to content

Commit

Permalink
Typst writer: escape commas.
Browse files Browse the repository at this point in the history
Otherwise we can get bad results e.g. in fractions, when
the commas separate arguments.

Closes #242.
  • Loading branch information
jgm committed Nov 11, 2024
1 parent 1f60df1 commit 1703b41
Show file tree
Hide file tree
Showing 10 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/Text/TeXMath/Writers/Typst.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ esc t =
needsEscape '"' = True
needsEscape '/' = True
needsEscape '\\' = True
needsEscape ',' = True -- #242
needsEscape _ = False

escInQuotes :: Text -> Text
Expand Down
2 changes: 1 addition & 1 deletion test/writer/typst/07.test
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
, EIdentifier "a"
]
>>> typst
u'' + p (x) u' + q (x) u = f (x) , quad x > a
u'' + p (x) u' + q (x) u = f (x) \, quad x > a
2 changes: 1 addition & 1 deletion test/writer/typst/08.test
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
, EDelimited "(" ")" [ Right (EIdentifier "z") ]
]
>>> typst
lr(|z^(‾)|) = lr(|z|) , lr(|(z^(‾))^n|) = lr(|z|)^n , arg (z^n) = n arg (z)
lr(|z^(‾)|) = lr(|z|) \, lr(|(z^(‾))^n|) = lr(|z|)^n \, arg (z^n) = n arg (z)
2 changes: 1 addition & 1 deletion test/writer/typst/11.test
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
NormalFrac (ENumber "1") (ESub (EIdentifier "l") (ENumber "0"))
]
>>> typst
phi.alt_n (kappa) = 0.033 C_n^2 kappa^(- 11 \/ 3) , quad 1 / L_0 lt.double kappa lt.double 1 / l_0
phi.alt_n (kappa) = 0.033 C_n^2 kappa^(- 11 \/ 3) \, quad 1 / L_0 lt.double kappa lt.double 1 / l_0
2 changes: 1 addition & 1 deletion test/writer/typst/13.test
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@
(EGrouped [ EIdentifier "n" , ESymbol Ord "!" ])
]
>>> typst
zws_p F_q (a_1 , dots.h , a_p ; c_1 , dots.h , c_q ; z) = sum_(n = 0)^oo frac((a_1)_n dots.h.c (a_p)_n, (c_1)_n dots.h.c (c_q)_n) frac(z^n, n !)
zws_p F_q (a_1 \, dots.h \, a_p ; c_1 \, dots.h \, c_q ; z) = sum_(n = 0)^oo frac((a_1)_n dots.h.c (a_p)_n, (c_1)_n dots.h.c (c_q)_n) frac(z^n, n !)
2 changes: 1 addition & 1 deletion test/writer/typst/binomial_coefficient.test
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@
])
]
>>> typst
bold(C) (n , k) = bold(C)_k^n = zws_n bold(C)_k = binom(n, k) = frac(n !, k ! thin (n - k) !)
bold(C) (n \, k) = bold(C)_k^n = zws_n bold(C)_k = binom(n, k) = frac(n !, k ! thin (n - k) !)
2 changes: 1 addition & 1 deletion test/writer/typst/complex1.test
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ nabla zws dot.c B^harpoon.lt_() & = & 0\
upright("Einstein Field Equations") & R_(mu nu)^() - 1 / 2 thin g_(mu nu)^() thin R = frac(8 pi G, c_()^4) thin T_(mu nu)^()\
upright("Ramanujan Identity") & frac(1, \( sqrt(phi sqrt(5)) - phi \) e_()^(25 / pi)) = 1 + frac(e_()^(- 2 pi), 1 + frac(e_()^(- 4 pi), 1 + frac(e_()^(- 6 pi), 1 + frac(e_()^(- 8 pi), 1 + dots.h))))\
upright("Another Ramanujan identity") & sum_(k = 1)^oo 1 / 2_()^(floor.l k dot.c zws phi floor.r) = frac(1, 2_()^0 + frac(1, 2_()^1 + dots.h.c))\
upright("Rogers-Ramanujan Identity") & 1 + sum_(k = 1)^oo frac(q_()^(k_()^2 + k), \( 1 - q \) \( 1 - q_()^2 \) dots.h.c \( 1 - q_()^k \)) = product_(j = 0)^oo frac(1, \( 1 - q_()^(5 j + 2) \) \( 1 - q_()^(5 j + 3) \)) , upright("  ") upright("  ") f o r med \| q \| < 1 .\
upright("Rogers-Ramanujan Identity") & 1 + sum_(k = 1)^oo frac(q_()^(k_()^2 + k), \( 1 - q \) \( 1 - q_()^2 \) dots.h.c \( 1 - q_()^k \)) = product_(j = 0)^oo frac(1, \( 1 - q_()^(5 j + 2) \) \( 1 - q_()^(5 j + 3) \)) \, upright("  ") upright("  ") f o r med \| q \| < 1 .\
upright("Commutative Diagram") & H & arrow.l & K\
arrow.b & zws & arrow.t\
H & arrow.r & K
2 changes: 1 addition & 1 deletion test/writer/typst/differentiable_manifold.test
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@
]
]
>>> typst
gamma_1 equiv gamma_2 arrow.l.r.double {gamma_1 (0) = gamma_2 (0) = p , upright(" and ")\
gamma_1 equiv gamma_2 arrow.l.r.double {gamma_1 (0) = gamma_2 (0) = p \, upright(" and ")\
frac(upright(d), upright(d) t) phi.alt circle.stroked.tiny gamma_1 (t)\|_(t = 0) = frac(upright(d), upright(d) t) phi.alt circle.stroked.tiny gamma_2 (t)\|_(t = 0)
2 changes: 1 addition & 1 deletion test/writer/typst/sphere_volume.test
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
]
]
>>> typst
S = { 0 lt.eq phi.alt lt.eq 2 pi , med 0 lt.eq theta lt.eq pi , med 0 lt.eq rho lt.eq R } upright(V o l u m e) & = integral.triple_S #h(-1em) rho^2 sin theta thin upright(d) rho thin upright(d) theta thin upright(d) phi.alt\
S = { 0 lt.eq phi.alt lt.eq 2 pi \, med 0 lt.eq theta lt.eq pi \, med 0 lt.eq rho lt.eq R } upright(V o l u m e) & = integral.triple_S #h(-1em) rho^2 sin theta thin upright(d) rho thin upright(d) theta thin upright(d) phi.alt\
& = integral_0^(2 pi) #h(-1em) upright(d) phi.alt thin integral_0^pi #h(-1em) sin theta thin upright(d) theta thin integral_0^R #h(-1em) rho^2 upright(d) rho\
& = phi.alt #scale(x: 180%, y: 180%)[\|]_0^(2 pi) med (- cos theta) #scale(x: 180%, y: 180%)[\|]_0^pi med 1 / 3 rho^3 #scale(x: 180%, y: 180%)[\|]_0^R\
& = 2 pi times 2 times 1 / 3 R^3\
Expand Down
2 changes: 1 addition & 1 deletion test/writer/typst/substack.test
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
]
>>> typst
sum_(0 < i < m\
0 < j < n) P (i , j)
0 < j < n) P (i \, j)

0 comments on commit 1703b41

Please sign in to comment.