How to define my own keybinding

So the questions is this:

In math mode, I often type \quad to make a blank space.
I know these must be a way to create a shortcut, like using double SPACE to perform this action.

How can this be achieved?

I think this question will be very instructive, since once I know how to create a set of key actions to perform a latex command like \quad, many others can be similarly worked out. (and in fact, from this question I have learned a lot and applied that method to many other instances)

Hi,
it is quite possible that I did not understand your question—let me try and answer it nonetheless.
If you want to make a shortcut for “something that is entered through a ‘LaTeX-like command’” (slash-something) one way to do it is to use the result of the expression in TeXmacs (looking at the source or copying it as “TeXmacs Scheme”).
If you want to use the space bar as part of a keyboard shortcut, then enter “space” as part of the key combination (the quotes are needed only once, to define the whole string that is the key combination).
Pls. let me know if this is what you had in mind.
G.

Could you please explain under what circumstance you need to add a blank space? Unlike LaTeX, TeXmacs differentiates the semantic of different spaces, so it is context-dependent.

Yes, for many “latex-like command”, I’ve already know how to do it, as an example, the following is my my-init-texmacs.scm:

(delayed
(lazy-keyboard-force)
(kbd-map
(:mode in-math-not-hybrid?)
("c var" "<chi>")
("q var" "<theta>")
("f var" "<phi>")
("f var var" "<varphi>")
("k var var var" "<b-k>")
("L var var" "<cal-L>")
("+ var" "<dag>")
("+ var var" "<kreuz>")
("S var var var" (math-big-operator "sum"))
("P var var var" (math-big-operator "prod"))
("O var var" "<cal-O>")
("A var var var var" "<cal-A>")
("B var var var var" "<cal-B>")
("D var var var var var" "<cal-D>")
("x var var" "<b-x>")
("r var var var" "<b-r>")
))


As you can see, I’ve essentially achieved some keyboard shortcut like type c-TAB to insert \chi in math mode.

The reason why I know how to do it (with little knowledge of texmacs scheme or whatsoever), is that I find many codes corresponding to latex commands in \$TEXMACS_PATH/progs/progs/math/math-kbd.scm. Say "<chi>" = \chi

Now the problem is this, there are many commands NOT given in that math-kbd.scm file. So in this case, what to do?

Returning to my original question, inside math mode, AFAIK, there is not a shortcut for \quad, so every time I have manually type SLASH-quad-RET to insert a standard blank space. And since there is not a shortcut for it, there is also not an item inside math-kbd.scm file. So how to write the code in my-init-texmacs.scm? Explicitly, if I want to use double SPACE to insert \quad.

Generalizing my question, I would like to learn how to write the codes inside my-init-texmacs.scm to create shortcut for an arbitrary latex commands.

JW

Yes, as an example, the space I am referring to is the following one, between the two equations,

I don’t know what is the “correct” way to produce this. You press the comma, then press Tab several times. This will generate a “separating space”, which seems to be semantically correct in this situation.

1 Like

I would do it in this way (picking up from my first answer, and see at the end for insertion of latex-style commands):

1. Figure out what TeXmacs expression corresponds to \quad

2. Make a shortcut for that

In order to do point 1., I would enter \quad Return in math, copy to TeXmacs Scheme (menu Edit->Copy To->TeXmacs Scheme) and finally paste in a text file—so that you see the expression that you have to use in my-init-texmacs.scm

In this case, the expression is (space “1em”) and you can include it in the keyboard shortcuts as “space space” (pressing twice the space bar) as

(“space space” (insert '(space “1em”)))

It seems to me that this is the general procedure.

One needs to keep in mind the quoting symbol ’ in front of the expression that one has copied from TeXmacs and must also put a space between successive key presses that make up a sequence—for example in (“ss” (insert '(space “1em”))) “ss” would not be recognized as the sequential press of “s” and “s”.

I found out two more Scheme forms, one is helpful and one maybe

In place of (insert '(space "1em")) one can use make-space: for example ("space space" (make-space "1em"))

There is a make-hybrid form as well (I found it in math-kbd.scm), and this, I guess, is the way to insert LaTeX-style commands. I have seen that this works (as an example, in math mode):

("a r r" (begin (make-hybrid) (insert "leftarrow")))

but then you still have to press the return key.

P.S.
All of this is by guessing and experimenting starting from the descriptions in the manuals (general and Scheme developer), so there may be mistakes

1 Like

Thanks for the info, I did not know about this … TeXmacs has many many shortcuts and as far as I know to find out them all one has to look in the code

By the way (for @vac) in this case using a default TeXmacs shortcut seems “better” than defining your own—the sequence of expressions that come out of comma-multiple tabs looks logical (although I did not understand what is coming out after the first tab press ) and the “separating space” is probably better than the space. My answer is for the general case.

That is a neat and intuitive keyboard shortcut!

I find texmacs has many hidden golds, we really need a better cheat sheet/manual guide.