Fix: Improve LaTeX preprocessing logic
The previous LaTeX preprocessing logic had a bug that could lead to incorrect rendering of mathematical equations. This commit refactors the logic to ensure that both block-level and inline equations are properly handled, improving the accuracy of LaTeX rendering in the application.
This commit is contained in:
parent
65ba2ff898
commit
55e22ebc48
@ -1,19 +1,14 @@
|
||||
export const preprocessLaTeX = (content: string) => {
|
||||
// Replace block-level LaTeX delimiters \[ \] with $$ $$
|
||||
|
||||
let processedContent = content.replace(
|
||||
/\\\[(.*?)\\\]/gs,
|
||||
(_, equation) => `$$${equation}$$`
|
||||
)
|
||||
|
||||
processedContent = processedContent.replace(
|
||||
/\\\((.*?)\\\)/gs,
|
||||
(_, equation) => `$${equation}$`
|
||||
)
|
||||
|
||||
processedContent = processedContent.replace(
|
||||
/\$(\d)/g,
|
||||
'\\$$1'
|
||||
)
|
||||
|
||||
return processedContent
|
||||
const blockProcessedContent = content.replace(
|
||||
/\\\[(.*?)\\\]/gs,
|
||||
(_, equation) => `$$${equation}$$`
|
||||
)
|
||||
// Replace inline LaTeX delimiters \( \) with $ $
|
||||
const inlineProcessedContent = blockProcessedContent.replace(
|
||||
/\\\((.*?)\\\)/gs,
|
||||
(_, equation) => `$${equation}$`
|
||||
)
|
||||
return inlineProcessedContent
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user