# 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))))`

3 Likes

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.

3 Likes

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