diff options
author | John MacFarlane <jgm@berkeley.edu> | 2018-10-15 12:24:20 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-10-15 12:32:38 -0700 |
commit | 788b1bb3d8bf5357354d3ac1fcc398ae64281b88 (patch) | |
tree | 21d6ee80ca02bafa6dadef4c1b5a73b448a55572 /src | |
parent | aed7aecfc305f1efffce635a0be20a237bb5003d (diff) | |
download | pandoc-788b1bb3d8bf5357354d3ac1fcc398ae64281b88.tar.gz |
LaTeX reader: more care with verbatim mode in macro definitions.
This solves some of the issues in #4408, but it is fragile and may
introduce new problems. We really need to change the approach
fundamentally and expand macros before pulling tokens from the stream,
rather than after.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index b292e9b8d..74f31cca1 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -1521,6 +1521,7 @@ defmacro = try $ Tok _ (CtrlSeq name) _ <- anyControlSeq argspecs <- many (argspecArg <|> argspecPattern) contents <- bracedOrToken + doMacros -- after all this verbatim mode return (name, Macro ExpandWhenUsed argspecs Nothing contents) argspecArg :: PandocMonad m => LP m ArgSpec @@ -1541,23 +1542,25 @@ newcommand = do controlSeq "renewcommand" <|> controlSeq "providecommand" <|> controlSeq "DeclareRobustCommand" - Tok _ (CtrlSeq name) txt <- withVerbatimMode $ do - optional (symbol '*') - anyControlSeq <|> - (symbol '{' *> spaces *> anyControlSeq <* spaces <* symbol '}') - spaces - numargs <- option 0 $ try bracketedNum - let argspecs = map (\i -> ArgNum i) [1..numargs] - spaces - optarg <- option Nothing $ Just <$> try bracketedToks - spaces - contents <- withVerbatimMode bracedOrToken - when (mtype == "newcommand") $ do - macros <- sMacros <$> getState - case M.lookup name macros of - Just _ -> report $ MacroAlreadyDefined (T.unpack txt) pos - Nothing -> return () - return (name, Macro ExpandWhenUsed argspecs optarg contents) + withVerbatimMode $ do + Tok _ (CtrlSeq name) txt <- do + optional (symbol '*') + anyControlSeq <|> + (symbol '{' *> spaces *> anyControlSeq <* spaces <* symbol '}') + spaces + numargs <- option 0 $ try bracketedNum + let argspecs = map (\i -> ArgNum i) [1..numargs] + spaces + optarg <- option Nothing $ Just <$> try bracketedToks + spaces + contents <- bracedOrToken + when (mtype == "newcommand") $ do + macros <- sMacros <$> getState + case M.lookup name macros of + Just _ -> report $ MacroAlreadyDefined (T.unpack txt) pos + Nothing -> return () + doMacros -- after all this verbatim mode + return (name, Macro ExpandWhenUsed argspecs optarg contents) newenvironment :: PandocMonad m => LP m (Text, Macro, Macro) newenvironment = do |