feat: inline LaTeX toggle

fixes #237
This commit is contained in:
Jing Hua 2023-04-17 17:36:34 +08:00
parent 62561e4e6c
commit 627e1cc03a
18 changed files with 56 additions and 2 deletions

View file

@ -25,6 +25,7 @@
"image": "Billede", "image": "Billede",
"autoTitle": "Auto generer titel", "autoTitle": "Auto generer titel",
"advancedMode": "Avanceret tilstand", "advancedMode": "Avanceret tilstand",
"inlineLatex": "Indlejret LaTeX",
"prompt": "Opgave", "prompt": "Opgave",
"promptLibrary": "Opgavebibliotek", "promptLibrary": "Opgavebibliotek",
"name": "Navn", "name": "Navn",

View file

@ -25,6 +25,7 @@
"image": "Image", "image": "Image",
"autoTitle": "Auto generate title", "autoTitle": "Auto generate title",
"advancedMode": "Advanced mode", "advancedMode": "Advanced mode",
"inlineLatex": "Inline Latex",
"prompt": "Prompt", "prompt": "Prompt",
"promptLibrary": "Prompt Library", "promptLibrary": "Prompt Library",
"name": "Name", "name": "Name",

View file

@ -25,6 +25,7 @@
"image": "Image", "image": "Image",
"autoTitle": "Auto generate title", "autoTitle": "Auto generate title",
"advancedMode": "Advanced mode", "advancedMode": "Advanced mode",
"inlineLatex": "Inline Latex",
"prompt": "Prompt", "prompt": "Prompt",
"promptLibrary": "Prompt Library", "promptLibrary": "Prompt Library",
"name": "Name", "name": "Name",

View file

@ -25,6 +25,7 @@
"image": "Imagen", "image": "Imagen",
"autoTitle": "Generar automáticamente el título de la conversación.", "autoTitle": "Generar automáticamente el título de la conversación.",
"advancedMode": "Modo avanzado", "advancedMode": "Modo avanzado",
"inlineLatex": "Latex en línea",
"prompt": "Prompt", "prompt": "Prompt",
"promptLibrary": "Librería de Prompts", "promptLibrary": "Librería de Prompts",
"name": "Nombre", "name": "Nombre",

View file

@ -25,6 +25,7 @@
"image": "Image", "image": "Image",
"autoTitle": "Générer le titre automatiquement", "autoTitle": "Générer le titre automatiquement",
"advancedMode": "Mode avancé", "advancedMode": "Mode avancé",
"inlineLatex": "Latex en ligne",
"prompt": "Incitation", "prompt": "Incitation",
"promptLibrary": "Bibliothèque de prompt", "promptLibrary": "Bibliothèque de prompt",
"name": "Nom", "name": "Nom",

View file

@ -25,6 +25,7 @@
"image": "Immagine", "image": "Immagine",
"autoTitle": "Genera automaticamente il titolo", "autoTitle": "Genera automaticamente il titolo",
"advancedMode": "Modalità avanzata", "advancedMode": "Modalità avanzata",
"inlineLatex": "Latex in linea",
"prompt": "Prompt", "prompt": "Prompt",
"promptLibrary": "Libreria Prompt", "promptLibrary": "Libreria Prompt",
"name": "Nome", "name": "Nome",

View file

@ -25,6 +25,7 @@
"image": "画像", "image": "画像",
"autoTitle": "タイトルを自動生成", "autoTitle": "タイトルを自動生成",
"advancedMode": "上級モード", "advancedMode": "上級モード",
"inlineLatex": "インライン LaTeX",
"prompt": "プロンプト", "prompt": "プロンプト",
"promptLibrary": "プロンプトライブラリ", "promptLibrary": "プロンプトライブラリ",
"name": "名前", "name": "名前",

View file

@ -25,6 +25,7 @@
"image": "Imej", "image": "Imej",
"autoTitle": "Jana tajuk secara automatik", "autoTitle": "Jana tajuk secara automatik",
"advancedMode": "Mod lanjutan", "advancedMode": "Mod lanjutan",
"inlineLatex": "Latex Sebaris",
"prompt": "Arahan", "prompt": "Arahan",
"promptLibrary": "Pustaka Arahan", "promptLibrary": "Pustaka Arahan",
"name": "Nama", "name": "Nama",

