git.iko.soy/typeable/pandoc
on master help sign in
Markdown: Ensure that expanded latex macros end with space if original did.
339392bJohn MacFarlane
src/Text/Pandoc/Readers/LaTeX/Parsing.hs+10−1
@@ -226,7 +226,16 @@ rawLaTeXParser retokenize parser valParser = do
226 Right ((val, raw), st) -> do
226 Right ((val, raw), st) -> do
227 updateState (updateMacros (sMacros st <>))
227 updateState (updateMacros (sMacros st <>))
228 _ <- takeP (T.length (untokenize toks'))
228 _ <- takeP (T.length (untokenize toks'))
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
229− return (val, T.unpack (untokenize raw))
238+ return (val, T.unpack result')
230
239
231applyMacros :: (PandocMonad m, HasMacros s, HasReaderOptions s)
240applyMacros :: (PandocMonad m, HasMacros s, HasReaderOptions s)
232 => String -> ParserT String s m String
241 => 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+```