git.iko.soy/typeable/pandoc
on master help sign in
Markdown: Ensure that expanded latex macros end with space if original did.

Closes #4442.

commit339392bf549a8a02ea17f94c02fb01cf121bc05a authorJohn MacFarlane <jgm@berkeley.edu> dateFri 19 Jul 2019, 10:32 (7 years ago) parent50885ea
2 files changed+19−1
src/Text/Pandoc/Readers/LaTeX/Parsing.hs+10−1 test/command/4442.md+9
src/Text/Pandoc/Readers/LaTeX/Parsing.hs+10−1
@@ -226,7 +226,16 @@ rawLaTeXParser retokenize parser valParser = do
226226 Right ((val, raw), st) -> do
227227 updateState (updateMacros (sMacros st <>))
228228 _ <- takeP (T.length (untokenize toks'))
229− return (val, T.unpack (untokenize raw))
229+ let result = untokenize raw
230+ -- ensure we end with space if input did, see #4442
231+ let result' =
232+ case reverse toks' of
233+ (Tok _ (CtrlSeq _) t : _)
234+ | " " `T.isSuffixOf` t
235+ , not (" " `T.isSuffixOf` result)
236+ -> result <> " "
237+ _ -> result
238+ return (val, T.unpack result')
230239
231240applyMacros :: (PandocMonad m, HasMacros s, HasReaderOptions s)
232241 => String -> ParserT String s m String
test/command/4442.mdnew file+9
@@ -0,0 +1,9 @@
1+```
2+% pandoc -f markdown -t latex
3+\newcommand{\myFruit}{Mango\xspace}
4+\myFruit is the king of fruits.
5+^D
6+\newcommand{\myFruit}{Mango\xspace}
7+
8+Mango\xspace is the king of fruits.
9+```