Skip to content

feat(ui): render markdown math#878

Open
ishowman wants to merge 2 commits into
backnotprop:mainfrom
ishowman:free/issue-831-markdown-math
Open

feat(ui): render markdown math#878
ishowman wants to merge 2 commits into
backnotprop:mainfrom
ishowman:free/issue-831-markdown-math

Conversation

@ishowman

@ishowman ishowman commented Jun 9, 2026

Copy link
Copy Markdown

Summary

Close #831, and extend Plannotator math rendering to support the common KaTeX/LLM-friendly delimiters \(...\) and \[...\], in addition to the existing $...$ and $$...$$ forms.

What changed

  • Render inline math with both $...$ and \(...\).
  • Render display math with both $$...$$ and \[...\].
  • Keep escaped dollars and non-math text literal.
  • Preserve accurate line tracking for display-math blocks so annotation exports stay correct.

Scope

This stays within the UI/parser layer and does not require server API changes.

Validation

  • bun test packages/ui/components/InlineMarkdown.test.ts packages/ui/utils/parser.test.ts
  • PATH=/Users/xxq/Documents/codes/plannotator/packages/ui/node_modules/.bin:$PATH bun run typecheck
  • git diff --check

Notes

This update is aimed at markdown generated by LLMs and math rendered by KaTeX-style delimiters.

@ishowman ishowman marked this pull request as draft June 9, 2026 10:36
@XxxXMil

XxxXMil commented Jun 9, 2026

Copy link
Copy Markdown

Would it be possible to also support \(...\) and \[...\] delimiters? They’re common in LLM-generated Markdown and KaTeX auto-render supports them by default.

@ishowman ishowman marked this pull request as ready for review June 10, 2026 04:00
@ishowman

Copy link
Copy Markdown
Author

Would it be possible to also support \(...\) and \[...\] delimiters? They’re common in LLM-generated Markdown and KaTeX auto-render supports them by default.

I've submitted new commit for it.Could you please verify if the result matches your expectations when you have spare time?

@XxxXMil

XxxXMil commented Jun 10, 2026

Copy link
Copy Markdown

Thanks for working on this! I tested the PR locally in Pi by installing the PR branch.

Some parts work well:

  • Inline math with \(...\) renders correctly.
  • Block math with \[...\] and $$...$$ renders correctly.

I also found a few issues during manual testing:

  1. Inline math using $...$ is not very stable in my testing. Some $...$ expressions render, but others remain as raw text.
  2. Highlighting anchoring doesn't shown on rendered math.

I attached screenshots showing these cases:

image image

Raw text for the last screenshot:

In a linear Gaussian model, the prediction \( \hat{y} = \mathbf{x}^\top \boldsymbol{\beta} \) is compared against the target $y$ using the loss \( \mathcal{L}(\boldsymbol{\beta}) = \frac{1}{2N}\sum_{i=1}^{N}(y_i - \mathbf{x}_i^\top\boldsymbol{\beta})^2 \), while the noise term satisfies $\varepsilon \sim \mathcal{N}(0,\sigma^2)$.

In this case, $...$ works well.

@XxxXMil

XxxXMil commented Jun 10, 2026

Copy link
Copy Markdown

Small follow-up: I found the cause of the inconsistent $...$ behavior.

Testing inline `$...$` with spaces inside the delimiters:

$ \varepsilon \sim \mathcal{N}(0,\sigma^2) $

Testing inline `$...$` without spaces inside the delimiters:

$\varepsilon \sim \mathcal{N}(0,\sigma^2)$
image

$\varepsilon \sim \mathcal{N}(0,\sigma^2)$ renders correctly, but $ \varepsilon \sim \mathcal{N}(0,\sigma^2) $ stays as raw text because of the spaces just inside the delimiters.

This might be avoidable by prompting LLMs to emit $...$ without inner spaces?

Other test:
image

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.

FR: Support Markdown math formula rendering in Plannotator

2 participants