✏️ feat: LaTeX parsing for Messages (#1585)

* feat: Beta features tab in Settings and LaTeX Parsing toggle

* feat: LaTex parsing with spec
This commit is contained in:
Danny Avila 2024-01-18 14:44:10 -05:00 committed by GitHub
parent 638f9242e5
commit a8d6bfde7a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 291 additions and 22 deletions

View file

@ -1,3 +1,4 @@
import { useRecoilValue } from 'recoil';
import React, { useState, useEffect } from 'react';
import type { TMessage } from 'librechat-data-provider';
import rehypeHighlight from 'rehype-highlight';
@ -8,9 +9,10 @@ import rehypeKatex from 'rehype-katex';
import remarkMath from 'remark-math';
import remarkGfm from 'remark-gfm';
import rehypeRaw from 'rehype-raw';
import { useChatContext } from '~/Providers';
import { langSubset, validateIframe } from '~/utils';
import CodeBlock from '~/components/Messages/Content/CodeBlock';
import { langSubset, validateIframe, processLaTeX } from '~/utils';
import { useChatContext } from '~/Providers';
import store from '~/store';
type TCodeProps = {
inline: boolean;
@ -42,11 +44,15 @@ const p = React.memo(({ children }: { children: React.ReactNode }) => {
const Markdown = React.memo(({ content, message, showCursor }: TContentProps) => {
const [cursor, setCursor] = useState('█');
const { isSubmitting, latestMessage } = useChatContext();
const LaTeXParsing = useRecoilValue<boolean>(store.LaTeXParsing);
const isInitializing = content === '<span className="result-streaming">█</span>';
const { isEdited, messageId } = message ?? {};
const isLatestMessage = messageId === latestMessage?.messageId;
const currentContent = content?.replace('z-index: 1;', '') ?? '';
const _content = content?.replace('z-index: 1;', '') ?? '';
const currentContent = LaTeXParsing ? processLaTeX(_content) : _content;
useEffect(() => {
let timer1: NodeJS.Timeout, timer2: NodeJS.Timeout;