From 6f6ad0514d7c5ec6f7177beecb4f2d5ef80100ae Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 15 Oct 2018 11:46:31 -0700 Subject: LaTeX reader: make macroDef polymorphic and allow in inline context. Otherwise we can't parse something like ``` \lowercase{\def\x{Foo}} ``` I have actually seen tex like this in the wild. --- src/Text/Pandoc/Readers/LaTeX.hs | 14 ++++---------- test/command/ifstrequal.md | 3 +-- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 3751921ce..9e419793d 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -1308,13 +1308,7 @@ isBlockCommand s = treatAsBlock :: Set.Set Text treatAsBlock = Set.fromList - [ "let", "def", "DeclareRobustCommand" - , "newcommand", "renewcommand" - , "newenvironment", "renewenvironment" - , "providecommand", "provideenvironment" - -- newcommand, etc. should be parsed by macroDef, but we need this - -- here so these aren't parsed as inline commands to ignore - , "special", "pdfannot", "pdfstringdef" + [ "special", "pdfannot", "pdfstringdef" , "bibliographystyle" , "maketitle", "makeindex", "makeglossary" , "addcontentsline", "addtocontents", "addtocounter" @@ -1375,6 +1369,7 @@ inline = (mempty <$ comment) <|> (space <$ whitespace) <|> (softbreak <$ endline) <|> word + <|> macroDef <|> inlineCommand' <|> inlineEnvironment <|> inlineGroup @@ -1420,8 +1415,7 @@ end_ t = try (do preamble :: PandocMonad m => LP m Blocks preamble = mempty <$ many preambleBlock where preambleBlock = spaces1 - <|> void macroDef - <|> void blockCommand + <|> void (macroDef <|> blockCommand) <|> void braced <|> (notFollowedBy (begin_ "document") >> void anyTok) @@ -1484,7 +1478,7 @@ authors = try $ do egroup addMeta "author" (map trimInlines auths) -macroDef :: PandocMonad m => LP m Blocks +macroDef :: (Monoid a, PandocMonad m) => LP m a macroDef = mempty <$ ((commandDef <|> environmentDef) <* doMacros) where commandDef = do diff --git a/test/command/ifstrequal.md b/test/command/ifstrequal.md index 4ad04d2e1..24ed7ef54 100644 --- a/test/command/ifstrequal.md +++ b/test/command/ifstrequal.md @@ -5,6 +5,5 @@ \h{a} \h{b} ^D -[Para [Emph [Str "no"]] -,Para [Str "\225",SoftBreak,Str "b"]] +[Para [Emph [Str "no"],SoftBreak,Str "\225",SoftBreak,Str "b"]] ``` -- cgit v1.2.3