From fb5499d7af1654bdcb93247950d72baffa562d98 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 25 Apr 2025 22:39:14 -0700 Subject: Typst writer: add equation label if math contains `\label{..}`. Closes #10805. --- src/Text/Pandoc/Writers/Typst.hs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src') 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 -- cgit v1.2.3