page-assist/src/utils/latex.ts
n4ze3m 55e22ebc48 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.
2024-11-03 23:39:42 +05:30

14 lines
442 B
TypeScript

export const preprocessLaTeX = (content: string) => {
// Replace block-level LaTeX delimiters \[ \] with $$ $$
const blockProcessedContent = content.replace(
/\\\[(.*?)\\\]/gs,
(_, equation) => `$$${equation}$$`
)
// Replace inline LaTeX delimiters \( \) with $ $
const inlineProcessedContent = blockProcessedContent.replace(
/\\\((.*?)\\\)/gs,
(_, equation) => `$${equation}$`
)
return inlineProcessedContent
}