Skip to content

Commit 430f1dc

Browse files
committed
Typst writer: escape backslash in text context.
See #245.
1 parent e8b92aa commit 430f1dc

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

src/Text/TeXMath/Writers/Typst.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,14 @@ esc t =
8484

8585
escInQuotes :: Text -> Text
8686
escInQuotes t =
87-
if T.any (== '"') t
87+
if T.any needsEscape t
8888
then T.concatMap escapeChar t
8989
else t
9090
where
9191
escapeChar c
92-
| c == '"' = "\\" <> T.singleton c
92+
| needsEscape c = "\\" <> T.singleton c
9393
| otherwise = T.singleton c
94+
needsEscape c = c == '\\' || c == '"'
9495

9596
writeExpS :: Exp -> Text
9697
writeExpS (EGrouped es) = "(" <> writeExps es <> ")"

test/regression/245a.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<<< native
2+
[ EText TextNormal "\\tau" ]
3+
>>> typst
4+
upright("\\tau")

0 commit comments

Comments
 (0)