git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: SUpport ams `\theoremstyle`.
commitff0e130560e32d23ead14bca7af821a80acc3318 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 22 Jul 2020, 23:52 (6 years ago) parentcdaaaa3
2 files changed+38−8
src/Text/Pandoc/Readers/LaTeX.hs+28−6 src/Text/Pandoc/Readers/LaTeX/Parsing.hs+10−2
src/Text/Pandoc/Readers/LaTeX.hs+28−6
@@ -1725,6 +1725,7 @@ blockCommands = M.fromList
17251725 , ("signature", mempty <$ (skipopts *> authors))
17261726 , ("date", mempty <$ (skipopts *> tok >>= addMeta "date"))
17271727 , ("newtheorem", newtheorem)
1728+ , ("theoremstyle", theoremstyle)
17281729 -- KOMA-Script metadata commands
17291730 , ("extratitle", mempty <$ (skipopts *> tok >>= addMeta "extratitle"))
17301731 , ("frontispiece", mempty <$ (skipopts *> tok >>= addMeta "frontispiece"))
@@ -1857,6 +1858,19 @@ environments = M.fromList
18571858 , ("iftoggle", try $ ifToggle >> block)
18581859 ]
18591860
1861+theoremstyle :: PandocMonad m => LP m Blocks
1862+theoremstyle = do
1863+ stylename <- untokenize <$> braced
1864+ let mbstyle = case stylename of
1865+ "plain" -> Just PlainStyle
1866+ "definition" -> Just DefinitionStyle
1867+ "remark" -> Just RemarkStyle
1868+ _ -> Nothing
1869+ case mbstyle of
1870+ Nothing -> return ()
1871+ Just sty -> updateState $ \s -> s{ sLastTheoremStyle = sty }
1872+ return mempty
1873+
18601874newtheorem :: PandocMonad m => LP m Blocks
18611875newtheorem = do
18621876 number <- option True (False <$ symbol '*' <* sp)
@@ -1867,7 +1881,9 @@ newtheorem = do
18671881 showName <- untokenize <$> braced
18681882 sp
18691883 syncTo <- option Nothing $ Just . untokenize <$> bracketedToks
1884+ sty <- sLastTheoremStyle <$> getState
18701885 let spec = TheoremSpec { theoremName = showName
1886+ , theoremStyle = sty
18711887 , theoremSeries = series
18721888 , theoremSyncTo = syncTo
18731889 , theoremNumber = number
@@ -1906,14 +1922,14 @@ environment = try $ do
19061922 controlSeq "begin"
19071923 name <- untokenize <$> braced
19081924 M.findWithDefault mzero name environments <|>
1909− lookupTheoremEnvironment name <|>
1925+ theoremEnvironment name <|>
19101926 if M.member name (inlineEnvironments
19111927 :: M.Map Text (LP PandocPure Inlines))
19121928 then mzero
19131929 else try (rawEnv name) <|> rawVerbEnv name
19141930
1915−lookupTheoremEnvironment :: PandocMonad m => Text -> LP m Blocks
1916−lookupTheoremEnvironment name = do
1931+theoremEnvironment :: PandocMonad m => Text -> LP m Blocks
1932+theoremEnvironment name = do
19171933 tmap <- sTheoremMap <$> getState
19181934 case M.lookup name tmap of
19191935 Nothing -> mzero
@@ -1947,10 +1963,16 @@ lookupTheoremEnvironment name = do
19471963 Nothing -> return ()
19481964 return $ space <> B.text (renderDottedNum num)
19491965 else return mempty
1950− let title = B.strong (B.text (theoremName tspec) <> number)
1966+ let titleEmph = case theoremStyle tspec of
1967+ PlainStyle -> B.strong
1968+ DefinitionStyle -> B.strong
1969+ RemarkStyle -> B.emph
1970+ let title = titleEmph (B.text (theoremName tspec) <> number)
19511971 <> optTitle <> space
1952− return $ divWith ("", [name], []) $ addTitle title $
1953− walk italicize bs
1972+ return $ divWith ("", [name], []) $ addTitle title
1973+ $ case theoremStyle tspec of
1974+ PlainStyle -> walk italicize bs
1975+ _ -> bs
19541976
19551977italicize :: Block -> Block
19561978italicize (Para ils) = Para [Emph ils]
src/Text/Pandoc/Readers/LaTeX/Parsing.hs+10−2
@@ -19,6 +19,7 @@ module Text.Pandoc.Readers.LaTeX.Parsing
1919 , renderDottedNum
2020 , incrementDottedNum
2121 , TheoremSpec(..)
22+ , TheoremStyle(..)
2223 , LaTeXState(..)
2324 , defaultLaTeXState
2425 , LP
@@ -103,7 +104,7 @@ import Text.Parsec.Pos
103104-- import Debug.Trace
104105
105106newtype DottedNum = DottedNum [Int]
106− deriving (Show)
107+ deriving (Show, Eq)
107108
108109renderDottedNum :: DottedNum -> T.Text
109110renderDottedNum (DottedNum xs) = T.pack $
@@ -115,14 +116,19 @@ incrementDottedNum level (DottedNum ns) = DottedNum $
115116 (x:xs) -> reverse (x+1 : xs)
116117 [] -> [] -- shouldn't happen
117118
119+data TheoremStyle =
120+ PlainStyle | DefinitionStyle | RemarkStyle
121+ deriving (Show, Eq)
122+
118123data TheoremSpec =
119124 TheoremSpec
120125 { theoremName :: Text
126+ , theoremStyle :: TheoremStyle
121127 , theoremSeries :: Maybe Text
122128 , theoremSyncTo :: Maybe Text
123129 , theoremNumber :: Bool
124130 , theoremLastNum :: DottedNum }
125− deriving (Show)
131+ deriving (Show, Eq)
126132
127133data LaTeXState = LaTeXState{ sOptions :: ReaderOptions
128134 , sMeta :: Meta
@@ -139,6 +145,7 @@ data LaTeXState = LaTeXState{ sOptions :: ReaderOptions
139145 , sLastFigureNum :: DottedNum
140146 , sLastTableNum :: DottedNum
141147 , sTheoremMap :: M.Map Text TheoremSpec
148+ , sLastTheoremStyle :: TheoremStyle
142149 , sLastLabel :: Maybe Text
143150 , sLabels :: M.Map Text [Inline]
144151 , sHasChapters :: Bool
@@ -163,6 +170,7 @@ defaultLaTeXState = LaTeXState{ sOptions = def
163170 , sLastFigureNum = DottedNum []
164171 , sLastTableNum = DottedNum []
165172 , sTheoremMap = M.empty
173+ , sLastTheoremStyle = PlainStyle
166174 , sLastLabel = Nothing
167175 , sLabels = M.empty
168176 , sHasChapters = False