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) => {
|
export const preprocessLaTeX = (content: string) => {
|
||||||
|
// Replace block-level LaTeX delimiters \[ \] with $$ $$
|
||||||
|
|
||||||
let processedContent = content.replace(
|
const blockProcessedContent = content.replace(
|
||||||
/\\\[(.*?)\\\]/gs,
|
/\\\[(.*?)\\\]/gs,
|
||||||
(_, equation) => `$$${equation}$$`
|
(_, equation) => `$$${equation}$$`
|
||||||
)
|
)
|
||||||
|
// Replace inline LaTeX delimiters \( \) with $ $
|
||||||
processedContent = processedContent.replace(
|
const inlineProcessedContent = blockProcessedContent.replace(
|
||||||
/\\\((.*?)\\\)/gs,
|
/\\\((.*?)\\\)/gs,
|
||||||
(_, equation) => `$${equation}$`
|
(_, equation) => `$${equation}$`
|
||||||
)
|
)
|
||||||
|
return inlineProcessedContent
|
||||||
processedContent = processedContent.replace(
|
|
||||||
/\$(\d)/g,
|
|
||||||
'\\$$1'
|
|
||||||
)
|
|
||||||
|
|
||||||
return processedContent
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user