@@ -46,7 +46,8 @@ import Text.Pandoc.Readers.HTML ( rawHtmlBlock, anyHtmlBlockTag,
46 htmlBlockElement, htmlComment, unsanitaryURI )
46 htmlBlockElement, htmlComment, unsanitaryURI )
47import Text.Pandoc.CharacterReferences ( decodeCharacterReferences )
47import Text.Pandoc.CharacterReferences ( decodeCharacterReferences )
48import Text.ParserCombinators.Parsec
48import Text.ParserCombinators.Parsec
49−import Control.Monad (when, liftM, unless)
49+import Control.Monad (when, liftM, unless, guard)
50+import Text.TeXMath.Macros (applyMacros, Macro, pMacroDefinition)
51-- | Read markdown from an input string and return a Pandoc document.
52-- | Read markdown from an input string and return a Pandoc document.
52readMarkdown :: ParserState -- ^ Parser state, including options for parser
53readMarkdown :: ParserState -- ^ Parser state, including options for parser
@@ -284,6 +285,7 @@ block = do
285 , nullBlock ]
286 , nullBlock ]
286 else [ codeBlockDelimited
287 else [ codeBlockDelimited
287 , header
289 , header
289 , codeBlockIndented
291 , codeBlockIndented
@@ -867,6 +869,29 @@ table = multilineTable False <|> simpleTable True <|>
867 simpleTable False <|> multilineTable True <|>
869 simpleTable False <|> multilineTable True <|>
868 gridTable False <|> gridTable True <?> "table"
870 gridTable False <|> gridTable True <?> "table"
876+-- | Parse a \newcommand or \renewcommand macro definition.
877+macro :: GenParser Char ParserState Block
878+macro = getState >>= guard . stateApplyMacros >>
879+ pMacroDefinition >>= addMacro >> return Null
881+-- | Add a macro to the list of macros in state.
882+addMacro :: Macro -> GenParser Char ParserState ()
884+ updateState $ \st -> st{ stateMacros = m : stateMacros st }
886+-- | Apply current macros to string.
887+applyMacros' :: String -> GenParser Char ParserState String
888+applyMacros' target = do
889+ apply <- liftM stateApplyMacros getState
891+ then do macros <- liftM stateMacros getState
892+ return $ applyMacros macros target
@@ -969,8 +994,8 @@ mathChunk = do char '\\'
969 <|> many1 (noneOf " \t\n\\$")
994 <|> many1 (noneOf " \t\n\\$")
971math :: GenParser Char ParserState Inline
996math :: GenParser Char ParserState Inline
972−math = (mathDisplay >>= return . Math DisplayMath)
997+math = (mathDisplay >>= applyMacros' >>= return . Math DisplayMath)
973− <|> (mathInline >>= return . Math InlineMath)
998+ <|> (mathInline >>= applyMacros' >>= return . Math InlineMath)
975mathDisplay :: GenParser Char ParserState String
1000mathDisplay :: GenParser Char ParserState String
976mathDisplay = try $ do
1001mathDisplay = try $ do