diff options
| author | John MacFarlane <[email protected]> | 2025-04-25 22:39:14 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2025-04-25 22:39:56 -0700 |
| commit | fb5499d7af1654bdcb93247950d72baffa562d98 (patch) | |
| tree | 849e46cad628b8dfe9c21cd8266ed1c134858e05 /src | |
| parent | a32a9ff7e9683220828e5c86eeb7a6cdde462581 (diff) | |
Typst writer: add equation label if math contains `\label{..}`.
Closes #10805.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Text/Pandoc/Writers/Typst.hs | 16 |
1 files changed, 13 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 |
