Przeglądaj źródła

fix: \\\\CD无法处理问题

过卫栋 3 tygodni temu
rodzic
commit
c62e59c92d
1 zmienionych plików z 5 dodań i 3 usunięć
  1. 5 3
      app/Services/MathFormulaProcessor.php

+ 5 - 3
app/Services/MathFormulaProcessor.php

@@ -79,11 +79,13 @@ class MathFormulaProcessor
      */
     private static function normalizeBackslashesInDelimiters(string $content): string
     {
-        // 只替换 \\+字母 的情况(被JSON转义的LaTeX命令)
+        // 只替换 \\+小写字母 的情况(被JSON转义的LaTeX命令,如 \\sqrt -> \sqrt)
+        // 保留 \\+大写字母 的情况(换行符后跟文本,如 \\CD 应保持为 \\CD)
         // 保留 \\+数字 或 \\+空白 的情况(矩阵换行符)
         $fixEscapedCommands = function ($tex) {
-            // \\sqrt -> \sqrt, \\frac -> \frac, 但 \\2 或 \\ 保持不变
-            return preg_replace('/\\\\\\\\([a-zA-Z])/', '\\\\$1', $tex);
+            // \\sqrt -> \sqrt, \\frac -> \frac, 但 \\CD 或 \\2 保持不变
+            // 【修复】只匹配小写字母,因为 LaTeX 命令都是小写
+            return preg_replace('/\\\\\\\\([a-z])/', '\\\\$1', $tex);
         };
 
         // 1. 处理 $$...$$ 块级公式