Only part of `my-init-texmacs.scm` works (try to bind new key in math mode)

Hi forum,

I am trying to bind new keys to exit from superscript like mentioned in this post:
http://forum.texmacs.cn/t/alternative-to-arrow-keys-to-exit-from-sub-superscripts/865

However, after I customized the my-init-texmcs.scm file, only part of my commands work.

(menu-bind insert-menu
  (former)
  ---
  ("Dear Sir" (insert "Dear Sir,")))

(kbd-map 
  (:require (inside? 'equation*))
  ("space" (structured-exit-right)))

(kbd-map 
  (:require (inside? 'equation))
  ("space" (structured-exit-right)))

(kbd-map 
  (:require (inside? 'eqnarray*))
  ("space" (structured-exit-right)))

(kbd-map 
  (:require (or (inside? 'equation*) (inside? 'equation) (inside? 'eqnarray*)))
  ("space" (structured-exit-right)))

(kbd-map 
  ("C-space" (structured-exit-right)))


(kbd-map
  ("D e f ." (make 'definition))
  ("L e m ." (make 'lemma))
  ("P r o p ." (make 'proposition))
  ("T h ." (make 'theorem)))

(kbd-map
  ("P r o o f ." (make 'proof)))

The last line serves as a sanity check. When I type “P r o o f .”, TexMacs does insert a proof block. This indicates the program did load the scheme file.

However, the key binding to the function (structured-exit-right) doesn’t work. For example, if I type “$ x ^ 2 space”, I expect the cursor moves from the superscript to the place after the superscript so that I can continue to type my equation without moving my hand to the arrow keys. But TexMacs doesn’t register this behavior. Instead, if I keep pressing space button, it inserts spaces.

In addition, I could not find the expected menu option “Dear Sir”, which is defined in the first block of my file.

As a new user, I am trying to learn the basic customization but got really confused. I would appreciate any insights on where the problem is. Many thanks!

1 Like

Hi @tom and welcome to the forum.

I think that your keyboard shortcuts get overwritten by the TeXmacs ones when TeXmacs loads them late (lazy binding).

To force the loading of TeXmacs’ shortcuts before you define yours you can prepend a (lazy-keyboard-force) to yours, and wrap shortcuts and (lazy-keyboard-force) in a delayed form:

(delayed (lazy-keyboard-force)

(kbd-map 
  (:require (inside? 'equation*))
  ("space" (structured-exit-right)))

(kbd-map 
  (:require (inside? 'equation))
  ("space" (structured-exit-right)))

(kbd-map 
  (:require (inside? 'eqnarray*))
  ("space" (structured-exit-right)))

(kbd-map 
  (:require (or (inside? 'equation*) (inside? 'equation) (inside? 'eqnarray*)))
  ("space" (structured-exit-right)))

(kbd-map 
  ("C-space" (structured-exit-right)))


(kbd-map
  ("D e f ." (make 'definition))
  ("L e m ." (make 'lemma))
  ("P r o p ." (make 'proposition))
  ("T h ." (make 'theorem)))

(kbd-map
  ("P r o o f ." (make 'proof))))

I left the menu item out of the example; for menu items I think the loading of the TeXmacs menu items can be forced with (lazy-initialize-force)

You can search the forum with delayed or lazy for more examples. Please let me know if this works.

3 Likes

Hi @pireddag, thank you so much for your reply. It works like a charm.
The following is the working code for those interested:

(delayed
  (lazy-keyboard-force)
  (kbd-map 
    (:mode in-math?)
    ("space" (structured-exit-right))
  )
)
3 Likes