Change system's default shortcut for symbols

Is it possible to change the default shortcut for input symbols?
E.g., in Wolfram Mathematica (and also for my personal keyboard layout), the Greek letter χ can be typed by esc-c-esc (or by ctrl-c for my keyboard layout), but in TeXmacs the corresponding action c-tab gives a rarely-used (at least for me) symbol ς, i.e., [FinalSigma] with unicode 03C2.

And there are many other default shortcuts which are not logical enough for me.

Can I change these default shortcuts to the ones I’d like?

BTW, on MacOS, where is $TEXMACS_PATH?

Launch a Shell session, and:

echo $TEXMACS_PATH
1 Like

ok, just got your point.
I should open a Shell session from inside texmacs, not from Terminal…

In the manual I find the following discussion which seems to be related to my question:


But I still feel clueless. Can anyone give an explicit example of how to do this?

You can, for example, look into

$TEXMACS_PATH/progs/progs/math/math-kbd.scm

to see how the current bindings are defined. E.g you could do

(kbd-map
  (:mode in-math-not-hybrid?)
  ("c var" "<chi>"))

to redefine the keybindg for chi as you prefer.

1 Like

I tried this out of curiosity and it works in my-init-buffer.scm, but not in my-init-texmacs.scm (where other things—I have tried (kbd-map ("h i ." (insert "Hi there!")))—work).

Is math-kbd.scm executed after my-init-texmacs.scm?

1 Like

Thanks to you all @darcy @mgubi @pireddag
I finally managed to change these default keybinding!
My personal solution is just to comment out the default setting and add my own in

$TEXMACS_PATH/progs/progs/math/math-kbd.scm

This will not survive an update of TeXmacs. As written somewhere in the Help some of the scheme files are not loaded just right away at the boot but delayed to have faster response. So it could happen that you redefine the bindings before they are actually defined, and then when the system bindings are loaded they will change yours. In particular in $TEXMACS_PATH/progs/init-texmacs.scm you can see the following lines:

;(display "Booting math mode\n")
(lazy-keyboard (math math-kbd) in-math?)
(lazy-keyboard (math math-sem-edit) in-sem-math?)
(lazy-menu (math math-menu) math-format-menu math-format-icons
           math-menu math-insert-menu
           math-icons math-insert-icons
           math-correct-menu semantic-math-preferences-menu
           context-preferences-menu insert-math-menu)
(lazy-initialize (math math-menu) (in-math?))
(lazy-define (math math-edit) brackets-refresh)

which load lazily the math mode. In $TEXMACS_PATH/progs/kernel/gui/kbd-define.scm you see the definition of lazy-keyboard. There is a procedure (lazy-keyboard-force) which you need to run before you redefine the keybinding, in order to be sure that it is operative. I think also another possibility is to create a copy of math-kbd.scm in your $TEXMACS_HOME_PATH, i.e. in

$TEXMACS_HOME_PATH/progs/progs/math/math-kbd.scm

and this will be found before the system one. But this solution prevents updates to this module, so it could generate bugs whenever new versions of TeXmacs change these functionalities in some way. HTH.

Btw, environment variables are also accessible via scheme. E.g.

(getenv "TEXMACS_PATH")

or

(environ)

See https://www.gnu.org/software/guile/manual/html_node/Runtime-Environment.html

Adding (lazy-keyboard-force) in my-init-texmacs.scm TeXmacs crashes:

Throwing no active view
-------------------------------------------------
Error message:
  no active view

System information:
  TeXmacs version  : 1.99.17
  Built by         : magix
  Building date    : Wed Dec  9 15:18:43 CET 2020
  Operating system : linux-gnu
  Vendor           : pc
  Processor        : @CONFIG_HOST_CPU@
  Crash date       : Di 22 Dez 2020 15:03:48 CET

TeXmacs does not yet have a current view
Backtrace of C++ stack:
  texmacs.bin() [0x10287c5]
  texmacs.bin() [0x59f698]
  texmacs.bin() [0xd67faa]
  texmacs.bin() [0xb52985]
  texmacs.bin() [0x1b4a39e]
  texmacs.bin() [0x1b45e96]
  texmacs.bin() [0x1b474e5]
  texmacs.bin() [0x1b447c7]
  texmacs.bin() [0x1b4494e]
  texmacs.bin() [0x1b630fc]
  texmacs.bin() [0x1b6311e]
  texmacs.bin() [0x1ba8ed9]
  texmacs.bin() [0x1ba8fe8]
  texmacs.bin() [0x1ba8b9d]
  texmacs.bin() [0x1ba8ccc]
  texmacs.bin() [0xbe5184]
  texmacs.bin() [0xd779d5]
  texmacs.bin() [0x1037b6c]
  texmacs.bin() [0x10383fd]
  texmacs.bin() [0x40fb1c]
  texmacs.bin() [0x1b600c7]
  texmacs.bin() [0x1bc296d]
  texmacs.bin() [0x1ba8b9d]
  texmacs.bin() [0x1bc2909]
  texmacs.bin() [0x1bc29f0]
  texmacs.bin() [0x1ba6c46]
  texmacs.bin() [0x1ba6c07]
  texmacs.bin() [0x1b60050]
  texmacs.bin() [0x415201]
  /lib/x86_64-linux-gnu/libc.so.6 : __libc_start_main() + 0xf2
  texmacs.bin() [0x40ecb9]

-------------------------------------------------
terminate called after throwing an instance of 'string'

By the way, for @vac: it is convenient to do like @mgubi says, putting your modifications in user files (in my-init-buffer.scm it will work, in my-init-texmacs.scm, which it feels like it is the right place, I am still trying as you see).

I have found the place in the manual where it is explained how to redefine keyboard shortcuts. It is in the Scheme developer manual, 1.4. The module system and lazy definitions.

It might be that (lazy-keyboard-force) is meant to be executed from plugin initialization files, on the other hand it seems to be sensible to put keyboard shortcuts in my-init-texmacs.scm. Might it be that (lazy-keyboard-force) crashing TeXmacs when executed inside my-init-texmacs.scm is a bug?

Yes, I think is a bug. Maybe should be filed, in the meantime one can do as follows. In my-init-texmacs.scm put

(delayed
 (lazy-keyboard-force)
 (kbd-map
  (:mode in-math-not-hybrid?)
  ("c var" "<chi>")))

This should not crash TeXmacs and work.

2 Likes

Thanks, now it works.

Thanks for the insight. I’ve adopted to your suggestion.