aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2019-07-19 10:32:59 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2019-07-19 10:32:59 -0700
commit339392bf549a8a02ea17f94c02fb01cf121bc05a (patch)
tree952220765c538c82a8442b7b9fd3124686d90163
parent50885eabde6e9ba524d74a234154766f4c522627 (diff)
downloadpandoc-339392bf549a8a02ea17f94c02fb01cf121bc05a.tar.gz
Markdown: Ensure that expanded latex macros end with space if original did.
Closes #4442.
-rw-r--r--src/Text/Pandoc/Readers/LaTeX/Parsing.hs11
-rw-r--r--test/command/4442.md9
2 files changed, 19 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs
index a265d6ca2..eeebab3e6 100644
--- a/src/Text/Pandoc/Readers/LaTeX/Parsing.hs
+++ b/src/Text/Pandoc/Readers/LaTeX/Parsing.hs
@@ -226,7 +226,16 @@ rawLaTeXParser retokenize parser valParser = do
Right ((val, raw), st) -> do
updateState (updateMacros (sMacros st <>))
_ <- takeP (T.length (untokenize toks'))
- return (val, T.unpack (untokenize raw))
+ let result = untokenize raw
+ -- ensure we end with space if input did, see #4442
+ let result' =
+ case reverse toks' of
+ (Tok _ (CtrlSeq _) t : _)
+ | " " `T.isSuffixOf` t
+ , not (" " `T.isSuffixOf` result)
+ -> result <> " "
+ _ -> result
+ return (val, T.unpack result')
applyMacros :: (PandocMonad m, HasMacros s, HasReaderOptions s)
=> String -> ParserT String s m String
diff --git a/test/command/4442.md b/test/command/4442.md
new file mode 100644
index 000000000..8574fe759
--- /dev/null
+++ b/test/command/4442.md
@@ -0,0 +1,9 @@
+```
+% pandoc -f markdown -t latex
+\newcommand{\myFruit}{Mango\xspace}
+\myFruit is the king of fruits.
+^D
+\newcommand{\myFruit}{Mango\xspace}
+
+Mango\xspace is the king of fruits.
+```