Skip to content

Fixes markdown katex bug#1586

Open
davidmerfield wants to merge 6 commits into
masterfrom
katex-bug
Open

Fixes markdown katex bug#1586
davidmerfield wants to merge 6 commits into
masterfrom
katex-bug

Conversation

@davidmerfield

@davidmerfield davidmerfield commented Jul 17, 2026

Copy link
Copy Markdown
Owner

There was previously an issue handling katex blocks with markdown inside, e.g.

$$
\mathbf{v}_1^{\text{cm}} = \mathbf{v} - \mathbf{v}_{\text{cm}} = \frac{\mathbf{v}}{2}
$$

Would become:

<p>$$ \mathbf{v}<em>2^{\text{cm}} = 0 - \mathbf{v}</em>{\text{cm}} = -\frac{\mathbf{v}}{2} $$</p>

This is now fixed.


  • we need to strip the HTML and body tags from the pandoc output
  • we need to preserve double dollar sign inline math somehow?
  • fix new test spec bugs
  • can we simplify some of the katex handling?
  • can we support other converters? do they need -katex now? add specs
  • add spec for weird bug in markdown txt file with html, e.g. This is an inline <code>$$withmath$$</code>

@cursor

cursor Bot commented Jul 17, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 131fa24f0e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread app/build/plugins/katex/index.js
Comment thread app/build/converters/markdown/convert.js
@davidmerfield

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d4927dfbd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +75 to +77
const source = $span.text();

$span.replaceWith(renderTex(source, display));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve escaped TeX when rendering fails

If a Pandoc math span contains invalid TeX with escaped markup, such as \bad &lt;img src=x onerror=...&gt;, this path decodes the entity via .text(), then renderTex falls back to returning $$ + original + $$, and replaceWith reparses that fallback as HTML. In that failure case escaped source text is turned into live tags instead of remaining a literal failed equation.

Useful? React with 👍 / 👎.

Comment thread app/build/plugins/katex/index.js Outdated
}

function render($, callback) {
renderPandocMath($);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Skip newly rendered KaTeX spans during text scanning

When a Pandoc span contains valid TeX that itself includes a literal $$...$$ sequence, such as \text{$$x$$}, this runs before the later eachTextNode pass. Because that pass does not skip the .katex markup just inserted, it scans the MathML <annotation> text and treats the literal dollars as another equation, nesting KaTeX HTML inside the annotation and corrupting the rendered math.

Useful? React with 👍 / 👎.

}

function renderPandocMath($) {
$("span.math.inline, span.math.display").each(function () {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid re-rendering non-KaTeX Pandoc math spans

For files that reach this plugin from Pandoc converters other than the Markdown converter, the converter args still don't include --katex (for example app/build/converters/org/convert.js), so span.math contains Pandoc's plain/Unicode HTML rather than raw TeX. This selector nevertheless feeds the span text back to KaTeX, which reinterprets already-rendered output such as a fraction as 1/2 and loses the original formula.

Useful? React with 👍 / 👎.

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.

1 participant