Browse Source

fix: 修复neq和ne的公式

过卫栋 6 days ago
parent
commit
a3b27dbebd
1 changed files with 2 additions and 1 deletions
  1. 2 1
      scripts/katex-render.mjs

+ 2 - 1
scripts/katex-render.mjs

@@ -138,7 +138,8 @@ function processDelimiter(html, left, right, displayMode) {
             }
 
             // 【修复】处理公式内的换行符:将 \n 替换成空格,避免破坏公式
-            cleanLatex = cleanLatex.replace(/\\n/g, ' ').replace(/\n/g, ' ');
+            // 使用负向前瞻 (?![a-zA-Z]) 避免误伤 LaTeX 命令如 \neq, \ne, \newline, \nu 等
+            cleanLatex = cleanLatex.replace(/\\n(?![a-zA-Z])/g, ' ').replace(/\n/g, ' ');
 
             // 渲染 KaTeX
             const rendered = katex.renderToString(cleanLatex, {