View file

@ -25,6 +25,7 @@
"image": "Bilde", "image": "Bilde",
"autoTitle": "Auto generer tittel", "autoTitle": "Auto generer tittel",
"advancedMode": "Avansert modus", "advancedMode": "Avansert modus",
"inlineLatex": "Inline Latex",
"prompt": "Oppgave", "prompt": "Oppgave",
"promptLibrary": "Oppgavebibliotek", "promptLibrary": "Oppgavebibliotek",
"name": "Navn", "name": "Navn",

View file

@ -25,6 +25,7 @@
"image": "Bild", "image": "Bild",
"autoTitle": "Auto generera titel", "autoTitle": "Auto generera titel",
"advancedMode": "Avancerat läge", "advancedMode": "Avancerat läge",
"inlineLatex": "Inline Latex",
"prompt": "Uppmaning", "prompt": "Uppmaning",
"promptLibrary": "Uppmaningsbibliotek", "promptLibrary": "Uppmaningsbibliotek",
"name": "Namn", "name": "Namn",

View file

@ -25,6 +25,7 @@
"image": "图片", "image": "图片",
"autoTitle": "自动生成标题", "autoTitle": "自动生成标题",
"advancedMode": "高级模式", "advancedMode": "高级模式",
"inlineLatex": "行内 Latex",
"prompt": "提示词", "prompt": "提示词",
"promptLibrary": "提示词资料库", "promptLibrary": "提示词资料库",
"name": "名称", "name": "名称",

View file

@ -25,6 +25,7 @@
"image": "圖片", "image": "圖片",
"autoTitle": "自動生成標題", "autoTitle": "自動生成標題",
"advancedMode": "高級模式", "advancedMode": "高級模式",
"inlineLatex": "行內 Latex",
"prompt": "Prompt", "prompt": "Prompt",
"promptLibrary": "Prompt 資料庫", "promptLibrary": "Prompt 資料庫",
"name": "名", "name": "名",

View file

@ -25,6 +25,7 @@
"image": "圖片", "image": "圖片",
"autoTitle": "自動生成標題", "autoTitle": "自動生成標題",
"advancedMode": "高級模式", "advancedMode": "高級模式",
"inlineLatex": "行內 Latex",
"prompt": "提示詞", "prompt": "提示詞",
"promptLibrary": "提示詞資料庫", "promptLibrary": "提示詞資料庫",
"name": "名稱", "name": "名稱",

View file

