feat: Add support for LaTeX environments
Support `equation` and `align` environments for LaTeX. This change enables us to handle more complex LaTeX expressions, including those within environments. By replacing the delimiters for these environments with the appropriate MathJax equivalents, we ensure consistent rendering of mathematical equations within the application.
This commit is contained in:
parent
55e22ebc48
commit
29169f8de1
@ -1,14 +1,19 @@
|
||||
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
|
||||
let processedContent = content.replace(
|
||||
/\\\[([\s\S]*?)\\\]/g,
|
||||
(_, equation) => `$$${equation}$$`
|
||||
);
|
||||
processedContent = processedContent.replace(
|
||||
/\\\(([\s\S]*?)\\\)/g,
|
||||
(_, equation) => `$${equation}$`
|
||||
);
|
||||
processedContent = processedContent.replace(
|
||||
/\\begin\{equation\}([\s\S]*?)\\end\{equation\}/g,
|
||||
(_, equation) => `$$${equation}$$`
|
||||
);
|
||||
processedContent = processedContent.replace(
|
||||
/\\begin\{align\}([\s\S]*?)\\end\{align\}/g,
|
||||
(_, equation) => `$$\\begin{aligned}${equation}\\end{aligned}$$`
|
||||
);
|
||||
return processedContent;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user