How to assign keyboard shortcut to a macro

Suppose I have the following macro (the \mathbb result looks better than the builtin RR result)

Now I can type \RR and enter to get the result. However, I am lazy and want to get the result by typing “RR” only, without the \ and enter, just like the builtin one. I already have working keyboard shortcuts such as ("a l" "<alpha>") in the math mode, but this does not work for my own macro ("R R" "<RR>").

I only know a way around, that is replicating the keypresses for \ R R enter:

(kbd-map ("R R" (begin (make-hybrid) (insert "RR") (kbd-return))))


This work! What exactly does the command (make-hybrid) do?

Goes into the hybrid mode, the one in which you enter when you press the slash key. According to the manual (Sec. 2.8.3) it is called hybrid because entering macros in this way looks like entering a TeX macro.

1 Like

Great! The reason I am concerned with these kind of shortcuts is because I am now using TeXmacs in university teaching. That is, type everything and project it on the screen instead of writing on the board. The feedback is actually quite good. I’d like to input content as quick as possible, and with minimal visual distractions such as the slash and the brackets.


I would have just added a keybinding to insert a \mathbb{R} tag instead of additionally having a specific macro. There should be a way to indicate to TeXmacs that you want to typeset such a character or also tell him which font it has to use for the blackboard bold characters. Somehow you do not want really to change font but to indicate that you want to type a special glyph (the simbor for the real number set) which incidentally should be typeset by choosing the R glyph from the a specific font.

I would also avoid to setup shortcuts for greek characters, the standard one is just to type the roman letter and then press “tab” to produce the first variant. So for alpha you just do “a tab”.

1 Like

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>"))

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: 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.