Skip to content

Commit 8be7cef

Browse files
da-liiiclaude
andauthored
[0130] 移除工具菜单中的 LaTeX 子菜单 (#3374)
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 3efc8ef commit 8be7cef

5 files changed

Lines changed: 59 additions & 121 deletions

File tree

TeXmacs/plugins/latex/progs/convert/latex/tmtex-widgets.scm

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -113,62 +113,3 @@
113113
(texmacs-input (string->document doc)
114114
`(style (tuple "verbatim-source"))
115115
(latex-source-buffer))))))
116-
117-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
118-
;; Convert, run pdflatex, and examine errors
119-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
120-
121-
(define (current-buffer-suffixed suf)
122-
(and (url-exists? (current-buffer))
123-
(buffer-has-name? (current-buffer))
124-
(let* ((tm (current-buffer))
125-
(nr (string-length (url-suffix tm)))
126-
(tex (url-glue (url-unglue tm nr) suf)))
127-
(and (== (url-suffix tm) "tm") tex))))
128-
129-
(define (latex-export)
130-
(with tex (current-buffer-suffixed "tex")
131-
(if (not tex)
132-
(set-message "TeXmacs buffer on disk expected" "latex-export")
133-
(export-buffer tex))))
134-
135-
(define (latex-run)
136-
(cond ((not (url-exists? (current-buffer)))
137-
(set-message "buffer must be on disk" "latex-run"))
138-
((not (buffer-has-name? (current-buffer)))
139-
(set-message "buffer must have a name" "latex-run"))
140-
((not (current-buffer-suffixed "tex"))
141-
(set-message "TeXmacs buffer expected" "latex-run"))
142-
(else
143-
(let* ((opts (std-converter-options "texmacs-stree" "latex-document"))
144-
(tm (current-buffer))
145-
(tex (current-buffer-suffixed "tex"))
146-
(report (with-global current-save-target tex
147-
(try-latex-export (buffer-get tm) opts tm tex))))
148-
(if (tree-atomic? report)
149-
(set-message (tree->string report) "latex-run")
150-
(let* ((buf (current-buffer))
151-
(doc (tree->string (tree-ref report 0)))
152-
(errs (cdr (tree-children report))))
153-
(if (null? errs)
154-
(set-message "Generated LaTeX document contains no errors"
155-
"latex-run")
156-
(dialogue-window (latex-errors-widget buf doc errs)
157-
noop "LaTeX errors"
158-
(latex-error-buffer)
159-
(latex-source-buffer)))))))))
160-
161-
(define (latex-preview)
162-
(let* ((tex (current-buffer-suffixed "tex"))
163-
(pdf (current-buffer-suffixed "pdf")))
164-
(if (not (and tex pdf))
165-
(set-message "TeXmacs buffer on disk expected" "latex-export")
166-
(begin
167-
(export-buffer tex)
168-
(run-pdflatex tex)
169-
(preview-file pdf)))))
170-
171-
(menu-bind tmtex-menu
172-
("Export" (latex-export))
173-
("Run" (latex-run))
174-
("Preview" (latex-preview)))

TeXmacs/progs/convert/latex/tmtex-widgets.scm

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -113,61 +113,3 @@
113113
`(style (tuple "verbatim-source"))
114114
(latex-source-buffer))))))
115115

116-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
117-
;; Convert, run pdflatex, and examine errors
118-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
119-
120-
(define (current-buffer-suffixed suf)
121-
(and (url-exists? (current-buffer))
122-
(buffer-has-name? (current-buffer))
123-
(let* ((tm (current-buffer))
124-
(nr (string-length (url-suffix tm)))
125-
(tex (url-glue (url-unglue tm nr) suf)))
126-
(and (== (url-suffix tm) "tm") tex))))
127-
128-
(define (latex-export)
129-
(with tex (current-buffer-suffixed "tex")
130-
(if (not tex)
131-
(set-message "TeXmacs buffer on disk expected" "latex-export")
132-
(export-buffer tex))))
133-
134-
(define (latex-run)
135-
(cond ((not (url-exists? (current-buffer)))
136-
(set-message "buffer must be on disk" "latex-run"))
137-
((not (buffer-has-name? (current-buffer)))
138-
(set-message "buffer must have a name" "latex-run"))
139-
((not (current-buffer-suffixed "tex"))
140-
(set-message "TeXmacs buffer expected" "latex-run"))
141-
(else
142-
(let* ((opts (std-converter-options "texmacs-stree" "latex-document"))
143-
(tm (current-buffer))
144-
(tex (current-buffer-suffixed "tex"))
145-
(report (with-global current-save-target tex
146-
(try-latex-export (buffer-get tm) opts tm tex))))
147-
(if (tree-atomic? report)
148-
(set-message (tree->string report) "latex-run")
149-
(let* ((buf (current-buffer))
150-
(doc (tree->string (tree-ref report 0)))
151-
(errs (cdr (tree-children report))))
152-
(if (null? errs)
153-
(set-message "Generated LaTeX document contains no errors"
154-
"latex-run")
155-
(dialogue-window (latex-errors-widget buf doc errs)
156-
noop "LaTeX errors"
157-
(latex-error-buffer)
158-
(latex-source-buffer)))))))))
159-
160-
(define (latex-preview)
161-
(let* ((tex (current-buffer-suffixed "tex"))
162-
(pdf (current-buffer-suffixed "pdf")))
163-
(if (not (and tex pdf))
164-
(set-message "TeXmacs buffer on disk expected" "latex-export")
165-
(begin
166-
(export-buffer tex)
167-
(run-pdflatex tex)
168-
(preview-file pdf)))))
169-
170-
(menu-bind tmtex-menu
171-
("Export" (latex-export))
172-
("Run" (latex-run))
173-
("Preview" (latex-preview)))

