diff options
| author | John MacFarlane <jgm@berkeley.edu> | 2018-01-13 12:10:52 -0800 | 
|---|---|---|
| committer | John MacFarlane <jgm@berkeley.edu> | 2018-01-13 12:11:36 -0800 | 
| commit | 44222e0373f47c986833a609271d495d55ff48de (patch) | |
| tree | 64c77bc0d7c98e69030c3ae8dda2dadf5881c847 /src/Text | |
| parent | 944ed5e0987e5069bfe70504e948f45a84f57324 (diff) | |
| download | pandoc-44222e0373f47c986833a609271d495d55ff48de.tar.gz | |
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')
| -rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 15 | 
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 | 
