Skip to content

Commit

Permalink
feat: Add support for LaTeX environments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
n4ze3m committed Nov 3, 2024
1 parent 55e22eb commit 29169f8
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/utils/latex.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 29169f8

Please sign in to comment.