TeXmacs/progs/init-research.scm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@
359359
(lazy-define (convert latex latex-tools) latex-set-virtual-packages
360360
latex-has-style? latex-has-package?
361361
latex-has-texmacs-style? latex-has-texmacs-package?)
362-
(lazy-menu (convert latex tmtex-widgets) tmtex-menu)
363362
;;(display* "time: " (- (texmacs-time) boot-start) "\n")
364363
;;(display* "memory: " (texmacs-memory) " bytes\n")
365364

TeXmacs/progs/texmacs/menus/tools-menu.scm

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@
4949
("Pictures" (picture-gc))
5050
("Plugins" (reinit-plugin-cache))
5151
("Styles" (style-clear-cache)))
52-
(if (url-exists-in-path? "pdflatex")
53-
(-> "LaTeX"
54-
(link tmtex-menu)))
5552
(-> "References"
5653
(link ref-menu))
5754
(if supports-email?

devel/0130.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# [0130] 移除工具菜单中的 LaTeX 子菜单
2+
3+
## 1 相关文档
4+
- [dddd.md](dddd.md) - 任务文档模板
5+
6+
## 2 任务相关的代码文件
7+
- `TeXmacs/progs/texmacs/menus/tools-menu.scm`
8+
- `TeXmacs/progs/convert/latex/tmtex-widgets.scm`
9+
- `TeXmacs/plugins/latex/progs/convert/latex/tmtex-widgets.scm`
10+
- `TeXmacs/progs/init-research.scm`
11+
12+
## 3 如何测试
13+
14+
### 3.1 确定性测试(单元测试)
15+
```
16+
# 本任务为菜单移除,无单元测试
17+
```
18+
19+
### 3.2 非确定性测试(文档验证)
20+
```
21+
# 编译后启动 Mogan,检查工具菜单中不再出现 LaTeX 子菜单
22+
```
23+
24+
## 4 如何提交
25+
26+
提交前执行以下最少步骤:
27+
28+
```bash
29+
# 编译验证
30+
xmake b mogan
31+
```
32+
33+
## 5 What
34+
35+
移除工具菜单(Tools)中的 LaTeX 子菜单,包括以下三个功能:
36+
37+
1. **导出 (Export)**:与 `文件 -> 导出 -> LaTeX` 功能重复,均将当前文档导出为 `.tex` 文件。
38+
2. **运行 (Run)**:依赖外部 `pdflatex` 命令行工具,对导出的 `.tex` 文件执行编译。
39+
3. **预览 (Preview)**:依赖外部 `pdflatex` 命令行工具,编译后预览生成的 PDF。
40+
41+
## 6 Why
42+
43+
Mogan STEM 的目标用户大多不安装本地 TeX Live,而是使用 Overleaf 等在线工具处理 LaTeX。保留依赖外部 `pdflatex` 的菜单项会造成困惑,且这些功能与 Mogan 的核心定位不符。`文件 -> 导出 -> LaTeX` 已足够满足用户导出 LaTeX 的需求。
44+
45+
## 7 How
46+
47+
### 7.1 分析结论
48+
49+
- `工具 -> LaTeX -> 导出` (`latex-export`):调用 `export-buffer` 将当前 `.tm` 文件导出为同名的 `.tex` 文件。这与 `文件 -> 导出 -> LaTeX` 的功能完全一致,只是路径自动确定而非让用户选择。
50+
- `工具 -> LaTeX -> 运行` (`latex-run`):调用 `try-latex-export`,后者在 C++ 代码 (`src/Plugins/Tex/latex_recover.cpp`) 中直接执行 `pdflatex -interaction=batchmode` 命令。
51+
- `工具 -> LaTeX -> 预览` (`latex-preview`):先导出 `.tex`,再调用 `run-pdflatex`(该函数在代码库中未定义,为无效引用),最后调用 `preview-file` 预览 PDF。其设计意图是依赖外部 `pdflatex` 生成 PDF 后预览。
52+
53+
因此,这三个菜单项均应移除。
54+
55+
### 7.2 修改步骤
56+
57+
1. **移除菜单入口**:在 `TeXmacs/progs/texmacs/menus/tools-menu.scm` 中,移除条件显示的 `LaTeX` 子菜单(`(-> "LaTeX" (link tmtex-menu))`)。
58+
2. **移除函数和菜单绑定**:在 `TeXmacs/progs/convert/latex/tmtex-widgets.scm``TeXmacs/plugins/latex/progs/convert/latex/tmtex-widgets.scm` 中,移除 `latex-export``latex-run``latex-preview` 三个函数,以及 `tmtex-menu``menu-bind`
59+
3. **移除懒加载引用**:在 `TeXmacs/progs/init-research.scm` 中,移除 `tmtex-menu``lazy-menu` 引用。

0 commit comments

Comments
 (0)