[Bug] Incorrect parsing and rendering for multi-line aligned LaTeX formulas (nabla vector calculus formulas)
Describe the bug Markpad's built-in LaTeX formula parser fails to correctly render multi-line aligned environment formulas. Vector calculus gradient/divergence/curl formulas with line breaks and vector symbols cannot be parsed normally, resulting in formula display failure, page width overflow and abnormal layout. This formula can be rendered perfectly in VS Code Markdown Preview Enhanced (MPE) and standard KaTeX environments.
To Reproduce Steps to reproduce the behavior: Steps to reproduce the behavior:
- Open Markpad application
- Create a new blank Markdown file
- Paste the following standard multi-line LaTeX aligned vector calculus formula into the file:
$$\begin{aligned}
\nabla(fg) &= f\nabla g + g\nabla f \\
\nabla\cdot(f\mathbf{F}) &= \nabla f\cdot\mathbf{F} + f\nabla\cdot\mathbf{F} \\
\nabla\times(f\mathbf{F}) &= \nabla f\times\mathbf{F} + f\nabla\times\mathbf{F} \\
\nabla(\mathbf{F}\cdot\mathbf{G}) &= (\mathbf{F}\cdot\nabla)\mathbf{G} + (\mathbf{G}\cdot\nabla)\mathbf{F} + \mathbf{F}\times(\nabla\times\mathbf{G}) + \mathbf{G}\times(\nabla\times\mathbf{F}) \\
\nabla\cdot(\mathbf{F}\times\mathbf{G}) &= \mathbf{G}\cdot(\nabla\times\mathbf{F}) - \mathbf{F}\cdot(\nabla\times\mathbf{G}) \\
\nabla\times(\mathbf{F}\times\mathbf{G}) &= (\mathbf{G}\cdot\nabla)\mathbf{F} - (\mathbf{F}\cdot\nabla)\mathbf{G} + \mathbf{F}(\nabla\cdot\mathbf{G}) - \mathbf{G}(\nabla\cdot\mathbf{F})
\end{aligned}$$
- Check the preview panel, observe rendering failure and page abnormal width overflow
Expected behavior The multi-line aligned LaTeX formula should be parsed and rendered correctly:
- Normal line-by-line alignment of vector calculus formulas
- Correct display of nabla, vector symbol and calculus operators
- No page width overflow or horizontal scrolling abnormality
- Consistent rendering effect with standard KaTeX / VS Code Markdown Preview Enhanced
Screenshots Only One Long-Long Line of Equations.
Device
- OS: [Windows / macOS / Linux (fill in your system)]
- Markpad Version: 2.6.11
Additional context
- Compatibility verification: This formula is a standard KaTeX-supported syntax, which can be rendered completely normally in mainstream Markdown preview tools represented by Markdown Preview Enhanced (MPE).
- Root cause speculation: The built-in formula parsing logic of Markpad has defects in processing multi-line aligned environments, line break symbols \ and vector bold symbols \mathbf{}, resulting in parsing interruption and page layout collapse.
- Associated layout issue: Failed formula parsing will cause the preview page to be infinitely widened beyond the viewport, triggering abnormal global horizontal scrolling, which seriously affects the reading experience of mathematical notes.
- Suggest optimizing the LaTeX parsing engine to be consistent with standard KaTeX rules to support complete multi-line alignment formulas and scientific calculus formulas.
Retested the exact aligned formula from this report against the current v2.6.14 source build on macOS. It renders as a multi-row aligned KaTeX display in split preview; the display uses its own horizontal overflow container, so it does not widen the document. The relevant current path is Comrak with hard line breaks → processDisplayMathBlocks → KaTeX, plus .katex-display { overflow-x: auto; }.
Please retest with a current build. If the original full fixture still fails on a specific platform, please attach that exact file and a screenshot so we can compare the rendering path.
Reproduced, and it is the same root cause as #177 and #174.
comrak applies CommonMark inline rules inside $$…$$ before KaTeX sees the source, so \\ is consumed as an escape and becomes a single \:
… g\nabla f \<br />
Feeding that to KaTeX, a three-row aligned block parses as one row — which is exactly the single long line and the horizontal overflow you described.
#351 added a guard, but it protects only underscores and only inside $$. The general fix is to mask the entire delimited span before comrak and restore it afterwards, which covers \\ here, \% in #177 and inline _ in #174 together. Working on it.
Fixed in v2.7.0 by #402 — comrak was applying Markdown inline rules inside the math delimiters before KaTeX saw the source, so \\ was eaten as an escape and the row separators of your aligned block disappeared.
#174 (_{1} becoming italics) and #177 (\% starting a TeX comment) were the same bug; #402 masks the whole delimited span before parsing rather than patching one character class at a time.
One thing worth flagging: the regression test uses a reduced aligned block rather than the nabla formula you posted. If you could retest with that exact file, it would be the more useful check. Happy to reopen if it's still there.