mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-06-02 11:09:20 +02:00
parent
0460531c72
commit
62302e3faf
@ -60,17 +60,25 @@ export function extractCodeText(
|
|||||||
return codeText || "";
|
return codeText || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a temporary solution to preprocess LaTeX in LLM output
|
// We must preprocess LaTeX in the LLM output to avoid improper formatting
|
||||||
export const preprocessLaTeX = (content: string) => {
|
export const preprocessLaTeX = (content: string) => {
|
||||||
// Replace block-level LaTeX delimiters \[ \] with $$ $$
|
// 1) Escape dollar signs used outside of LaTeX context
|
||||||
const blockProcessedContent = content.replace(
|
const escapedCurrencyContent = content.replace(
|
||||||
|
/\$(\d+(?:\.\d*)?)/g,
|
||||||
|
(_, p1) => `\\$${p1}`
|
||||||
|
);
|
||||||
|
|
||||||
|
// 2) Replace block-level LaTeX delimiters \[ \] with $$ $$
|
||||||
|
const blockProcessedContent = escapedCurrencyContent.replace(
|
||||||
/\\\[([\s\S]*?)\\\]/g,
|
/\\\[([\s\S]*?)\\\]/g,
|
||||||
(_, equation) => `$$${equation}$$`
|
(_, equation) => `$$${equation}$$`
|
||||||
);
|
);
|
||||||
// Replace inline LaTeX delimiters \( \) with $ $
|
|
||||||
|
// 3) Replace inline LaTeX delimiters \( \) with $ $
|
||||||
const inlineProcessedContent = blockProcessedContent.replace(
|
const inlineProcessedContent = blockProcessedContent.replace(
|
||||||
/\\\(([\s\S]*?)\\\)/g,
|
/\\\(([\s\S]*?)\\\)/g,
|
||||||
(_, equation) => `$${equation}$`
|
(_, equation) => `$${equation}$`
|
||||||
);
|
);
|
||||||
|
|
||||||
return inlineProcessedContent;
|
return inlineProcessedContent;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user