Hello everyone,
This post is about how Texmacs deals with math operators like sup, inf, exp and such.
I would like to express my belief that it is slightly anti-intuitive (this is an opinion) and also highlight an actual bug.
Background and examples
LaTeX wants operators like \sup, \inf, and \lim to be macros. Texmacs does not encode these operators as macros: to input sup you just type the letters that spell sup in math mode.
However, Texmacs does have a bunch of special logic to deal with these operators.
Example 1:
For example, start by writing u p _ t in math mode. You get

Now move your cursor to the beginning
![]()
and type an s:
![]()
VoilĂ : Texmacs recognizes that sup is special and its indexes should be rendered appropriately.
Here is a comparison with the source code:

with source given by

Example 2:
Other interesting logic is built into the exporter to LaTeX and into hybrid input mode. When exporting to LaTeX, Texmacs detects that sup is special and converts it to a LaTeX macro. When using hybrid mode, you can try to input a non-existent macro e.g. by typing \ t e s t + <RET>
to obtain
![]()
and after pressing <RET> you get
![]()
Texmacs, correctly, does not recognize the macro test and displays it as an unknown macro.
However, if you try to do this with \ s u p + <RET> Texmacs recognizes that something special is going on. It does not insert a special macro but it just inserts the letters sup:

and then with <RET> you get
![]()
If you look at the source, here is a comparison of the results of the two procedures above:

is encoded as

Example 3:
Generally, Texmacs encodes normal math operators using the <math-up|???> macro. For example, if I wanted to use the operator conv (e.g. to denote the convex hull of a set) I would do:
- put myself in math mode;
- click on
; - type in the operator:
;
If I wanted to reuse this operator often, I could define a macro in the preamble:
And now I can insert
conv either by assigning it a keyboard shortcut or using hybrid mode by typing \ c o n v <RET>:becomes
Example 4:
Following up on Example 3, suppose that I go out of my way to define sup to be a math-up - type math operator in the preamble:

If I try to enter my new macro using hybrid-mode then Texmacs actually does not allow this to happen and just inserts the letters s u p instead of my macro.
Type: \ s u p:![]()
Follow it by <RET>: ![]()
with this as corresponding source: ![]()
Issues, thoughts, and questions
1) I think logic and structure should be emphasized and sup inf and the rest should be special tags/macros instead of just having ad-hoc logic. This would also allow eliminating ad-hoc logic from the LaTeX converter to search for keywords as substrings of math.
2) Hybrid mode should give priority to user defined macros rather than latex keywords. Doing what is described in Example 4 should give the defined macro, rather than revert to the logic of “LaTeX” symbols. User defined preferences should have higher priority!
3) How would one define a macro that renders subscripts below in the same way as sup does?
More precisely, suppose that I want to define the operator fancylim that has the same visualization of lim when followed by an underscript (see Example 1). The only way I see of doing it now is by manually using “Insert->Script->Script below” and even then the spacing is off:
with code:
4) According to example 4, is there any way to insert my newly defined sup operator without assigning a special shortcut and without using the menu (keyboard only)?
5) Erasing operator is, I believe, suboptimal. If you have ![]()
erasing removes the p. This is mostly not what one wants. When I am erasing sup I am probably not looking for the operator su that probably is not defined. It would be, I think, more ergonomic, in that case to erase sup and write the mysterious su operator. This would be solved by defining sup as a tag/macro
6) See the bug below
Bug with selecting and copy pasting math operators
Bug 1
Suppose I start with the following math-mode equation

I would like to copy the limit to somewhere. So I press <SHIFT> and start moving the cursor backwards. If I am in front of the whole limit, this works well. One backwards arrow gives

and one copy+paste later I have
on a new line.
If I start before the subscript but in front of the lim then this happens:
after two <SHIFT>+<LEFT ARROW> becomes

that is not very ergonomic but it is NOT A BUG.
However, suppose I start with the function and I want to copy paste with the limit with the function. If I do it with the keyboard, everything works like expected:

followed by just enough <SHIFT>+<LEFT ARROW> gives

If you do a copy paste at this point, everything works as expected:

However if you accidentally go one step backwards more with the selection this is what happens:

and a copy paste gives:

This is a mild bug. One can see what is happening: the highlighting goes until the m and does not include the li part. However, the visual representation of this is off. The editor suggests that the whole lim is highlighted while only the m is.
This is much a bigger issue when you are using a mouse. If you select by dragging here is what you get:
A copy+past gives a truncated limit:

Since aiming with the mouse is very unproductive, this essentially makes mouse selection useless in formulas with things like lim, sup and such.
Note that this does not happen with operators enclosed by math-up. Even though the cursor can end up in the middle of the operator:

A copy paste yields:

Furthermore, if conv is defined as a macro in the preamble it works even better: the cursor sticks to the boundary of the tag/macro and does not go inside!!

(Please forgive me for the meaningless math above)
TL; DR
Please make sup inf and such into a tag/macro instead of using ad-hoc logic for rendering these math operators. I believe this is more logical and avoids some buggy behavior.
Also, I think one should be encouraged to “define” math operators in the preamble if one uses them consistently through a paper. I would appreciate a pointer on how to encode the behavior of super/subscripts close to such macros.
Summary
Here is a screenshot of three math equations with:
- the operator
conv - the ad-hoc defined operator
sup - the default result of typing
\ s u p <RET>
I believesupand similar should be like in the second math entry rather than in the third one. Texmacs however really prefers the third option (second version ofsup) and I think that is counterproductive.

Source:
EDIT: One shortcoming of my proposal comes to mind: suppose you are a new user typing math and you just write s u p to insert a sup. Then this would just insert the letters sup and not a special operator. Maybe logic to detect these operators when typed should be implemented (it already is) but, for example, once space is pressed (that should be pressed at the end of the operator sup) then it converts it to a macro?
Thank you very much in advance!!!


