Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions TeXmacs/progs/kernel/gui/menu-widget.scm
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,34 @@
;; Symbol fields
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define (menu-symbol-needs-typeset-preview? sym)
(in? sym '("<lefttimesthree>" "<righttimesthree>")))

(define (make-menu-symbol-typeset-widget sym col-name)
(let* ((pre (document-get-preamble (buffer-tree)))
(master (url->system (current-buffer)))
(inits* (map cdr (cdr (tm->stree (get-all-inits)))))
(env (append (apply append inits*) (list "magnification" "1.4")))
(doc `(with ,@env "project" ,master
(surround (hide-preamble ,pre) ""
(document (math (with "color" ,col-name ,sym)))))))
(widget-texmacs-output-transparent doc '(style (tuple "generic")))))

(define (make-menu-symbol-widget font sym col col-name)
(if (menu-symbol-needs-typeset-preview? sym)
(make-menu-symbol-typeset-widget sym col-name)
(widget-box font sym col #t #t)))

(define (make-menu-symbol-button style font sym opt-cmd clr)
(with col (if (greyed? style) (color "dark grey") clr)
(let* ((col-name (if (greyed? style) "dark grey"
(if (string? clr) clr "black")))
(col (if (greyed? style) (color "dark grey")
(if (string? clr) (color clr) clr))))
(if opt-cmd
(widget-menu-button (widget-box font sym col #t #t)
(widget-menu-button (make-menu-symbol-widget font sym col col-name)
(make-menu-command (apply opt-cmd '()))
"" "" style)
(widget-menu-button (widget-box font sym col #t #t)
(widget-menu-button (make-menu-symbol-widget font sym col col-name)
(make-menu-command (insert sym))
"" "" style))))

Expand Down Expand Up @@ -851,11 +872,11 @@
(symbol-completion (:string? :*)
,(lambda (p style bar?)
(let ((symbol-color (if (== (get-preference "gui theme") "liii-night") "white" "black")))
(list (make-menu-symbol p style '(roman mr medium normal 10 600 0) (color symbol-color))))))
(list (make-menu-symbol p style '(roman mr medium normal 10 600 0) symbol-color)))))
(symbol-completion* (:string? :*)
,(lambda (p style bar?)
(let ((symbol-color (if (== (get-preference "gui theme") "liii-night") "#ff6666" "red")))
(list (make-menu-symbol p style '(roman mr medium normal 10 600 -2) (color symbol-color))))))
(list (make-menu-symbol p style '(roman mr medium normal 10 600 -2) symbol-color)))))
(texmacs-output (:%2)
,(lambda (p style bar?) (list (make-texmacs-output p style))))
(texmacs-input (:%3)
Expand Down
38 changes: 38 additions & 0 deletions devel/221_3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[221_3] 修复数学 tab cycling 菜单中 `<lefttimesthree>` 和 `<righttimesthree>` 显示异常

## 如何测试

测试项一:`'T'` 的 tab cycling 菜单和实际插入结果正确
1. 进入数学输入环境
2. 输入 `T`,连续按 `Tab` 切换候选
3. 浏览整组候选,重点检查 `<lefttimesthree>` 和 `<righttimesthree>`
4. 这两个候选应显示为完整符号,不应出现红色报错文本,也不应只显示半个符号
5. 当前高亮候选应保持和其他候选一致的选中态颜色
6. 在这两个候选高亮时确认输入,文档中插入的应是对应符号,且正文渲染正常
7. `<Tau>`、`<top>`、`<perp>`、`<leftthreetimes>`、`<rightthreetimes>` 的显示和输入行为应保持原样

## 2026/04/09 修复数学 tab cycling 菜单中组合乘号符号显示异常

### What
修复数学模式下,输入 `T` 后通过 tab cycling 弹出的候选菜单中,`<lefttimesthree>` 和 `<righttimesthree>` 无法正常显示的问题。

此次修复只调整 popup 预览链:
- 这两个符号在菜单中改为使用透明的 typeset 预览 widget
- 其余候选仍保持原来的 `widget-box` 预览方式

### Why
`<lefttimesthree>` 和 `<righttimesthree>` 不是传统数学字体中的现成 glyph,而是定义在 `TeXmacs/fonts/virtual/emu-operators.vfn` 里的虚拟组合符号。

此前 tab cycling 菜单走的是 `symbol-completion -> widget-box -> text_box -> font` 这条轻量预览链。
这条链对普通符号和已有编码映射的符号可以直接取 glyph,但对 `lefttimesthree/righttimesthree` 这种需要继续展开内部虚拟名字 `times2/times4/times6/times8` 的符号支持不完整,因此会在 popup 中退化成错误文本或异常显示。

### How
TeXmacs/progs/kernel/gui/menu-widget.scm 为 `<lefttimesthree>` 和 `<righttimesthree>` 增加单独判断,仅对这两个符号使用 `make-menu-symbol-typeset-widget`

src/Texmacs/tm_window.hpp 声明新的透明输出 widget 接口 `texmacs_output_widget_transparent`

src/Texmacs/Window/tm_button.cpp 新增 `texmacs_output_widget_transparent`,沿用正文 typeset 生成 box,但以透明 widget 的方式嵌入菜单,避免出现额外深色底框

src/Scheme/L5/glue_widget.lua 注册 Scheme 侧接口 `widget-texmacs-output-transparent`

src/Graphics/Fonts/virtual_font.cpp 调整虚拟字体 atomic token 的解析优先级:当名字本身就在当前虚拟字体字典中时,优先继续递归展开,而不是先回退到 `base_fn` 查位图,避免 `times2/times4/times6/times8` 落入 error font
17 changes: 8 additions & 9 deletions src/Graphics/Fonts/virtual_font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,10 +263,9 @@ virtual_font_rep::supported (scheme_tree t, bool svg) {
if (r == "#28") r= "(";
if (r == "#29") r= ")";
if (N (r) > 1) r= "<" * r * ">";
if (!extend || base_fn->supports (r) || !virt->dict->contains (r))
return base_fn->supports (r);
if (!virt->dict->contains (r)) return false;
return supported (virt->virt_def[virt->dict[r]], svg);
if (virt->dict->contains (r) && (!extend || !base_fn->supports (r)))
return supported (virt->virt_def[virt->dict[r]], svg);
return base_fn->supports (r);
}

if (is_func (t, TUPLE, 3) && (is_double (t[0])) && (is_double (t[1])))
Expand Down Expand Up @@ -450,14 +449,14 @@ virtual_font_rep::compile_bis (scheme_tree t, metric& ex) {
if (r == "#29") r= ")";
if (N (r) > 1) r= "<" * r * ">";
glyph gl;
if (!extend || base_fn->supports (r) || !virt->dict->contains (r)) {
base_fn->get_extents (r, ex);
gl= base_fn->get_glyph (r);
}
else {
if (virt->dict->contains (r) && (!extend || !base_fn->supports (r))) {
scheme_tree u= virt->virt_def[virt->dict[r]];
gl = compile (u, ex);
}
else {
base_fn->get_extents (r, ex);
gl= base_fn->get_glyph (r);
}
if (gl->width == 0 && gl->height == 0)
ex->x1= ex->y1= ex->x2= ex->y2= ex->x3= ex->y3= ex->x4= ex->y4= 0;
return gl;
Expand Down
9 changes: 9 additions & 0 deletions src/Scheme/L5/glue_widget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,15 @@ function main()
"content"
}
},
{
scm_name = "widget-texmacs-output-transparent",
cpp_name = "texmacs_output_widget_transparent",
ret_type = "widget",
arg_list = {
"content",
"content"
}
},
{
scm_name = "widget-texmacs-input",
cpp_name = "texmacs_input_widget",
Expand Down
29 changes: 29 additions & 0 deletions src/Texmacs/Window/tm_button.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,35 @@ texmacs_output_widget (tree doc, tree style) {
return widget (tm_new<box_widget_rep> (b, col, false, zoom, 0, 0));
}

widget
texmacs_output_widget_transparent (tree doc, tree style) {
doc= enrich_embedded_document (doc, style);
drd_info drd ("none", std_drd);
hashmap<string, tree> h1 (UNINIT), h2 (UNINIT);
hashmap<string, tree> h3 (UNINIT), h4 (UNINIT);
hashmap<string, tree> h5 (UNINIT), h6 (UNINIT);
tree prj= extract (doc, "project");
if (is_atomic (prj) && exists (url_system (prj->label))) {
tm_buffer buf= concrete_buffer_insist (url_system (prj->label));
if (!is_nil (buf)) {
h1= copy (buf->data->ref);
h3= copy (buf->data->aux);
h5= copy (buf->data->att);
}
}
edit_env env (drd, "none", h1, h2, h3, h4, h5, h6);
initialize_environment (env, doc, drd);
tree t = extract (doc, "body");
lazy lz= make_lazy (env, t, path ());
format vf=
make_query_vstream_width (array<line_item> (), array<line_item> ());
format rf = lz->query (LAZY_BOX, vf);
SI w = ((format_vstream) rf)->width;
box b = (box) lz->produce (LAZY_BOX, make_format_width (w));
double zoom= (retina_zoom == 2 ? 1.0 : 1.2);
return widget (tm_new<box_widget_rep> (b, white, true, zoom, 0, 0));
}

array<SI>
get_texmacs_widget_size (widget wid) {
array<SI> ret;
Expand Down
1 change: 1 addition & 0 deletions src/Texmacs/tm_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ typedef tm_view_rep* tm_view;
typedef tm_window_rep* tm_window;

widget texmacs_output_widget (tree doc, tree style);
widget texmacs_output_widget_transparent (tree doc, tree style);
widget texmacs_input_widget (tree doc, tree style, url wname);
bool is_embedded_buffer (url name);
array<SI> get_texmacs_widget_size (widget wid);
Expand Down
Loading