Skip to content

Commit fb5499d

Browse files
committed
Typst writer: add equation label if math contains \label{..}.
Closes #10805.
1 parent a32a9ff commit fb5499d

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/Text/Pandoc/Writers/Typst.hs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,12 @@ inlineToTypst inline =
384384
case res of
385385
Left il -> inlineToTypst il
386386
Right r ->
387-
case mathType of
388-
InlineMath -> return $ "$" <> literal r <> "$"
389-
DisplayMath -> return $ "$ " <> literal r <> " $"
387+
(case extractLabel str of -- #10805
388+
Nothing -> id
389+
Just lab -> (<> ("<" <> literal lab <> ">"))) <$>
390+
case mathType of
391+
InlineMath -> return $ "$" <> literal r <> "$"
392+
DisplayMath -> return $ "$ " <> literal r <> " $"
390393
Code (_,cls,_) code -> return $
391394
case cls of
392395
(lang:_) -> "#raw(lang:" <> doubleQuoted lang <>
@@ -605,3 +608,10 @@ doubleQuoted = doubleQuotes . literal . escape
605608

606609
endCode :: Doc Text
607610
endCode = beforeNonBlank ";"
611+
612+
extractLabel :: Text -> Maybe Text
613+
extractLabel = go . T.unpack
614+
where
615+
go [] = Nothing
616+
go ('\\':'l':'a':'b':'e':'l':'{':xs) = Just (T.pack (takeWhile (/='}') xs))
617+
go (_:xs) = go xs

test/command/10805.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```
2+
% pandoc -t typst -f latex
3+
\begin{equation}
4+
\label{eq:U}
5+
U = A
6+
\end{equation}
7+
^D
8+
$ U = A $<eq:U>
9+
```

0 commit comments

Comments
 (0)