[Share] To disable math keyboard bindings in label

When you are in math mode, for example equation, align, eqnarray, very often you want to label the equation or one of the equations for later reference in the article or document, there is a chance that you triggered a keybinding when you are in label. My case is as follows:

In math-mode, I bind d i to the math formula \partial_i (in terms of Tex, \partial_{i}). For me it is extremely useful. Say I want to label the equation differential. When there was no third line of the below code, \partial_i will be popping up in label.

(kbd-map
 (:mode in-math?)
 (:require (not (in-variants-disabled?)))     
 ("d i" (math-insert '(concat "<partial>" (rsub "i")))))

Alternative solution could also be

(kbd-map
 (:mode in-math?)
 ("d i" (math-insert '(concat "<partial>" (rsub "i")))))

(kbd-map
 (:mode in-variants-disabled?)
 ("d i" "di"))

Figure

Reference of TeXmacs code:

  1. progs/kernel/texmacs/tm-modes.scm, See texmacs-modes.
  2. progs/kernel/gui/kbd-define.scm, See the definitions of kbd-add-condition, kbd-map-one, kbd-map-body and kbd-map
2 Likes

Exactly what I want! What is the meaning of in-variants-disabled?

To make it more flexiable, move cursor into the slot and type what you want:

   ("d i" (begin
            (insert "<partial>")
            (insert-go-to '(rsub "") '(0 0))))
   ("d I" (begin
            (insert "<partial>")
            (insert-go-to '(rsup "") '(0 0))))
3 Likes

I don’t know whether @susoren is reading the forum in these days, I am going to answer in his stead.
With the procedure-source form you can get the source for Scheme functions.

(procedure-source in-variants-disabled?)

returns

(lambda () (tree-in? (tree-up (cursor-tree)) (quote (hlink reference pageref label))))

I did not try and figure out what tree-up does, this said it looks like a list of tags within which you want to disable tab variants … and other keyboard shortcuts.

1 Like