@ -86,6 +86,7 @@ const ContentView = React.memo(
const lastMessageIndex = useStore((state) => const lastMessageIndex = useStore((state) =>
state.chats ? state.chats[state.currentChatIndex].messages.length - 1 : 0 state.chats ? state.chats[state.currentChatIndex].messages.length - 1 : 0
); );
const inlineLatex = useStore((state) => state.inlineLatex);
const handleDelete = () => { const handleDelete = () => {
const updatedChats: ChatInterface[] = JSON.parse( const updatedChats: ChatInterface[] = JSON.parse(
@ -139,7 +140,7 @@ const ContentView = React.memo(
<ReactMarkdown <ReactMarkdown
remarkPlugins={[ remarkPlugins={[
remarkGfm, remarkGfm,
[remarkMath, { singleDollarTextMath: false }], [remarkMath, { singleDollarTextMath: inlineLatex }],
]} ]}
rehypePlugins={[ rehypePlugins={[
rehypeKatex, rehypeKatex,

View file

@ -0,0 +1,28 @@
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import useStore from '@store/store';
import Toggle from '@components/Toggle';
const InlineLatexToggle = () => {
const { t } = useTranslation();
const setInlineLatex = useStore((state) => state.setInlineLatex);
const [isChecked, setIsChecked] = useState<boolean>(
useStore.getState().inlineLatex
);
useEffect(() => {
setInlineLatex(isChecked);
}, [isChecked]);
return (
<Toggle
label={t('inlineLatex') as string}
isChecked={isChecked}
setIsChecked={setIsChecked}
/>
);
};
export default InlineLatexToggle;

View file

@ -9,11 +9,12 @@ import ThemeSwitcher from '@components/Menu/MenuOptions/ThemeSwitcher';
import LanguageSelector from '@components/LanguageSelector'; import LanguageSelector from '@components/LanguageSelector';
import AutoTitleToggle from './AutoTitleToggle'; import AutoTitleToggle from './AutoTitleToggle';
import AdvancedModeToggle from './AdvencedModeToggle'; import AdvancedModeToggle from './AdvencedModeToggle';
import InlineLatexToggle from './InlineLatexToggle';
import PromptLibraryMenu from '@components/PromptLibraryMenu'; import PromptLibraryMenu from '@components/PromptLibraryMenu';
import ChatConfigMenu from '@components/ChatConfigMenu'; import ChatConfigMenu from '@components/ChatConfigMenu';
import EnterToSubmitToggle from './EnterToSubmitToggle'; import EnterToSubmitToggle from './EnterToSubmitToggle';
const SettingsMenu = () => { const SettingsMenu = () => {
const { t } = useTranslation(); const { t } = useTranslation();
@ -45,6 +46,7 @@ const SettingsMenu = () => {
<div className='flex flex-col gap-3'> <div className='flex flex-col gap-3'>
<AutoTitleToggle /> <AutoTitleToggle />
<EnterToSubmitToggle /> <EnterToSubmitToggle />
<InlineLatexToggle />
<AdvancedModeToggle /> <AdvancedModeToggle />
</div> </div>
<PromptLibraryMenu /> <PromptLibraryMenu />

View file

@ -13,6 +13,7 @@ export interface ConfigSlice {
defaultSystemMessage: string; defaultSystemMessage: string;
hideSideMenu: boolean; hideSideMenu: boolean;
enterToSubmit: boolean; enterToSubmit: boolean;
inlineLatex: boolean;
setOpenConfig: (openConfig: boolean) => void; setOpenConfig: (openConfig: boolean) => void;
setTheme: (theme: Theme) => void; setTheme: (theme: Theme) => void;
setAutoTitle: (autoTitle: boolean) => void; setAutoTitle: (autoTitle: boolean) => void;
@ -22,6 +23,7 @@ export interface ConfigSlice {
setHideMenuOptions: (hideMenuOptions: boolean) => void; setHideMenuOptions: (hideMenuOptions: boolean) => void;
setHideSideMenu: (hideSideMenu: boolean) => void; setHideSideMenu: (hideSideMenu: boolean) => void;
setEnterToSubmit: (enterToSubmit: boolean) => void; setEnterToSubmit: (enterToSubmit: boolean) => void;
setInlineLatex: (inlineLatex: boolean) => void;
} }
export const createConfigSlice: StoreSlice<ConfigSlice> = (set, get) => ({ export const createConfigSlice: StoreSlice<ConfigSlice> = (set, get) => ({
@ -34,6 +36,7 @@ export const createConfigSlice: StoreSlice<ConfigSlice> = (set, get) => ({
advancedMode: true, advancedMode: true,
defaultChatConfig: _defaultChatConfig, defaultChatConfig: _defaultChatConfig,
defaultSystemMessage: _defaultSystemMessage, defaultSystemMessage: _defaultSystemMessage,
inlineLatex: false,
setOpenConfig: (openConfig: boolean) => { setOpenConfig: (openConfig: boolean) => {
set((prev: ConfigSlice) => ({ set((prev: ConfigSlice) => ({
...prev, ...prev,
@ -88,4 +91,10 @@ export const createConfigSlice: StoreSlice<ConfigSlice> = (set, get) => ({
enterToSubmit: enterToSubmit, enterToSubmit: enterToSubmit,
})); }));
}, },
setInlineLatex: (inlineLatex: boolean) => {
set((prev: ConfigSlice) => ({
...prev,
inlineLatex: inlineLatex,
}));
},
}); });

View file

@ -55,6 +55,7 @@ export const createPartializedState = (state: StoreState) => ({
hideSideMenu: state.hideSideMenu, hideSideMenu: state.hideSideMenu,
folders: state.folders, folders: state.folders,
enterToSubmit: state.enterToSubmit, enterToSubmit: state.enterToSubmit,
inlineLatex: state.inlineLatex,
}); });
const useStore = create<StoreState>()( const useStore = create<StoreState>()(