Change shortcuts for math subscript (from ^ to Ctrl+6) and superscript (from _ to Ctrl+-)

Since I’m using TeXmacs and Mathematica recently and they have different shortcuts for super and subscripts. For convenience, I would like to change the shortcuts for subscript and superscript in TeXmacs. I find math-kbd.scm and the following lines seem to be relevant:

  ("_" (make-script #f #t))
  ("_ var" "_")
  ("^" (make-script #t #t))
  ("^ var" "^")

However, I’m not sure how I can modify to change the shortcut for subscript from _ to Ctrl+-, and that for superscript from ^ to Ctrl+6, i.e. changing the first key from Shift to Ctrl.

For the subscript, this worked:

(kbd-map ("C--" (make-script #f #t)))

In "C--" the first dash indicates that the previous key is the control-key, not the letter C, and that the next key, which is the dash, is pressed simultaneously to the control-key.
I expect that it is possible to add a shortcut for superscripts in an analogous way; this worked:

(kbd-map ("C-^" (make-script #t #t)))

and it seems to me that one obtains the same shortcut as in Mathematica, it might be necessary to adapt it for different keyboard layouts even if I do not see why while I am writing. For your Ctrl+6:

(kbd-map ("C-6" (make-script #t #t)))

G.

Thank you! Do I add these pieces of code at the end of math-kbd.scm?

Not in math-kbd.scm because if you update TeXmacs to a new version these changes would be overwritten or would be in a file that the new version of TeXmacs does not read.
Rather in my-init-texmacs.scm , the personal initialization file. It is in the .TeXmacs/progs directory, One way to find this file is through the Developer menu, which appears if you select the Developer tool under the Tools menu; there is a menu item “Open my-init-texmacs.scm”.

2 Likes

Thank you! It works well.