Skip to content

Commit 7099b90

Browse files
committed
Typst writer: improve rendering of EDelimited.
Together with earlier commits, closes #238.
1 parent 61a7045 commit 7099b90

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

Diff for: src/Text/TeXMath/Writers/Typst.hs

+15-6
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,24 @@ writeExp (EDelimited op "" [Right (EArray [AlignLeft, AlignLeft] rows)]) =
247247
writeExp (EDelimited open close es) =
248248
if isDelim open && isDelim close
249249
then
250-
if matchedPair open close && -- see #233
250+
(if matchedPair open close && -- see #233
251251
not (any (\x -> x == Left open || x == Left close) es)
252-
then open <> body <> close
253-
else "lr" <> inParens (open <> body <> close)
252+
then id
253+
else ("lr" <>) . inParens)
254+
(renderOpen open <> body <> renderClose close)
254255
else esc open <> body <> esc close
255-
where fromDelimited (Left e) =
256-
"mid(" <> fromMaybe (esc e) (M.lookup e typstSymbolMap) <> ")"
256+
where fromDelimited (Left e) = "mid(" <> renderSymbol e <> ")"
257257
fromDelimited (Right e) = writeExp e
258-
isDelim c = c `elem` ["(",")","[","]","{","}","|","||"]
258+
isDelim c = c `elem` ["(",")","[","]","{","}","|","||","\x2016"]
259+
renderOpen e =
260+
if T.all isAscii e
261+
then e
262+
else renderSymbol e <> " "
263+
renderClose e =
264+
if T.all isAscii e
265+
then e
266+
else " " <> renderSymbol e
267+
renderSymbol e = fromMaybe (esc e) (M.lookup e typstSymbolMap)
259268
matchedPair "(" ")" = True
260269
matchedPair "[" "]" = True
261270
matchedPair "{" "}" = True

Diff for: test/regression/238.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<<< tex
22
\left\{ x \in \mathbb{R}^n \middle| \lVert x \rVert_2^2 = \sum_{i=1}^n x_i^2 = 1\right\}
33
>>> typst
4-
{x in bb(R)^n mid(bar.v) parallel x parallel_2^2 = sum_(i = 1)^n x_i^2 = 1}
4+
{x in bb(R)^n mid(bar.v) lr(bar.v.double x bar.v.double)_2^2 = sum_(i = 1)^n x_i^2 = 1}

0 commit comments

Comments
 (0)