Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions src/Text/Pandoc/Writers/Typst.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import Text.Pandoc.Logging (LogMessage(..))
import qualified Text.Pandoc.UTF8 as UTF8
import Text.Collate.Lang (Lang(..), parseLang)
import Text.Printf (printf)
import Data.Char (isDigit)
import Data.Char (isAlphaNum, isDigit)
import Data.Maybe (fromMaybe)
import Unicode.Char (isXIDContinue)
import qualified Data.ByteString as B
Expand Down Expand Up @@ -434,6 +434,36 @@ isSpacey SoftBreak = True
isSpacey LineBreak = True
isSpacey _ = False

normalizeDeprecatedMathSymbolNames :: Text -> Text
normalizeDeprecatedMathSymbolNames = go False
where
go inString txt
| T.null txt = ""
| inString =
case T.uncons txt of
Just ('\\', rest) ->
case T.uncons rest of
Just (c, rest') -> T.pack ['\\', c] <> go True rest'
Nothing -> "\\"
Just ('"', rest) -> "\"" <> go False rest
Just (c, rest) -> T.singleton c <> go True rest
Nothing -> ""
| otherwise =
case T.uncons txt of
Just ('"', rest) -> "\"" <> go True rest
Just (c, rest)
| isMathNameChar c ->
let (name, rest') = T.span isMathNameChar txt
in normalize name <> go False rest'
| otherwise -> T.singleton c <> go False rest
Nothing -> ""

normalize "sect.big" = "inter.big"
normalize "sect" = "inter"
normalize x = x

isMathNameChar c = isAlphaNum c || c == '.'

inlineToTypst :: PandocMonad m => Inline -> TW m (Doc Text)
inlineToTypst inline =
case inline of
Expand All @@ -454,12 +484,13 @@ inlineToTypst inline =
case res of
Left il -> inlineToTypst il
Right r ->
let r' = normalizeDeprecatedMathSymbolNames r in
(case extractLabel str of -- #10805
Nothing -> id
Just lab -> (<> (toLabel FreestandingLabel lab))) <$>
case mathType of
InlineMath -> return $ "$" <> literal r <> "$"
DisplayMath -> return $ "$ " <> literal r <> " $"
InlineMath -> return $ "$" <> literal r' <> "$"
DisplayMath -> return $ "$ " <> literal r' <> " $"
Code (ident,cls,kvs) code -> do
opts <- gets stOptions
let defaultHighlightedCode =
Expand Down
13 changes: 13 additions & 0 deletions test/command/typst-math-intersection.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
```
% pandoc -f latex -t typst
$\cap$
^D
$inter$
```

```
% pandoc -f latex -t typst
$$\bigcap_{i=1}^n A_i$$
^D
$ inter.big_(i = 1)^n A_i $
```