From 6e36375bdcf8875091e3716e951ebd5a2efc8f44 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Wed, 12 Dec 2012 19:28:33 -0800 Subject: LaTeX reader: Make command macros work everywhere, including non-math. Environment macros still not supported. --- src/Text/Pandoc/Readers/LaTeX.hs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index db148617e..8848be028 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -204,7 +204,7 @@ block :: LP Blocks block = (mempty <$ comment) <|> (mempty <$ ((spaceChar <|> newline) *> spaces)) <|> environment - <|> mempty <$ macro -- TODO improve macros, make them work everywhere + <|> mempty <$ macro <|> blockCommand <|> paragraph <|> grouped block @@ -327,11 +327,15 @@ inlineCommand = try $ do parseRaw <- getOption readerParseRaw star <- option "" (string "*") let name' = name ++ star - let rawargs = withRaw (skipopts *> option "" dimenarg - *> many braced) >>= applyMacros' . snd - let raw = if parseRaw - then (rawInline "latex" . (('\\':name') ++)) <$> rawargs - else mempty <$> rawargs + let raw = do + rawargs <- withRaw (skipopts *> option "" dimenarg *> many braced) + let rawcommand = '\\' : name ++ star ++ snd rawargs + transformed <- applyMacros' rawcommand + if transformed /= rawcommand + then parseFromString inlines transformed + else if parseRaw + then return $ rawInline "latex" rawcommand + else return mempty case M.lookup name' inlineCommands of Just p -> p <|> raw Nothing -> case M.lookup name inlineCommands of -- cgit v1.2.3