@@ -68,7 +68,9 @@ module Text.Pandoc.Parsing ( (>>~),
70 lookupKeySrc,
70 lookupKeySrc,
71− smartPunctuation )
71+ smartPunctuation,
74import Text.Pandoc.Definition
76import Text.Pandoc.Definition
@@ -82,7 +84,7 @@ import Network.URI ( parseURI, URI (..), isAllowedInURI )
82import Control.Monad ( join, liftM, guard )
84import Control.Monad ( join, liftM, guard )
83import Text.Pandoc.Shared
85import Text.Pandoc.Shared
84import qualified Data.Map as M
86import qualified Data.Map as M
85−import Text.TeXMath.Macros (Macro)
87+import Text.TeXMath.Macros (applyMacros, Macro, pMacroDefinition)
87-- | Like >>, but returns the operation on the left.
89-- | Like >>, but returns the operation on the left.
88-- (Suggested by Tillmann Rendel on Haskell-cafe list.)
90-- (Suggested by Tillmann Rendel on Haskell-cafe list.)
@@ -781,3 +783,26 @@ emDash = do
781 try (charOrRef "—") <|> (oneOfStrings ["---", "--"] >> return '—')
783 try (charOrRef "—") <|> (oneOfStrings ["---", "--"] >> return '—')
782 return EmDash
784 return EmDash
790+-- | Parse a \newcommand or \renewcommand macro definition.
791+macro :: GenParser Char ParserState Block
792+macro = getState >>= guard . stateApplyMacros >>
793+ pMacroDefinition >>= addMacro >> blanklines >> return Null
795+-- | Add a macro to the list of macros in state.
796+addMacro :: Macro -> GenParser Char ParserState ()
798+ updateState $ \st -> st{ stateMacros = m : stateMacros st }
800+-- | Apply current macros to string.
801+applyMacros' :: String -> GenParser Char ParserState String
802+applyMacros' target = do
803+ apply <- liftM stateApplyMacros getState
805+ then do macros <- liftM stateMacros getState
806+ return $ applyMacros macros target