@@ -1168,10 +1168,10 @@ inlineToLaTeX (Str str) = do
1168 liftM text $ stringToLaTeX TextString str
1168 liftM text $ stringToLaTeX TextString str
1169inlineToLaTeX (Math InlineMath str) = do
1169inlineToLaTeX (Math InlineMath str) = do
1170 setEmptyLine False
1170 setEmptyLine False
1171− return $ "\\(" <> text str <> "\\)"
1171+ return $ "\\(" <> text (handleMathComment str) <> "\\)"
1172inlineToLaTeX (Math DisplayMath str) = do
1172inlineToLaTeX (Math DisplayMath str) = do
1173 setEmptyLine False
1173 setEmptyLine False
1174− return $ "\\[" <> text str <> "\\]"
1174+ return $ "\\[" <> text (handleMathComment str) <> "\\]"
1175inlineToLaTeX il@(RawInline f str)
1175inlineToLaTeX il@(RawInline f str)
1176 | f == Format "latex" || f == Format "tex"
1176 | f == Format "latex" || f == Format "tex"
@@ -1272,6 +1272,16 @@ inlineToLaTeX (Note contents) = do
1272 -- note: a \n before } needed when note ends with a Verbatim environment
1272 -- note: a \n before } needed when note ends with a Verbatim environment
1273 else "\\footnote" <> beamerMark <> braces noteContents
1273 else "\\footnote" <> beamerMark <> braces noteContents
1275+-- A comment at the end of math needs to be followed by a newline,
1276+-- or the closing delimiter gets swallowed.
1277+handleMathComment :: String -> String
1278+handleMathComment s =
1279+ let (xs, ys) = break (\c -> c == '\n' || c == '%') $ reverse s
1275protectCode :: [Inline] -> [Inline]
1285protectCode :: [Inline] -> [Inline]
1276protectCode [] = []
1286protectCode [] = []
1277protectCode (x@(Code ("",[],[]) _) : xs) = x : protectCode xs
1287protectCode (x@(Code ("",[],[]) _) : xs) = x : protectCode xs