diff --git a/src/renderer/src/i18n/locales/en-us.json b/src/renderer/src/i18n/locales/en-us.json
index a4b167bd..42a2d79a 100644
--- a/src/renderer/src/i18n/locales/en-us.json
+++ b/src/renderer/src/i18n/locales/en-us.json
@@ -709,6 +709,8 @@
"markdown_export.path_placeholder": "Export Path",
"markdown_export.select": "Select",
"markdown_export.help": "If provided, exports will be automatically saved to this path; otherwise, a save dialog will appear.",
+ "markdown_export.force_dollar_math.title": "Force $$ for LaTeX formulas",
+ "markdown_export.force_dollar_math.help": "When enabled, $$ will be forcibly used to mark LaTeX formulas when exporting to Markdown. Note: This option also affects all export methods through Markdown, such as Notion, Yuque, etc.",
"notion.api_key": "Notion API Key",
"notion.api_key_placeholder": "Enter Notion API Key",
"notion.auto_split": "Auto split when exporting",
@@ -1089,4 +1091,4 @@
"visualization": "Visualization"
}
}
-}
\ No newline at end of file
+}
diff --git a/src/renderer/src/i18n/locales/ja-jp.json b/src/renderer/src/i18n/locales/ja-jp.json
index c214811b..fb59f13e 100644
--- a/src/renderer/src/i18n/locales/ja-jp.json
+++ b/src/renderer/src/i18n/locales/ja-jp.json
@@ -709,6 +709,8 @@
"markdown_export.path_placeholder": "エクスポートパス",
"markdown_export.select": "選択",
"markdown_export.help": "入力された場合、エクスポート時に自動的にこのパスに保存されます。未入力の場合、保存ダイアログが表示されます。",
+ "markdown_export.force_dollar_math.title": "LaTeX数式に$$を強制使用",
+ "markdown_export.force_dollar_math.help": "有効にすると、Markdownにエクスポートする際にLaTeX数式を$$で強制的にマークします。注意:この設定はNotion、Yuqueなど、Markdownを通じたすべてのエクスポート方法にも影響します。",
"notion.api_key": "Notion APIキー",
"notion.api_key_placeholder": "Notion APIキーを入力してください",
"notion.auto_split": "ダイアログをエクスポートすると自動ページ分割",
@@ -1089,4 +1091,4 @@
"visualization": "可視化"
}
}
-}
\ No newline at end of file
+}
diff --git a/src/renderer/src/i18n/locales/ru-ru.json b/src/renderer/src/i18n/locales/ru-ru.json
index c9472887..dd4bc77a 100644
--- a/src/renderer/src/i18n/locales/ru-ru.json
+++ b/src/renderer/src/i18n/locales/ru-ru.json
@@ -709,6 +709,8 @@
"markdown_export.path_placeholder": "Путь экспорта",
"markdown_export.select": "Выбрать",
"markdown_export.help": "Если указано, файлы будут автоматически сохраняться в этот путь; в противном случае появится диалоговое окно сохранения.",
+ "markdown_export.force_dollar_math.title": "Принудительно использовать $$ для формул LaTeX",
+ "markdown_export.force_dollar_math.help": "Если включено, при экспорте в Markdown для обозначения формул LaTeX будет принудительно использоваться $$. Примечание: Эта опция также влияет на все методы экспорта через Markdown, такие как Notion, Yuque и т.д.",
"notion.api_key": "Ключ API Notion",
"notion.api_key_placeholder": "Введите ключ API Notion",
"notion.auto_split": "Автоматическое разбиение на страницы при экспорте диалога",
@@ -1089,4 +1091,4 @@
"visualization": "Визуализация"
}
}
-}
\ No newline at end of file
+}
diff --git a/src/renderer/src/i18n/locales/zh-cn.json b/src/renderer/src/i18n/locales/zh-cn.json
index 3ad77645..0444d346 100644
--- a/src/renderer/src/i18n/locales/zh-cn.json
+++ b/src/renderer/src/i18n/locales/zh-cn.json
@@ -709,6 +709,8 @@
"markdown_export.path_placeholder": "导出路径",
"markdown_export.select": "选择",
"markdown_export.help": "若填入,则每次导出时将自动保存到该路径;否则,将弹出保存对话框",
+ "markdown_export.force_dollar_math.title": "强制使用$$来标记LaTeX公式",
+ "markdown_export.force_dollar_math.help": "开启后,导出Markdown时会将强制使用$$来标记LaTeX公式。注意:该项也会影响所有通过Markdown导出的方式,如Notion、语雀等。",
"notion.api_key": "Notion 密钥",
"notion.api_key_placeholder": "请输入Notion 密钥",
"notion.auto_split": "导出对话时自动分页",
@@ -1089,4 +1091,4 @@
"visualization": "可视化"
}
}
-}
\ No newline at end of file
+}
diff --git a/src/renderer/src/i18n/locales/zh-tw.json b/src/renderer/src/i18n/locales/zh-tw.json
index e91f4fd0..e93ef51c 100644
--- a/src/renderer/src/i18n/locales/zh-tw.json
+++ b/src/renderer/src/i18n/locales/zh-tw.json
@@ -709,6 +709,8 @@
"markdown_export.path_placeholder": "匯出路徑",
"markdown_export.select": "選擇",
"markdown_export.help": "若填入,每次匯出時將自動儲存至該路徑;否則,將彈出儲存對話框。",
+ "markdown_export.force_dollar_math.title": "LaTeX公式強制使用$$",
+ "markdown_export.force_dollar_math.help": "開啟後,匯出Markdown時會強制使用$$來標記LaTeX公式。注意:該項也會影響所有透過Markdown匯出的方式,如Notion、語雀等。",
"notion.api_key": "Notion 金鑰",
"notion.api_key_placeholder": "請輸入 Notion 金鑰",
"notion.auto_split": "匯出對話時自動分頁",
@@ -1089,4 +1091,4 @@
"visualization": "視覺化"
}
}
-}
\ No newline at end of file
+}
diff --git a/src/renderer/src/pages/settings/DataSettings/MarkdownExportSettings.tsx b/src/renderer/src/pages/settings/DataSettings/MarkdownExportSettings.tsx
index f2e1cec4..65eae380 100644
--- a/src/renderer/src/pages/settings/DataSettings/MarkdownExportSettings.tsx
+++ b/src/renderer/src/pages/settings/DataSettings/MarkdownExportSettings.tsx
@@ -2,8 +2,8 @@ import { DeleteOutlined, FolderOpenOutlined } from '@ant-design/icons'
import { HStack } from '@renderer/components/Layout'
import { useTheme } from '@renderer/context/ThemeProvider'
import { RootState, useAppDispatch } from '@renderer/store'
-import { setmarkdownExportPath } from '@renderer/store/settings'
-import { Button } from 'antd'
+import { setForceDollarMathInMarkdown, setmarkdownExportPath } from '@renderer/store/settings'
+import { Button, Switch } from 'antd'
import Input from 'antd/es/input/Input'
import { FC } from 'react'
import { useTranslation } from 'react-i18next'
@@ -17,6 +17,7 @@ const MarkdownExportSettings: FC = () => {
const dispatch = useAppDispatch()
const markdownExportPath = useSelector((state: RootState) => state.settings.markdownExportPath)
+ const forceDollarMathInMarkdown = useSelector((state: RootState) => state.settings.forceDollarMathInMarkdown)
const handleSelectFolder = async () => {
const path = await window.api.file.selectFolder()
@@ -29,6 +30,10 @@ const MarkdownExportSettings: FC = () => {
dispatch(setmarkdownExportPath(null))
}
+ const handleToggleForceDollarMath = (checked: boolean) => {
+ dispatch(setForceDollarMathInMarkdown(checked))
+ }
+
return (
{t('settings.data.markdown_export.title')}
@@ -56,6 +61,14 @@ const MarkdownExportSettings: FC = () => {
{t('settings.data.markdown_export.help')}
+
+
+ {t('settings.data.markdown_export.force_dollar_math.title')}
+
+
+
+ {t('settings.data.markdown_export.force_dollar_math.help')}
+
)
}
diff --git a/src/renderer/src/store/settings.ts b/src/renderer/src/store/settings.ts
index 651e0e4d..ae90d919 100644
--- a/src/renderer/src/store/settings.ts
+++ b/src/renderer/src/store/settings.ts
@@ -75,6 +75,7 @@ export interface SettingsState {
notionApiKey: string | null
notionPageNameKey: string | null
markdownExportPath: string | null
+ forceDollarMathInMarkdown: boolean
thoughtAutoCollapse: boolean
notionAutoSplit: boolean
notionSplitSize: number
@@ -143,6 +144,7 @@ const initialState: SettingsState = {
notionApiKey: '',
notionPageNameKey: 'Name',
markdownExportPath: null,
+ forceDollarMathInMarkdown: false,
thoughtAutoCollapse: true,
notionAutoSplit: false,
notionSplitSize: 90,
@@ -325,6 +327,9 @@ const settingsSlice = createSlice({
setmarkdownExportPath: (state, action: PayloadAction) => {
state.markdownExportPath = action.payload
},
+ setForceDollarMathInMarkdown: (state, action: PayloadAction) => {
+ state.forceDollarMathInMarkdown = action.payload
+ },
setThoughtAutoCollapse: (state, action: PayloadAction) => {
state.thoughtAutoCollapse = action.payload
},
@@ -407,6 +412,7 @@ export const {
setNotionApiKey,
setNotionPageNameKey,
setmarkdownExportPath,
+ setForceDollarMathInMarkdown,
setThoughtAutoCollapse,
setNotionAutoSplit,
setNotionSplitSize,
diff --git a/src/renderer/src/utils/export.ts b/src/renderer/src/utils/export.ts
index 01086b35..0046d81e 100644
--- a/src/renderer/src/utils/export.ts
+++ b/src/renderer/src/utils/export.ts
@@ -5,14 +5,15 @@ import { getMessageTitle } from '@renderer/services/MessagesService'
import store from '@renderer/store'
import { setExportState } from '@renderer/store/runtime'
import { Message, Topic } from '@renderer/types'
-import { removeSpecialCharactersForFileName } from '@renderer/utils/index'
+import { convertMathFormula, removeSpecialCharactersForFileName } from '@renderer/utils/index'
import { markdownToBlocks } from '@tryfabric/martian'
import dayjs from 'dayjs'
export const messageToMarkdown = (message: Message) => {
+ const { forceDollarMathInMarkdown } = store.getState().settings
const roleText = message.role === 'user' ? '🧑💻 User' : '🤖 Assistant'
const titleSection = `### ${roleText}`
- const contentSection = message.content
+ const contentSection = forceDollarMathInMarkdown ? convertMathFormula(message.content) : message.content
return [titleSection, '', contentSection].join('\n')
}
diff --git a/src/renderer/src/utils/index.ts b/src/renderer/src/utils/index.ts
index c17a922b..7684c78b 100644
--- a/src/renderer/src/utils/index.ts
+++ b/src/renderer/src/utils/index.ts
@@ -246,8 +246,12 @@ export function loadScript(url: string) {
}
export function convertMathFormula(input) {
- // 使用正则表达式匹配并替换公式格式
- return input.replaceAll(/\\\[/g, '$$$$').replaceAll(/\\\]/g, '$$$$')
+ if (!input) return input
+
+ let result = input
+ result = result.replaceAll('\\[', '$$$$').replaceAll('\\]', '$$$$')
+ result = result.replaceAll('\\(', '$$').replaceAll('\\)', '$$')
+ return result
}
export function getBriefInfo(text: string, maxLength: number = 50): string {