diff options
| -rw-r--r-- | src/Text/Pandoc/Writers/Typst.hs | 16 | ||||
| -rw-r--r-- | test/command/10805.md | 9 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Writers/Typst.hs b/src/Text/Pandoc/Writers/Typst.hs index 767772521..d18b0fde3 100644 --- a/src/Text/Pandoc/Writers/Typst.hs +++ b/src/Text/Pandoc/Writers/Typst.hs @@ -384,9 +384,12 @@ inlineToTypst inline = case res of Left il -> inlineToTypst il Right r -> - case mathType of - InlineMath -> return $ "$" <> literal r <> "$" - DisplayMath -> return $ "$ " <> literal r <> " $" + (case extractLabel str of -- #10805 + Nothing -> id + Just lab -> (<> ("<" <> literal lab <> ">"))) <$> + case mathType of + InlineMath -> return $ "$" <> literal r <> "$" + DisplayMath -> return $ "$ " <> literal r <> " $" Code (_,cls,_) code -> return $ case cls of (lang:_) -> "#raw(lang:" <> doubleQuoted lang <> @@ -605,3 +608,10 @@ doubleQuoted = doubleQuotes . literal . escape endCode :: Doc Text endCode = beforeNonBlank ";" + +extractLabel :: Text -> Maybe Text +extractLabel = go . T.unpack + where + go [] = Nothing + go ('\\':'l':'a':'b':'e':'l':'{':xs) = Just (T.pack (takeWhile (/='}') xs)) + go (_:xs) = go xs diff --git a/test/command/10805.md b/test/command/10805.md new file mode 100644 index 000000000..e3d02bc51 --- /dev/null +++ b/test/command/10805.md @@ -0,0 +1,9 @@ +``` +% pandoc -t typst -f latex +\begin{equation} + \label{eq:U} + U = A +\end{equation} +^D +$ U = A $<eq:U> +``` |
