Skip to content

Fix KaTeX matrix rendering when LaTeX contains HTML-escaped ampersands#61

Merged
mcgivrer merged 3 commits into
mainfrom
copilot/fix-latex-code-interpretation
Apr 17, 2026
Merged

Fix KaTeX matrix rendering when LaTeX contains HTML-escaped ampersands#61
mcgivrer merged 3 commits into
mainfrom
copilot/fix-latex-code-interpretation

Conversation

Copilot AI commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Markdown-to-HTML conversion escapes matrix separators (&) to &, which causes KaTeX to render amp; text and break matrix alignment in preview. This PR updates the math rendering path so LaTeX receives the expected separators.

  • Math rendering fix (preview.js)

    • In renderKaTeX(), decode & back to & for extracted TeX content before calling katex.renderToString(...).
    • Scope is intentionally narrow: only matrix-relevant ampersand unescaping in KaTeX input.
  • Behavioral impact

    • LaTeX matrices using escaped separators now render with correct column structure.
    • Non-math HTML escaping behavior remains unchanged.
function decodeHtmlEntities(text) {
  return text.replace(/&/g, '&');
}

html = html.replace(/\$\$([\s\S]+?)\$\$/g, function(m, tex) {
  return katex.renderToString(decodeHtmlEntities(tex).trim(), { displayMode: true, throwOnError: false });
});

Copilot AI linked an issue Apr 17, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits April 17, 2026 10:26
Copilot AI changed the title [WIP] Fix issue interpreting LaTeX code for matrices Fix KaTeX matrix rendering when LaTeX contains HTML-escaped ampersands Apr 17, 2026
Copilot AI requested a review from mcgivrer April 17, 2026 10:31
@mcgivrer mcgivrer marked this pull request as ready for review April 17, 2026 11:15
@mcgivrer mcgivrer merged commit 9c05718 into main Apr 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Issue interpreting Latex code for Matrices

2 participants