git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: SUpport ams `\theoremstyle`.
ff0e130John MacFarlane
src/Text/Pandoc/Readers/LaTeX.hs+28−6
@@ -1725,6 +1725,7 @@ blockCommands = M.fromList
1725 , ("signature", mempty <$ (skipopts *> authors))
1725 , ("signature", mempty <$ (skipopts *> authors))
1726 , ("date", mempty <$ (skipopts *> tok >>= addMeta "date"))
1726 , ("date", mempty <$ (skipopts *> tok >>= addMeta "date"))
1727 , ("newtheorem", newtheorem)
1727 , ("newtheorem", newtheorem)
1728+ , ("theoremstyle", theoremstyle)
1728 -- KOMA-Script metadata commands
1729 -- KOMA-Script metadata commands
1729 , ("extratitle", mempty <$ (skipopts *> tok >>= addMeta "extratitle"))
1730 , ("extratitle", mempty <$ (skipopts *> tok >>= addMeta "extratitle"))
1730 , ("frontispiece", mempty <$ (skipopts *> tok >>= addMeta "frontispiece"))
1731 , ("frontispiece", mempty <$ (skipopts *> tok >>= addMeta "frontispiece"))
@@ -1857,6 +1858,19 @@ environments = M.fromList
1857 , ("iftoggle", try $ ifToggle >> block)
1858 , ("iftoggle", try $ ifToggle >> block)
1858 ]
1859 ]
1859
1860
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+
1860newtheorem :: PandocMonad m => LP m Blocks
1874newtheorem :: PandocMonad m => LP m Blocks
1861newtheorem = do
1875newtheorem = do
1862 number <- option True (False <$ symbol '*' <* sp)
1876 number <- option True (False <$ symbol '*' <* sp)
@@ -1867,7 +1881,9 @@ newtheorem = do
1867 showName <- untokenize <$> braced
1881 showName <- untokenize <$> braced
1868 sp
1882 sp
1869 syncTo <- option Nothing $ Just . untokenize <$> bracketedToks
1883 syncTo <- option Nothing $ Just . untokenize <$> bracketedToks
1884+ sty <- sLastTheoremStyle <$> getState
1870 let spec = TheoremSpec { theoremName = showName
1885 let spec = TheoremSpec { theoremName = showName
1886+ , theoremStyle = sty
1871 , theoremSeries = series
1887 , theoremSeries = series
1872 , theoremSyncTo = syncTo
1888 , theoremSyncTo = syncTo
1873 , theoremNumber = number
1889 , theoremNumber = number
@@ -1906,14 +1922,14 @@ environment = try $ do
1906 controlSeq "begin"
1922 controlSeq "begin"
1907 name <- untokenize <$> braced
1923 name <- untokenize <$> braced
1908 M.findWithDefault mzero name environments <|>
1924 M.findWithDefault mzero name environments <|>
1909− lookupTheoremEnvironment name <|>
1925+ theoremEnvironment name <|>
1910 if M.member name (inlineEnvironments
1926 if M.member name (inlineEnvironments
1911 :: M.Map Text (LP PandocPure Inlines))
1927 :: M.Map Text (LP PandocPure Inlines))
1912 then mzero
1928 then mzero
1913 else try (rawEnv name) <|> rawVerbEnv name
1929 else try (rawEnv name) <|> rawVerbEnv name
1914
1930
1915−lookupTheoremEnvironment :: PandocMonad m => Text -> LP m Blocks
1931+theoremEnvironment :: PandocMonad m => Text -> LP m Blocks
1916−lookupTheoremEnvironment name = do
1932+theoremEnvironment name = do
1917 tmap <- sTheoremMap <$> getState
1933 tmap <- sTheoremMap <$> getState
1918 case M.lookup name tmap of
1934 case M.lookup name tmap of
1919 Nothing -> mzero
1935 Nothing -> mzero
@@ -1947,10 +1963,16 @@ lookupTheoremEnvironment name = do
1947 Nothing -> return ()
1963 Nothing -> return ()
1948 return $ space <> B.text (renderDottedNum num)
1964 return $ space <> B.text (renderDottedNum num)
1949 else return mempty
1965 else return mempty
1966+ let titleEmph = case theoremStyle tspec of
1967+ PlainStyle -> B.strong
1968+ DefinitionStyle -> B.strong
1969+ RemarkStyle -> B.emph
1950− let title = B.strong (B.text (theoremName tspec) <> number)
1970+ let title = titleEmph (B.text (theoremName tspec) <> number)
1951 <> optTitle <> space
1971 <> optTitle <> space
1952− return $ divWith ("", [name], []) $ addTitle title $
1972+ return $ divWith ("", [name], []) $ addTitle title
1973+ $ case theoremStyle tspec of
1953− walk italicize bs
1974+ PlainStyle -> walk italicize bs
1975+ _ -> bs
1954
1976
1955italicize :: Block -> Block
1977italicize :: Block -> Block
1956italicize (Para ils) = Para [Emph ils]
1978italicize (Para ils) = Para [Emph ils]
src/Text/Pandoc/Readers/LaTeX/Parsing.hs+10−2
@@ -19,6 +19,7 @@ module Text.Pandoc.Readers.LaTeX.Parsing
19 , renderDottedNum
19 , renderDottedNum
20 , incrementDottedNum
20 , incrementDottedNum
21 , TheoremSpec(..)
21 , TheoremSpec(..)
22+ , TheoremStyle(..)
22 , LaTeXState(..)
23 , LaTeXState(..)
23 , defaultLaTeXState
24 , defaultLaTeXState
24 , LP
25 , LP
@@ -103,7 +104,7 @@ import Text.Parsec.Pos
103-- import Debug.Trace
104-- import Debug.Trace
104
105
105newtype DottedNum = DottedNum [Int]
106newtype DottedNum = DottedNum [Int]
106− deriving (Show)
107+ deriving (Show, Eq)
107
108
108renderDottedNum :: DottedNum -> T.Text
109renderDottedNum :: DottedNum -> T.Text
109renderDottedNum (DottedNum xs) = T.pack $
110renderDottedNum (DottedNum xs) = T.pack $
@@ -115,14 +116,19 @@ incrementDottedNum level (DottedNum ns) = DottedNum $
115 (x:xs) -> reverse (x+1 : xs)
116 (x:xs) -> reverse (x+1 : xs)
116 [] -> [] -- shouldn't happen
117 [] -> [] -- shouldn't happen
117
118
119+data TheoremStyle =
120+ PlainStyle | DefinitionStyle | RemarkStyle
121+ deriving (Show, Eq)
122+
118data TheoremSpec =
123data TheoremSpec =
119 TheoremSpec
124 TheoremSpec
120 { theoremName :: Text
125 { theoremName :: Text
126+ , theoremStyle :: TheoremStyle
121 , theoremSeries :: Maybe Text
127 , theoremSeries :: Maybe Text
122 , theoremSyncTo :: Maybe Text
128 , theoremSyncTo :: Maybe Text
123 , theoremNumber :: Bool
129 , theoremNumber :: Bool
124 , theoremLastNum :: DottedNum }
130 , theoremLastNum :: DottedNum }
125− deriving (Show)
131+ deriving (Show, Eq)
126
132
127data LaTeXState = LaTeXState{ sOptions :: ReaderOptions
133data LaTeXState = LaTeXState{ sOptions :: ReaderOptions
128 , sMeta :: Meta
134 , sMeta :: Meta
@@ -139,6 +145,7 @@ data LaTeXState = LaTeXState{ sOptions :: ReaderOptions
139 , sLastFigureNum :: DottedNum
145 , sLastFigureNum :: DottedNum
140 , sLastTableNum :: DottedNum
146 , sLastTableNum :: DottedNum
141 , sTheoremMap :: M.Map Text TheoremSpec
147 , sTheoremMap :: M.Map Text TheoremSpec
148+ , sLastTheoremStyle :: TheoremStyle
142 , sLastLabel :: Maybe Text
149 , sLastLabel :: Maybe Text
143 , sLabels :: M.Map Text [Inline]
150 , sLabels :: M.Map Text [Inline]
144 , sHasChapters :: Bool
151 , sHasChapters :: Bool
@@ -163,6 +170,7 @@ defaultLaTeXState = LaTeXState{ sOptions = def
163 , sLastFigureNum = DottedNum []
170 , sLastFigureNum = DottedNum []
164 , sLastTableNum = DottedNum []
171 , sLastTableNum = DottedNum []
165 , sTheoremMap = M.empty
172 , sTheoremMap = M.empty
173+ , sLastTheoremStyle = PlainStyle
166 , sLastLabel = Nothing
174 , sLastLabel = Nothing
167 , sLabels = M.empty
175 , sLabels = M.empty
168 , sHasChapters = False
176 , sHasChapters = False