git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: allow macro definitions inside macros.
44222e0John MacFarlane
src/Text/Pandoc/Readers/LaTeX.hs+9−6
@@ -442,19 +442,22 @@ doMacros n = do
442 Just o ->
442 Just o ->
443 (:) <$> option o bracketedToks
443 (:) <$> option o bracketedToks
444 <*> count (numargs - 1) getarg
444 <*> count (numargs - 1) getarg
445+ -- first boolean param is true if we're tokenizing
446+ -- an argument (in which case we don't want to
447+ -- expand #1 etc.)
445− let addTok (Tok _ (Arg i) _) acc | i > 0
448+ let addTok False (Tok _ (Arg i) _) acc | i > 0
446− , i <= numargs =
449+ , i <= numargs =
447− foldr addTok acc (args !! (i - 1))
450+ foldr (addTok True) acc (args !! (i - 1))
448 -- add space if needed after control sequence
451 -- add space if needed after control sequence
449 -- see #4007
452 -- see #4007
450− addTok (Tok _ (CtrlSeq x) txt)
453+ addTok _ (Tok _ (CtrlSeq x) txt)
451 acc@(Tok _ Word _ : _)
454 acc@(Tok _ Word _ : _)
452 | not (T.null txt) &&
455 | not (T.null txt) &&
453 (isLetter (T.last txt)) =
456 (isLetter (T.last txt)) =
454 Tok spos (CtrlSeq x) (txt <> " ") : acc
457 Tok spos (CtrlSeq x) (txt <> " ") : acc
455− addTok t acc = setpos spos t : acc
458+ addTok _ t acc = setpos spos t : acc
456 ts' <- getInput
459 ts' <- getInput
457− setInput $ foldr addTok ts' newtoks
460+ setInput $ foldr (addTok False) ts' newtoks
458 case expansionPoint of
461 case expansionPoint of
459 ExpandWhenUsed ->
462 ExpandWhenUsed ->
460 if n > 20 -- detect macro expansion loops
463 if n > 20 -- detect macro expansion loops