kimi-code icon indicating copy to clipboard operation
kimi-code copied to clipboard

feat(web): enable \(...\) as inline math delimiter in kimi web

Open Henry-Jessie opened this issue 4 months ago • 2 comments

What feature would you like to see?

Enable \(...\) as an inline math delimiter in kimi web.

Currently, apps/kimi-web/src/components/chat/Markdown.vue (disableInlineMath) disables markdown-it's inline math rule entirely, so no inline math renders at all — $...$, \(...\), and mid-paragraph $$...$$ all show as raw source. Only standalone $$...$$ blocks are rendered.

\(...\) is the safe way to bring inline math back:

  • It contains no $, so literal text like $5, $PATH, $HOME/bin — the original reason inline math was disabled — stays completely untouched.
  • markstream's inline math rule already recognizes \(...\) (markstream-vue/packages/markdown-parser/src/plugins/math.ts); the current blanket disable('math') kills it together with $...$. Re-enabling just the \(...\) branch is enough.

Inline math is heavily used in technical and scientific answers, and models default to it — so a large fraction of math output currently degrades to raw LaTeX source on the web. The VSCode extension webview already renders inline math (remark-math + rehype-katex), so the same answer also renders inconsistently across surfaces.

Additional information

No response

Henry-Jessie avatar Jul 17 '26 03:07 Henry-Jessie

We hit the same problem and implemented a fix that goes one step further: instead of enabling only \(...\), it brings back full $...$ inline math (which is what models emit most of the time) while keeping $5, $PATH, $HOME/bin literal.

Approach: swap markstream's built-in math inline rule (md.inline.ruler.at('math', …) instead of disable('math')) for a conservative pandoc-style variant:

  • the opening delimiter must be followed by a non-space character;
  • a closing $ must be preceded by a non-space and must not be followed by a digit (this is what keeps $5 and $10-style prices literal);
  • the content must be non-empty, contain no backtick, and not be a bare number ($100$ stays a currency amount);
  • an unclosed $ stays literal — no mid-stream "loading" math;
  • \(...\) and inline $$...$$ keep working, and math_block is untouched.

Code spans are safe by construction: markdown-it's backticks rule consumes the whole span before the math rule ever sees a $ inside it, and the backtick guard prevents a math span from closing across a code span.

Working implementation with unit + parser-integration tests: https://github.com/nothankyouzzz/kimi-code/commit/637a984ee (branch fix/web-inline-katex). Verified on real sessions — formulas like $\Sigma_t$, $\leq t-1$, $w^\top\Sigma w$ now render through the existing KaTeX pipeline, while $5, $PATH, $HOME/bin and $PATH stay literal.

Happy to open a PR if the maintainers are interested in this direction.

nothankyouzzz avatar Jul 23 '26 09:07 nothankyouzzz

Adding a user-side confirmation plus one extra data point not explicitly listed above: Markdown table cells.

Environment

  • kimi-code 0.29.1
  • Windows 11, kimi web UI in browser

What I see

  • $$...$$ display blocks render correctly.
  • Inline $...$ renders as raw source throughout prose (dollar signs and backslashes visible), e.g. Suppose $v_1,\dots,v_n$ is a basis of $V$ shows literally.
  • Table cells: LaTeX inside Markdown table cells also renders raw. Math-heavy answers often end with a comparison/summary table whose cells contain formulas (e.g. $T|_U = S$, $\dim \mathcal{L}(V,W) = (\dim V)(\dim W)$), and every such cell degrades to raw source. Whichever fix lands (the conservative $...$ rule in PR #2105 or the opt-in setting in PR #1848), it would be valuable to have the table-cell rendering path explicitly covered by tests.

Use case / why it matters Long technical tutoring sessions (working through a linear algebra textbook theorem-by-theorem). Models default to inline $...$ very heavily — a single answer can contain 50+ inline formulas, so a large fraction of the content is currently unreadable in the web UI. Workaround for now: instructing the model to write inline math in Unicode (T: V → W, λ, ∈, ⊆) and reserve $$...$$ for display blocks — serviceable, but it shouldn't be necessary.

Happy to attach a screenshot or test a fix build.

RollinCCC avatar Jul 25 '26 09:07 RollinCCC