summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-10-30 11:51:49 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2017-10-30 11:51:49 -0700
commit90597fe292a84959d289fe17eae226c7e8bf23c8 (patch)
tree5d33b201c84653047d856ebf3be89c9a1ca0a2c8
parent272b833ad55c6705e44703d1d38b07548f017ecf (diff)
LaTeX reader: insert space when needed in macro expansion.
Sometimes we need to insert a space after a control sequence to prevent it merging with a following letter. Closes #4007.
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 407952a54..a982029af 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -438,7 +438,14 @@ doMacros n = do
<*> count (numargs - 1) getarg
let addTok (Tok _ (Arg i) _) acc | i > 0
, i <= numargs =
- map (setpos spos) (args !! (i - 1)) ++ acc
+ foldr addTok acc (args !! (i - 1))
+ -- add space if needed after control sequence
+ -- see #4007
+ 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
ts' <- getInput
setInput $ foldr addTok ts' newtoks