Skip to content

Commit cc6fb5b

Browse files
fix(chat): fix issues with LaTeX rendering (Issue #2925) (#3741)
1 parent c1e7a05 commit cc6fb5b

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

apps/chat/src/components/Markdown/ChatMDComponent.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ import { PluggableList } from 'react-markdown/lib/react-markdown';
33

44
import classnames from 'classnames';
55

6+
import { useScreenState } from '@/src/hooks/useScreenState';
7+
68
import { getMappedAttachmentUrl } from '@/src/utils/app/attachments';
7-
import { convertLaTeXToMarkdownMath } from '@/src/utils/converters';
9+
import { convertLaTeXToMarkdownMath } from '@/src/utils/app/converters';
10+
11+
import { ScreenState } from '@/src/types/common';
812

913
import { useAppSelector } from '@/src/store/hooks';
1014
import { SettingsSelectors } from '@/src/store/settings/settings.reducers';
@@ -118,10 +122,13 @@ const ChatMDComponent = ({
118122
const isChatFullWidth = useAppSelector(UISelectors.selectIsChatFullWidth);
119123
const isOverlay = useAppSelector(SettingsSelectors.selectIsOverlay);
120124

125+
const screenState = useScreenState();
126+
121127
const mdClassNames = classnames(
122-
'prose min-w-full leading-[150%] dark:prose-invert prose-a:text-primary prose-a:underline',
128+
'prose min-w-full dark:prose-invert prose-a:text-primary prose-a:underline',
123129
isChatFullWidth && 'max-w-none',
124-
isOverlay ? 'text-sm' : 'md:leading-normal',
130+
isOverlay && 'text-sm',
131+
(screenState === ScreenState.SM || isOverlay) && 'leading-[150%]',
125132
);
126133

127134
const processedContent = convertLaTeXToMarkdownMath(content);

apps/chat/src/styles/globals.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,7 @@ pre:has(div.codeblock) {
231231
min-height: calc(var(--vh, 1vh) * 100);
232232
height: calc(var(--vh, 1vh) * 100);
233233
}
234+
235+
span.katex-mathml {
236+
display: none;
237+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
export const convertLaTeXToMarkdownMath = (content: string) => {
22
const transformedContent = content.replace(
33
/\\\[([\s\S]*?)\\\]/g,
4-
(_, mathContent) => `$$$$ ${mathContent} $$$$`,
4+
(_, mathContent: string) => `$$\n${mathContent.trim()}\n$$`,
55
);
66

77
return transformedContent.replace(
88
/\\\((.*?)\\\)/g,
9-
(_, inlineMathContent) => `$$ ${inlineMathContent} $$`,
9+
(_, inlineMathContent: string) => `$${inlineMathContent.trim()}$`,
1010
);
1111
};

0 commit comments

Comments
 (0)