Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Text/TeXMath/Writers/Typst.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,24 @@ writeExps = go . map writeExp
where
go (a : b : es)
| Just (bstart, _) <- T.uncons b
, Just (astart, _) <- T.uncons a
, Just (_, aend) <- T.unsnoc a
, bstart == '\'' -- avoid space before a prime #239
|| bstart == '|' || aend == '|' || bstart == '\\' || astart == '\\' -- #286
|| bstart == '|' || aend == '|'
|| bstart == '\\' || isStandaloneEscape a -- #291, #286
= a <> go (b:es)
go (a : as)
= a <> if null as
then mempty
else " " <> go as
go [] = mempty

-- A compound expression may start with an escape but end in an identifier.
-- Only a standalone escape suppresses the following space (#291).
isStandaloneEscape t =
case T.uncons t of
Just ('\\', rest) -> T.length rest == 1
_ -> False

inParens :: Text -> Text
inParens s = "(" <> s <> ")"

Expand Down
6 changes: 6 additions & 0 deletions test/regression/291.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<<< tex
)^n k \qquad
(\mathbf x)^\top\mathbf A \qquad
\mathcal G=\langle\mathcal N,(\mathcal A_i)_i,(u_i)_i\rangle
>>> typst
\)^n k #h(2em)\(upright(bold(x))\)^top upright(bold(A)) #h(2em) cal(G) = chevron.l cal(N)\,\(cal(A)_i\)_i\,\(u_i\)_i chevron.r