diff --git a/.changeset/tidy-planets-kneel.md b/.changeset/tidy-planets-kneel.md new file mode 100644 index 0000000000..363dbd33ab --- /dev/null +++ b/.changeset/tidy-planets-kneel.md @@ -0,0 +1,5 @@ +--- +"@moonshot-ai/kimi-code": patch +--- + +web: Add an opt-in setting to render $…$ as inline LaTeX in chat messages; it stays off by default because bare $ in prices or variables like $PATH can be misdetected as math. Enable it in Settings → General → Inline math rendering. diff --git a/apps/kimi-web/src/App.vue b/apps/kimi-web/src/App.vue index 5708bcc9bf..da4e3617c2 100644 --- a/apps/kimi-web/src/App.vue +++ b/apps/kimi-web/src/App.vue @@ -998,6 +998,7 @@ function openPr(url: string): void { :notify-permission="client.notifyPermission.value" :sound="client.soundOnComplete.value" :conversation-toc="client.conversationToc.value" + :inline-math="client.inlineMath.value" :config="client.config.value" :models="client.models.value" :config-saving="configSaving" @@ -1011,6 +1012,7 @@ function openPr(url: string): void { @set-notify-approval="client.setNotifyOnApproval($event)" @set-sound="client.setSoundOnComplete($event)" @set-conversation-toc="client.setConversationToc($event)" + @set-inline-math="client.setInlineMath($event)" @update-config="handleUpdateConfig($event)" @login="() => { showSettings = false; openLogin(); }" @logout="client.logout" @@ -1110,6 +1112,7 @@ function openPr(url: string): void { :ui-font-size="client.uiFontSize.value" :auth-ready="client.authReady.value" :conversation-toc="client.conversationToc.value" + :inline-math="client.inlineMath.value" :server-version="client.serverVersion.value" @pick-model="openModelPicker()" @set-thinking="client.setThinking($event)" @@ -1119,6 +1122,7 @@ function openPr(url: string): void { @set-color-scheme="client.setColorScheme($event)" @set-ui-font-size="client.setUiFontSize($event)" @set-conversation-toc="client.setConversationToc($event)" + @set-inline-math="client.setInlineMath($event)" @login="() => { showMobileSettings = false; openLogin(); }" @logout="client.logout" /> diff --git a/apps/kimi-web/src/components/chat/Markdown.vue b/apps/kimi-web/src/components/chat/Markdown.vue index 3e20657ddc..b86bc07750 100644 --- a/apps/kimi-web/src/components/chat/Markdown.vue +++ b/apps/kimi-web/src/components/chat/Markdown.vue @@ -12,6 +12,8 @@ import { clearMermaidWorker, } from 'markstream-vue'; import type { MarkdownIt } from 'markstream-vue'; +import { useKimiWebClient } from '../../composables/useKimiWebClient'; +import { configureMathRules } from '../../lib/markdownMath'; import { useIsDark } from '../../composables/useIsDark'; import type { FilePreviewRequest } from '../../types'; import { collectFilePathAliases, findFilePathLinks } from '../../lib/filePathLinks'; @@ -64,13 +66,15 @@ clearMermaidWorker(); setKaTeXWorker(new katexWorkerModule.default()); setMermaidWorker(new mermaidWorkerModule.default()); -// Only `$$…$$` display math is rendered; single `$` inline math is disabled so -// prices, env vars, and shell paths (`$5`, `$PATH`, `$HOME/bin`) stay literal -// without any escaping or code-detection gymnastics. `math_block` (the $$ rule) -// is left enabled. -function disableInlineMath(md: MarkdownIt): MarkdownIt { - md.inline.ruler.disable('math'); - return md; +// Only `$$…$$` display math (the `math_block` rule) is always rendered. +// Single-`$` inline math is OPT-IN (Settings → inline math): the rule can +// misdetect prices, env vars, and shell paths (`$5`, `$PATH`, `$HOME/bin`) +// as math and swallow them into a broken formula, so it stays disabled +// unless the user turns it on. The MarkdownRender instances are keyed on the +// preference below so toggling it re-parses the message. +const client = useKimiWebClient(); +function applyMathRules(md: MarkdownIt): MarkdownIt { + return configureMathRules(md, { inline: client.inlineMath.value }); } const { t } = useI18n(); @@ -433,8 +437,9 @@ function copyDiff(code: string, idx: number) { (); @@ -372,6 +376,14 @@ watch( + +