diff options
author | John MacFarlane <jgm@berkeley.edu> | 2018-10-31 21:51:20 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2018-10-31 21:51:20 -0700 |
commit | e0290fd18bb523f5f08e2d5f5d2a8b89916654d2 (patch) | |
tree | 87f7df3c0a76da0bdfd457652951701e2ef7fe34 /src/Text | |
parent | ffd3aa4f090f9add3521ce88f01b96518489d49c (diff) | |
download | pandoc-e0290fd18bb523f5f08e2d5f5d2a8b89916654d2.tar.gz |
LaTeX writer: add newline if math ends in a comment.
This prevents the closing delimiter from being swalled
up in the comment.
Closes #4880.
Diffstat (limited to 'src/Text')
-rw-r--r-- | src/Text/Pandoc/Writers/LaTeX.hs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs index 11d58b90a..a2c7ac34f 100644 --- a/src/Text/Pandoc/Writers/LaTeX.hs +++ b/src/Text/Pandoc/Writers/LaTeX.hs @@ -1168,10 +1168,10 @@ inlineToLaTeX (Str str) = do liftM text $ stringToLaTeX TextString str inlineToLaTeX (Math InlineMath str) = do setEmptyLine False - return $ "\\(" <> text str <> "\\)" + return $ "\\(" <> text (handleMathComment str) <> "\\)" inlineToLaTeX (Math DisplayMath str) = do setEmptyLine False - return $ "\\[" <> text str <> "\\]" + return $ "\\[" <> text (handleMathComment str) <> "\\]" inlineToLaTeX il@(RawInline f str) | f == Format "latex" || f == Format "tex" = do @@ -1272,6 +1272,16 @@ inlineToLaTeX (Note contents) = do -- note: a \n before } needed when note ends with a Verbatim environment else "\\footnote" <> beamerMark <> braces noteContents +-- A comment at the end of math needs to be followed by a newline, +-- or the closing delimiter gets swallowed. +handleMathComment :: String -> String +handleMathComment s = + let (xs, ys) = break (\c -> c == '\n' || c == '%') $ reverse s + in case ys of + '%':'\\':_ -> s + '%':_ -> s ++ "\n" + _ -> s + protectCode :: [Inline] -> [Inline] protectCode [] = [] protectCode (x@(Code ("",[],[]) _) : xs) = x : protectCode xs |