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.
14 lines
442 B
TypeScript
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
|
|
} |