Skip to content

[201_90] fix inner product symbol display in tab cycle popup#2939

Closed
1sh-repalto wants to merge 1 commit intoMoganLab:mainfrom
1sh-repalto:1sh-repalto/201_90/fix-inner-product-symbol-in-tab-group
Closed

[201_90] fix inner product symbol display in tab cycle popup#2939
1sh-repalto wants to merge 1 commit intoMoganLab:mainfrom
1sh-repalto:1sh-repalto/201_90/fix-inner-product-symbol-in-tab-group

Conversation

@1sh-repalto
Copy link
Contributor

Fixes #2926
Inner product symbol does not show on Tab cycling popup window

Summary

When cycling through math variants for the < key (which includes the inner product ⟨⟩ as the 7th variant), the popup window showed a broken/red symbol instead of the angle brackets.

Developer Document: devel/201_90.md

Issue Found

The math-bracket-open case in lambda-to-symbol was concatenating the left and right bracket symbols (e.g., "<langle><rangle>"). This produced a compound string that the widget-box rendering engine (using the roman font) could not render correctly, showing as a red broken symbol or --.

Changes

In TeXmacs/progs/math/math-edit.scm:

Modified lambda-to-symbol to return only the left bracket symbol for math-bracket-open:

 ((math-bracket-open)
  (and (>= (length (cdr body)) 2)
       (string? (cadr body))
       (string? (caddr body))
       (let ((lb (cadr body))
             (rb (caddr body)))
         `(symbol-completion
-          ,(string-append lb rb)))))
+          ,lb))))

How to test

  1. Open Mogan Editor
  2. Enter math mode by pressing $
  3. Type <
  4. Press Tab repeatedly (7 times) to reach the inner product ⟨⟩ variant
  5. Verify that the popup window shows the left angle bracket clearly (instead of a broken red symbol or --)
  6. Press Tab once more to return to < and verify the cycle continues correctly
Screenshot 2026-03-05 145152

@JackYansongLi
Copy link
Contributor

Could you make it show $\langle \rangle$ instead of a single $\langle$

@wumoin
Copy link
Contributor

wumoin commented Mar 6, 2026

image The Tab cycling for the `[` symbol seems to have some issues.

@1sh-repalto
Copy link
Contributor Author

Hello @JackYansongLi and @wumoin ,
Thank you for your reviews. I noticed that these issues had already been fixed when I worked on #2910. I created the PR #2916 which fixed these tab cycling behaviors and it was merged. However, a later PR #2918 modified font_fn in src/Texmacs/Window/tm_button.cpp:

- font fn= smart_font (family, fn_class, series, shape, sz, dpi);
+ font fn= find_font (family, fn_class, series, shape, sz, dpi);

From my investigation, this change led to the unusual behaviour of the fixes I had done in my PR.
From my perspective, the best and minimal change would be to revert find_font back to smart_font. I also attempted to resolve the issue while keeping find_font, but I was unable to find a clean solution. Is there some good reason to let it stay as find_font and also possible to fix the issues at the same time ?

Let me know what you guys think on this.

I have tested both behaviours and am attaching them for reference:

  1. with smart_font
with_smart_font.mp4
  1. with find_font
with_find_font.mp4

@wumoin
Copy link
Contributor

wumoin commented Mar 9, 2026

Hello @JackYansongLi and @wumoin , Thank you for your reviews. I noticed that these issues had already been fixed when I worked on #2910. I created the PR #2916 which fixed these tab cycling behaviors and it was merged. However, a later PR #2918 modified font_fn in src/Texmacs/Window/tm_button.cpp:

- font fn= smart_font (family, fn_class, series, shape, sz, dpi);
+ font fn= find_font (family, fn_class, series, shape, sz, dpi);

From my investigation, this change led to the unusual behaviour of the fixes I had done in my PR. From my perspective, the best and minimal change would be to revert find_font back to smart_font. I also attempted to resolve the issue while keeping find_font, but I was unable to find a clean solution. Is there some good reason to let it stay as find_font and also possible to fix the issues at the same time ?

Let me know what you guys think on this.

I have tested both behaviours and am attaching them for reference:

  1. with smart_font

with_smart_font.mp4
2. with find_font

with_find_font.mp4

Using smart_font causes the program to crash and also leads to incorrect rendering.
The following shows the correct display.
image
After switching to smart_font, the display becomes inaccurate.
image
Additionally, clicking this option will also cause the program to crash.
image

@1sh-repalto
Copy link
Contributor Author

Thanks for the clarification @wumoin. I'll look into this issue again and try solve it with find_font.

@1sh-repalto 1sh-repalto force-pushed the 1sh-repalto/201_90/fix-inner-product-symbol-in-tab-group branch from df8e879 to f8b6da0 Compare March 9, 2026 13:46
@1sh-repalto
Copy link
Contributor Author

Hello @JackYansongLi @wumoin, I have modified the code to fix the rendering of tab cycle components. Here is a quick summary of what I did:

Instead of forcing the basic C++ box_widget to parse complex macros, this fix changes the Scheme logic to use widget-texmacs-output. This safely routes the popup symbols through the editor's full math typesetting engine, ensuring complex macros like <langle> render perfectly. I also fixed a hardcoded opacity bug in tm_button.cpp so the tab cycle symbols have a transparent background.

Let me know if this approach looks good. If so, I will update the developer document and PR description accordingly.

Note: While fixing this issue I found some symbols that don't render properly in tab cycling but it's not a new issue as I checked on old version too they don't work properly. I'll raise new issues to fix them.

Here is the state of tab cycling after this fix:

fix_tab_cycling.mp4

@wumoin
Copy link
Contributor

wumoin commented Mar 10, 2026

The current changes significantly degrade the performance of tab cycling. In particular, the response becomes noticeably slower when pressing Tab to cycle through the options.

You can observe the difference in the before-and-after video comparison. When holding down the Tab key continuously, the interface becomes noticeably laggy.

tab.mp4

@1sh-repalto
Copy link
Contributor Author

Hi @wumoin, thank you for pointing this out. My bad I didn't catch this.
I have addressed this performance lag by introducing caching inside texmacs_output_widget in tm_button.cpp.
The lag was caused by widget-texmacs-output re-initializing a full typesetting environment for every symbol on every Tab press. The new implementation uses a static hashmap keyed by the (doc, style) tree pair to cache the computed boxes. This ensures each unique symbol (e.g., <, {}, etc.) is typeset exactly once; all subsequent cycles retrieve the pre-rendered box instantly from memory.

Does this seem like a correct approach ?

Below is the code diff. I have also attached a screen recording demonstrating the before vs. after performance.

Inside tm_button.cpp

+// Cached result for texmacs_output_widget
+struct texmacs_output_cache_entry {
+  box   b;
+  color col;
+  bool  trans;
+};
+
 widget
 texmacs_output_widget (tree doc, tree style) {
+  // --- Cache lookup ---
+  static hashmap<tree, texmacs_output_cache_entry> output_cache;
+  tree cache_key= tuple (doc, style);
+  if (output_cache->contains (cache_key)) {
+    texmacs_output_cache_entry& e= output_cache (cache_key);
+    double zoom= (retina_zoom == 2 ? 1.0 : 1.2);
+    return widget (tm_new<box_widget_rep> (e.b, e.col, e.trans, zoom, 0, 0));
+  }
+
   .
   .
   .
+
+  // --- Cache store ---
+  texmacs_output_cache_entry entry;
+  entry.b    = b;
+  entry.col  = col;
+  entry.trans= trans;
+  output_cache (cache_key)= entry;
+
   double zoom= (retina_zoom == 2 ? 1.0 : 1.2);
   return widget (tm_new<box_widget_rep> (b, col, trans, zoom, 0, 0));
 }
optimize_tab_cycling_performance.mp4

@wumoin
Copy link
Contributor

wumoin commented Mar 12, 2026

Initializing each symbol through a full typesetting environment is not a very good approach.

I think this issue should be split into two separate parts: one is the display problem with [ and |, and the other is the issue where < cannot be displayed in tab cycling.

I just took a look at the first problem, and I will submit a PR for it later. You can take a look at that then.

@wumoin
Copy link
Contributor

wumoin commented Mar 12, 2026

#2973

@wumoin
Copy link
Contributor

wumoin commented Mar 12, 2026

You can look into how these symbols are rendered. I’ll close this PR for now.

@wumoin wumoin closed this Mar 12, 2026
@1sh-repalto
Copy link
Contributor Author

Got it, I'll create a new PR that addresses this issue based on the changes you have made in your PR. Should I wait for your PR to get merged first ?

@wumoin
Copy link
Contributor

wumoin commented Mar 13, 2026

#2569 #2574 #2589
I gave you a few references. You can first look into how these symbols are rendered, and then investigate why one of the tab-cycling entries for < is not being rendered. This is somewhat difficult, so you may want to try working on other issues first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inner product symbol does not show on Tab cycling popup window

3 participants