Skip to content

Fix LaTeX preprocessing mutating code blocks#147

Open
rickintoplace wants to merge 1 commit into
gwdg:mainfrom
rickintoplace:fix/preprocess-latex-preserve-code-blocks
Open

Fix LaTeX preprocessing mutating code blocks#147
rickintoplace wants to merge 1 commit into
gwdg:mainfrom
rickintoplace:fix/preprocess-latex-preserve-code-blocks

Conversation

@rickintoplace

@rickintoplace rickintoplace commented May 21, 2026

Copy link
Copy Markdown

Summary

Fixes #146.

Probably also fixes #144.

Fixes an issue in Default render mode where fenced and inline code blocks containing regex character classes could be modified by preprocessLaTeX which resulted in incorrect regex.

Problem

Code blocks were temporarily replaced with placeholders, but restored before global LaTeX delimiter replacements were applied.

As a result, sequences such as \] inside JavaScript regexes were interpreted as LaTeX delimiters and replaced.

Example affected input:

const re = /[.*+?^${}()|[$$\$$/g;

Fix

  • Keep code block placeholders in place until after LaTeX delimiter replacements.
  • Use replacement callbacks for literal dollar signs, because "$$" in JavaScript replacement strings produces a single $.

Testing

  • Manually checked the preprocessing logic. The fix preserves regex character classes in fenced code blocks while still converting LaTeX delimiters outside code.
  • I am working with the fix without problems since 4 days.

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.

[Bug] preprocessLaTeX mutates fenced code block content in Default render mode [Bug] Rendering of LaTeX Formulae Broken

1 participant