How to assign keyboard shortcut to a macro

Yes, the current way is a bit awkward.

About the greek letters, the original “a tab” is sufficiently convenient. However, the repeated use of the pinky finger makes it less efficient for long-time typing.

Or simply:

("R R" (insert "<bbb-R>"))
2 Likes

This yields the same result as the system default shortcut R R, which is different from \mathbb{R}.

Why not

(insert '(with "font" "Bbb" "R"))
1 Like

This is it.
Is this the generate way to replicate TeXmacs tags in scheme?

I have a related problem: define dx in integrals. d*x certainly is not the best option even using the invisible-multiply package, since it’s semantically incorrect. dx should be considered as a single symbol. My workaround is to define a shortcut for d\phantom{|}x. I could use a macro for that, then a shortcut for the macro. But it’s awkward. How do we replicate d\phantom{|}x with a scheme code?

Another option is to use \mathd x, but nowdays it seems this upright verison is not as popular.

The easy way to figure out the Scheme code for any TeXmacs expression is using the menu item Edit -> Copy to -> TeXmacs Scheme, and then paste in a text editor.
For your construct I get (concat "d" (phantom "") "x")

1 Like

Thanks! I get it done with

("d x" (insert '(concat "d" (phantom "") "x")))

1 Like

Perhaps it is worth to set up two different meanings for the shortcut, one for math mode and one for text mode. The one for text mode might be (math (concat "d" (phantom "") "x"))

Thanks! The "|" should be replaced by "" though.

1 Like

Note that the standard way to write the integral symbols is to use the “correct” d, when you type “d” this mean a standard variable, for the integral symbol you have to type “d tab tab” which give you “\mathd”. It exists only for this purpose, I would tend to disagree with your assessment that because “it is not popular” it has to be dismissed. My experience with many LaTeX writers is that they do not care with these fine typographical points, but TeXmacs makes easy for you to “do the right thing”. I write all my papers (with a lot of integrals!) with “d tab tab”, it is easy, fast and you do not need another macro to support it.

See for example this paper: https://arxiv.org/pdf/2210.15047.pdf which has been completely written in TeXmacs.

There are discussions in stackexchange about which is correct, the upright or italic d in dx. Some consider d as a differential operator and write it in upright. I tend to think dx as a single entity (a differential) and type it in italic. Nevertheless the conventions are different in different community.

I am more concerned with the space before the dx in integrals. In TeXmacs the semantically correct way is to type a multiplication (I agree with this considering the math definition of integrals) or an apply between the integrand and dx. However, this will cause a problem when exported to LaTeX because there is no space at all. Preferably we want insert a space like \, (equivalent to 0.2spc in TeXmacs).

I do not share this point of view, but let’s say you want to go for it, then the appropriate thing to do is to make TeXmacs aware that anyway “dx” is a different object than the product of two variables. So I would make a macro of the kind \d{x} which take one parameter and produce your “differential” (whatever it is). Once you have this macro you can easily modify its appearance on screen and I think also how it is translated into LaTeX (indeed I think you can prescribe a different definition when you translate a macro to latex). Keep in mind that TeXmacs tries to parse your math semantically and this in order to give it the proper spacing, e.g. the minus sign has different spacing whether is is binary or unary, ("-1" vs. “1-2”), so all the other symbols. You can modify the parsing by adding semantic annotations, that is declare that some construction has some specific semantic content (operator, binary operation, etc…) this allow TeXmacs to put proper spacing around it.

Why is it a problem to have a tiny space before dx? This seems standard.

I mean the space is not inserted in the latex export if I used * or apply in TeXmacs. If I want the space in the latex export, I must used 0.2spc in TeXmacs, but then it is not semantically correct.

My naive workaround now is to define commonly used ones with shortcuts
("d x" (insert '(concat "d" (hspace "0pt") "x")))
This has a shortcoming of redundant \hspace in the LaTeX export.

This is not the right way to do it. If you prescribe the rendering then you loose the meaning and the LaTeX translator cannot read in your mind about what you really want. Your markup should prescribe the meaning and then you need to use macro expansion to set up the rendering, the LaTeX converter will see a macro (I believe) and can be instructed to translate it in predefined ways.

Do you mean we can define macro in one way but export it in a different way?

Yes, please look at the manual for conversion to other formats:

2 Likes

There is a disadvantage of specific, or more precisely, that of the TeXmacs GUI: it seems to only support single-line codes. It would be better if it also applies to blocks.

See this bug report: https://savannah.gnu.org/bugs/?62800

When you apply the specific macros to export the LaTeX macro definitions you want in the exported LaTeX preamble, you also need to unselect “Expand TeXmacs macros with no LaTeX equivalent” and “Expand user-defined macros” in the TeXmacs preferences.