aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <[email protected]>2023-07-01 13:04:58 -0700
committerJohn MacFarlane <[email protected]>2023-07-01 13:04:58 -0700
commit358c08c565f850c10b41e42943f58b20b5f81d85 (patch)
treea3661b76737dac6d54324da3b9af696a7fe12083 /src/Text
parente634d8b87d9fb877658583b03418c23748b70dc5 (diff)
Typst writer: some math improvements.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/Typst/Math.hs30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Readers/Typst/Math.hs b/src/Text/Pandoc/Readers/Typst/Math.hs
index 8256843c1..e1c584675 100644
--- a/src/Text/Pandoc/Readers/Typst/Math.hs
+++ b/src/Text/Pandoc/Readers/Typst/Math.hs
@@ -37,15 +37,24 @@ withGroup :: [Exp] -> Exp
withGroup [x] = x
withGroup xs = EGrouped xs
-data AttachmentStyle = Limits | Scripts
+data AttachmentStyle = Limits | LimitsDisplay | Scripts
deriving (Eq, Show)
getAttachmentStyle :: PandocMonad m => M.Map Identifier Val -> P m (Maybe AttachmentStyle)
getAttachmentStyle fields = do
(base :: Seq Content) <- getField "base" fields
case base of
- [Elt "limits" _ _] -> pure $ Just Limits
- [Elt "scripts" _ _] -> pure $ Just Scripts
+ [Elt "math.op" _ fs] -> do
+ limits <- getField "limits" fs
+ if limits == VBoolean True
+ then pure $ Just Limits
+ else pure Nothing
+ [Elt "math.limits" _ fs] -> do
+ inl <- getField "inline" fs
+ if inl == VBoolean False
+ then pure $ Just LimitsDisplay
+ else pure $ Just Limits
+ [Elt "math.scripts" _ _] -> pure $ Just Scripts
_ -> pure Nothing
pMath :: PandocMonad m => P m Exp
@@ -86,7 +95,6 @@ handleMath tok =
_ -> acc
pure $ EOver False base acc'
Elt "math.attach" _ fields -> do
- attachmentStyle <- getAttachmentStyle fields
base <- getField "base" fields >>= pMathGrouped
t' <- getField "t" fields
b' <- getField "b" fields
@@ -94,7 +102,12 @@ handleMath tok =
tl' <- getField "tl" fields
br' <- getField "br" fields
bl' <- getField "bl" fields
- let limits = attachmentStyle == Just Limits
+ attachmentStyle <- getAttachmentStyle fields
+ let limits = case attachmentStyle of
+ Just Limits -> True
+ Just LimitsDisplay -> True
+ _ -> False
+ let convertible = attachmentStyle == Just LimitsDisplay
let (mbt, mbtr) =
case (t', tr') of
(Just top, Just topright) -> (Just top, Just topright)
@@ -133,9 +146,10 @@ handleMath tok =
suffix <- case (mbt, mbb) of
(Nothing, Nothing) -> pure base'
- (Nothing, Just bot) -> EUnder False base' <$> pMathGrouped bot
- (Just top, Nothing) -> EOver False base' <$> pMathGrouped top
- (Just top, Just bot) -> EUnderover False base' <$> pMathGrouped bot <*> pMathGrouped top
+ (Nothing, Just bot) -> EUnder convertible base' <$> pMathGrouped bot
+ (Just top, Nothing) -> EOver convertible base' <$> pMathGrouped top
+ (Just top, Just bot) -> EUnderover convertible base'
+ <$> pMathGrouped bot <*> pMathGrouped top
addPrefix suffix
Elt "math.serif" _ fields ->