Is the key binding for multiplication hard coded?

In my case multiplication occurs much more frequently than function application in math formulas. For efficiency it’s desirable to use Space instead of * for multiplication and another key for function application. In math-kbd.scm I found settings that may be related to multiplication but no settings for direct function application (only variations of space), and tweaking those settings was unsuccessful. It made me wonder if the key binding for multiplication is hard coded.

The space key in general (both math and text) is bound TeXmacs/progs/generic/generic-kbd.scm line 53 to (kbd-space). This function in turn calls kbd-space-bar, which is overloaded, calling the function which is relevant to the context. For math environments, the relevant definition is in TeXmacs/progs/math/math-edit.scm line 52.

So basically, you can remap * to call (kbd-space) in math environments, if you so wish.

1 Like

After reading the implementation of kbd-space-bar, I accomplished what I want by using ("space" (insert "*")) in a kbd-map. My original failed try was ("space" "*"). What’s the difference between "*" and (insert "*")?

The complete code snippet:

(delayed
 (lazy-keyboard-force)
 (kbd-map
  (:mode in-math-not-hybrid?)
  ("space" (insert "*")))) 

with the structure taken from http://forum.texmacs.cn/t/change-systems-default-shortcut-for-symbols/310/14?u=jade. But honestly I don’t understand the delayed and lazy-keyboard-force keywords even after readin the manual.

1 Like

Nice! The delayed is to make sure your definitions are loaded after the default ones, otherwise the shortcut would get overridden. I believe the lazy delays are such that the command gets executed once TeXmacs is first idle. You can use a fixed delay, but then you need to make sure it’s neither too short so it comes after the system one, nor too long so you don’t have to wait to use it.

To speed up the startup of TeXmacs many of the initial scheme definitions are lazily loaded, i.e. they are read from disk but not executed yet, so that the UI can be responsive as soon as possible. Later on, when the user is not interacting with the system (idle time), TeXmacs start to run the queue of “delayed” commands from booting. If you create a keybinding too early in this process it is then overridden by the standard keybinding once they get lazily loaded. “Delayed” put your commands in queue at the end, waiting for execution, and “lazy-keyboard-force” ensure that all the lazy keyboard definitions are considered before yours. HTH

2 Likes

Does the ideal time mean I need to wait a while (1 sec?) with no keyboading and mouse interaction before I can use my own definitions? Or if the lazy-keyboard-force is put in front of my own definitions, then all the built-in definitions with a lazy property will be executed the moment I press one of my custom key bindings?

Sorry, I was not clear. delayed will put it in the queue, I guess it is enough to get it running at the right time. The delayed command queue is processed as soon as TeXmacs has some free time. The lazy-keyboard-force run the pending lazy definitions at the moment of invocation, so this prepares the right environment for your subsequent commands to be properly executed and avoid that later forcing of previous lazy definitions override you own keybindings. This is the reason your kbd-map has to be executed in the way your snippet does. To be sincere right now I’m not sure why delayed is needed. I guess that only (lazy-keyboard-force) would be enough, but I might miss something. @jeroen you have some insights?

When I tested lazy-keyboard-force without delayed there was a crash - documented in this post Change system's default shortcut for symbols