mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-08-01 21:37:33 +08:00
fix: normalize double-escaped LaTeX backslashes and HTML entities (#14564)
Fixes #14562 ## Problem LLMs like DeepSeek V4 Flash and Qwen3-MAX return \\( and \\[ (double backslash) in LaTeX output. The preprocessLaTeX() function only handled single backslash delimiters, so equations showed as raw text. HTML entities like < and > were also not decoded. ## Solution Added normalization step before existing delimiter conversion: - \\( → \( and \\[ → \[ - < → < and > → > and & → & --------- Co-authored-by: Vivek <viveksantoshkumardubey@email.com>
This commit is contained in:
26
web/src/utils/tests/chat.test.ts
Normal file
26
web/src/utils/tests/chat.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { preprocessLaTeX } from '../chat';
|
||||
|
||||
test('handles double-escaped inline LaTeX', () => {
|
||||
const result = preprocessLaTeX('\\\\(\\\\Delta = b^2\\\\)');
|
||||
expect(result).toBe('$\\Delta = b^2$');
|
||||
});
|
||||
|
||||
test('handles double-escaped block LaTeX', () => {
|
||||
const result = preprocessLaTeX('\\\\[E = mc^2\\\\]');
|
||||
expect(result).toBe('$$E = mc^2$$');
|
||||
});
|
||||
|
||||
test('decodes HTML entities', () => {
|
||||
const result = preprocessLaTeX('a < b & c > d');
|
||||
expect(result).toBe('a < b & c > d');
|
||||
});
|
||||
|
||||
test('handles mixed double-escaped delimiters with HTML entities', () => {
|
||||
const result = preprocessLaTeX('\\\\(x < y\\\\)');
|
||||
expect(result).toBe('$x < y$');
|
||||
});
|
||||
|
||||
test('passes through already correct single-escaped delimiters unchanged', () => {
|
||||
const result = preprocessLaTeX('\\(x = 1\\)');
|
||||
expect(result).toBe('$x = 1$');
|
||||
});
|
||||
Reference in New Issue
Block a user