Repository navigation
侧边栏和摘读记录:AI 回答里的 LaTeX 公式渲染成数学式 - #464
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
侧边栏和摘读记录里,AI 回答中的 LaTeX 公式原样显示成一串代码,例如问卷积池化时的
\[ \begin{bmatrix} 1 & 3\\ 4 & 6 \end{bmatrix} \](#462 的截图)。现在显示成矩阵和公式。renderMarkdown之前不认公式。浏览器只认 MathML、不认 LaTeX,所以加了 Temml 0.14.0(MIT,vendor/里三个文件共约 180KB)把 LaTeX 转成 MathML,由 Chrome 自己画。没用 KaTeX:它要自带字体,整包约 600KB;Temml 用系统的数学字体,macOS 和 Windows 都有。ChatGPT、Gemini 用的是 KaTeX,Temml 是它专为输出 MathML 做的分支,语法覆盖相同。认
$$…$$、\[…\](独占一行)和\(…\)、$…$(行内)。公式在转义 HTML 之前取出,代码块和行内代码里的不动。单个$只在紧贴内容、且结尾的$后面不是数字或字母时才算,所以「$5 和 $10」不变。流式输出中没闭合的公式先按原文显示;没闭合的代码块里的不渲染;\[遇到空行就不再往下找。Temml 抛错(例如递归宏撑爆调用栈)时该公式保留原文,回答照常显示。很宽的式子在气泡内横向滚动。只在加载了 Temml 的侧边栏和摘读记录生效。已知没处理:模型用
\[1\]转义方括号写引用时会被当成公式(ChatGPT 的前端同样如此)。写入 Obsidian 的笔记里公式仍是\[…\]原文,Obsidian 只认$…$,另做。验证:
node scripts/selftest.mjs48 个通过,撤掉note.js的改动新测试会失败。node scripts/smoke.mjs通过(macOS,Chrome 无头)。把 #462 的原文交给renderMarkdown,在无头 Chrome 里用侧边栏的样式截图,两个矩阵、行内2×2和超宽求和式都正常。没测:真实侧边栏里的流式回答,Windows 和 Linux 上的字体。Closes #462