aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Ferdman <[email protected]>2025-11-04 10:42:27 +0200
committerGitHub <[email protected]>2025-11-04 09:42:27 +0100
commitb106dca0693a26b8f134bb8550fe6ea5a83f3346 (patch)
treea8e916e66168ddb2e0b6420190a57932bd24aef1
parent74f583847fb108593101a34ed88a13005a2252fb (diff)
LaTeX reader: fix spurious paragraph breaks in math environments (#11265)
Previously, a math environment with extra space before the `\end` would get rendered with a blank line, which LaTeX treats as a paragraph break. Signed-off-by: Emmanuel Ferdman <[email protected]>
-rw-r--r--src/Text/Pandoc/Readers/LaTeX/Math.hs4
-rw-r--r--test/command/latex-math-trailing-space.md38
2 files changed, 40 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX/Math.hs b/src/Text/Pandoc/Readers/LaTeX/Math.hs
index 1f4dc4f8c..f1491656e 100644
--- a/src/Text/Pandoc/Readers/LaTeX/Math.hs
+++ b/src/Text/Pandoc/Readers/LaTeX/Math.hs
@@ -21,7 +21,7 @@ import qualified Data.Sequence as Seq
import Text.Pandoc.Readers.LaTeX.Parsing
import Text.Pandoc.TeX
import Text.Pandoc.Class
-import Text.Pandoc.Shared (trimMath, stripTrailingNewlines)
+import Text.Pandoc.Shared (trimMath, trimr)
import Text.Pandoc.Parsing hiding (blankline, mathDisplay, mathInline,
optional, space, spaces, withRaw, (<|>))
import Control.Applicative ((<|>), optional)
@@ -82,7 +82,7 @@ mathEnv :: PandocMonad m => Text -> LP m Text
mathEnv name = withMathMode $ do
optional blankline
res <- manyTill anyTok (end_ name)
- return $ stripTrailingNewlines $ untokenize res
+ return $ trimr $ untokenize res
inlineEnvironment :: PandocMonad m => LP m Inlines
inlineEnvironment = try $ do
diff --git a/test/command/latex-math-trailing-space.md b/test/command/latex-math-trailing-space.md
new file mode 100644
index 000000000..6502b120a
--- /dev/null
+++ b/test/command/latex-math-trailing-space.md
@@ -0,0 +1,38 @@
+Test that trailing spaces before \end{equation} don't create spurious paragraph breaks:
+
+```
+% pandoc -f latex -t latex
+\begin{equation}
+ a
+ \end{equation}
+^D
+\begin{equation}
+ a
+\end{equation}
+```
+
+Same for align environment:
+
+```
+% pandoc -f latex -t latex
+\begin{align}
+ x &= y \\
+ \end{align}
+^D
+\begin{align}
+ x &= y \\
+\end{align}
+```
+
+Test with multiple trailing spaces:
+
+```
+% pandoc -f latex -t latex
+\begin{equation}
+ a + b
+ \end{equation}
+^D
+\begin{equation}
+ a + b
+\end{equation}
+```