diff options
author | John MacFarlane <jgm@berkeley.edu> | 2021-02-20 22:03:29 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2021-02-20 22:03:29 -0800 |
commit | 31b8f60ea82d96b370cf4a765c46c18004ff6fa8 (patch) | |
tree | 4e18210b1b2e5c19e28ca6e0cb70e2a73a4afde8 /src/Text/Pandoc/Readers | |
parent | 0f955b10b455e9b3d326262d03261f17538a6943 (diff) | |
download | pandoc-31b8f60ea82d96b370cf4a765c46c18004ff6fa8.tar.gz |
LaTeX reader: avoid macro resolution code if no macros defined.
Diffstat (limited to 'src/Text/Pandoc/Readers')
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX/Parsing.hs | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs index dab4d334e..fc8542894 100644 --- a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs +++ b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs @@ -453,20 +453,24 @@ doMacros = do updateState $ \st -> st{ sExpanded = True } doMacros' :: PandocMonad m => Int -> [Tok] -> LP m [Tok] -doMacros' n inp = - case inp of - Tok spos (CtrlSeq "begin") _ : Tok _ Symbol "{" : - Tok _ Word name : Tok _ Symbol "}" : ts - -> handleMacros n spos name ts - Tok spos (CtrlSeq "end") _ : Tok _ Symbol "{" : - Tok _ Word name : Tok _ Symbol "}" : ts - -> handleMacros n spos ("end" <> name) ts - Tok _ (CtrlSeq "expandafter") _ : t : ts - -> combineTok t <$> doMacros' n ts - Tok spos (CtrlSeq name) _ : ts - -> handleMacros n spos name ts - _ -> return inp - <|> return inp +doMacros' n inp = do + macros <- sMacros <$> getState + if M.null macros + then return inp + else + case inp of + Tok spos (CtrlSeq "begin") _ : Tok _ Symbol "{" : + Tok _ Word name : Tok _ Symbol "}" : ts + -> handleMacros macros n spos name ts + Tok spos (CtrlSeq "end") _ : Tok _ Symbol "{" : + Tok _ Word name : Tok _ Symbol "}" : ts + -> handleMacros macros n spos ("end" <> name) ts + Tok _ (CtrlSeq "expandafter") _ : t : ts + -> combineTok t <$> doMacros' n ts + Tok spos (CtrlSeq name) _ : ts + -> handleMacros macros n spos name ts + _ -> return inp + <|> return inp where combineTok (Tok spos (CtrlSeq name) x) (Tok _ Word w : ts) @@ -507,10 +511,9 @@ doMacros' n inp = Tok spos (CtrlSeq x) (txt <> " ") : acc addTok _ _ spos t acc = setpos spos t : acc - handleMacros n' spos name ts = do + handleMacros macros n' spos name ts = do when (n' > 20) -- detect macro expansion loops $ throwError $ PandocMacroLoop name - macros <- sMacros <$> getState case M.lookup name macros of Nothing -> mzero Just (Macro expansionPoint argspecs optarg newtoks) -> do |