LaTeX writer: add newline if math ends in a comment.
This prevents the closing delimiter from being swalled up in the comment. Closes #4880.
This commit is contained in:
parent
ffd3aa4f09
commit
e0290fd18b
2 changed files with 19 additions and 2 deletions
|
@ -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
|
||||
|
|
7
test/command/4880.md
Normal file
7
test/command/4880.md
Normal file
|
@ -0,0 +1,7 @@
|
|||
```
|
||||
% pandoc -t latex
|
||||
$x=y%comment$
|
||||
^D
|
||||
\(x=y%comment
|
||||
\)
|
||||
```
|
Loading…
Reference in a new issue