summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Readers/LaTeX.hs
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-01-13 12:10:52 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2018-01-13 12:11:36 -0800
commit44222e0373f47c986833a609271d495d55ff48de (patch)
tree64c77bc0d7c98e69030c3ae8dda2dadf5881c847 /src/Text/Pandoc/Readers/LaTeX.hs
parent944ed5e0987e5069bfe70504e948f45a84f57324 (diff)
LaTeX reader: allow macro definitions inside macros.
Previously we went into an infinite loop with ``` \newcommand{\noop}[1]{#1} \noop{\newcommand{\foo}[1]{#1}} \foo{hi} ``` See #4253.
Diffstat (limited to 'src/Text/Pandoc/Readers/LaTeX.hs')
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 62d240688..d9b188606 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -442,19 +442,22 @@ doMacros n = do
Just o ->
(:) <$> option o bracketedToks
<*> count (numargs - 1) getarg
- let addTok (Tok _ (Arg i) _) acc | i > 0
- , i <= numargs =
- foldr addTok acc (args !! (i - 1))
+ -- first boolean param is true if we're tokenizing
+ -- an argument (in which case we don't want to
+ -- expand #1 etc.)
+ let addTok False (Tok _ (Arg i) _) acc | i > 0
+ , i <= numargs =
+ foldr (addTok True) acc (args !! (i - 1))
-- add space if needed after control sequence
-- see #4007
- addTok (Tok _ (CtrlSeq x) txt)
+ addTok _ (Tok _ (CtrlSeq x) txt)
acc@(Tok _ Word _ : _)
| not (T.null txt) &&
(isLetter (T.last txt)) =
Tok spos (CtrlSeq x) (txt <> " ") : acc
- addTok t acc = setpos spos t : acc
+ addTok _ t acc = setpos spos t : acc
ts' <- getInput
- setInput $ foldr addTok ts' newtoks
+ setInput $ foldr (addTok False) ts' newtoks
case expansionPoint of
ExpandWhenUsed ->
if n > 20 -- detect macro expansion loops