Skip to content

Commit

Permalink
Typst writer: escape backslash in text context.
Browse files Browse the repository at this point in the history
See #245.
  • Loading branch information
jgm committed Jan 4, 2025
1 parent e8b92aa commit 430f1dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Text/TeXMath/Writers/Typst.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@ esc t =

escInQuotes :: Text -> Text
escInQuotes t =
if T.any (== '"') t
if T.any needsEscape t
then T.concatMap escapeChar t
else t
where
escapeChar c
| c == '"' = "\\" <> T.singleton c
| needsEscape c = "\\" <> T.singleton c
| otherwise = T.singleton c
needsEscape c = c == '\\' || c == '"'

writeExpS :: Exp -> Text
writeExpS (EGrouped es) = "(" <> writeExps es <> ")"
Expand Down
4 changes: 4 additions & 0 deletions test/regression/245a.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<<< native
[ EText TextNormal "\\tau" ]
>>> typst
upright("\\tau")

0 comments on commit 430f1dc

Please sign in to comment.