Excellent, @pireddag thank you for your reply. I have now figured out how to do this by looking at the math-kbd.scm
file, which on a Mac I found in /Applications/TeXmacs.app/Contents/Resources/share/TeXmacs/progs/math/math-kbd.scm
.
Now, regarding creating my own shortcuts, as it seems to be recommended in this forum, I edited the my-init-texmacs.scm
file, the process for which I will describe below, in case other want to do something similar.
Creating/Editing TeXmacs Shortcuts
Here I will describe, as I understand it, how to create/edit TeXmacs keyboard shortcuts.
Step 1: Enable Developer Mode
Start up TeXmacs, and activate the Developer Mode by clicking Tools > Developer Mode
in the tool bar.
This will enable a new toolbar menu item called Developer
.
Step 2: Access my-init-texmacs.scm
Next, via this Developer menu, we can access the my-init-texmacs.scm
file by clicking
Developer > Open my-init-texmacs.scm
in the toolbar.
This will open the file
my-init-texmacs.scm
in a new TeXmacs window.
If one wishes, one can also access the my-init-texmacs.scm
file directly using your preferred text editor via /Users/spaceman/.TeXmacs/progs/my-init-texmacs.scm
. To be able to view the folder .TeXmacs
in Finder, you must enable hidden files.
The text editor used will not matter here, so I will use VSCode.
Step 3: Adding Keyboard Shortcuts
Currently defined math keyboard shortcuts can be found in math-kbd.scm
(for directory location, see above), and one can use this as a reference for defining new keyboard shortcuts.
I should note that, as far as I understand, any keyboard shortcuts defined in my-init-texmacs.scm
will “overwrite” (more precisely redefine) any keyboard shortcuts that are similarly defined in math-kbd.scm
.
A snapshot of math-kbd.scm
shows the following keyboard shortcuts written in Scheme that refer to creating a new variant of a symbol in math mode via the command var
.
To create a new keyboard shortcut, one needs to write these within a kbd-map
environment.
Following this, if we wish to create a math based keyboard shortcut, which only works within math mode, we need to specify that the keyboard shortcuts within this kbd-map
environment should only work within math mode via the command (:mode in-math?)
. If you further wish for this command to only work outside of the so-called hybrid environment (which is the environment you enter when you press the key \
), we instead write (:mode in-math-not-hybrid?)
.
Now, on line 1672
we see that command ("a var" "<alpha>)
, which tells TeXmacs that when we type a + Tab
in math mode (outside hybrid), I want it to replace a
with <alpha>
. Now, we can guess by the naming of the command <alpha>
that this corresponds to the greek letter \alpha. Although, if we wish, we can search through the contents of TeXmacs in /Applications/TeXmacs.app/Contents/
to determine that in the file tmuniversaltounicode.scm
, <alpha>
corresponds to the unicode character #03B1
Personal Keyboard Shortcuts
Now we move on to the keyboard shortcuts. I will define here only the one that is of interest to me in this post, which is defining a variant on the R + R
command (which creates \mathbb{R}) to produce \mathcal{R}. For this, we now move over to the my-init-texmacs.scm
file.
Within it, in theory to create the desired behaviour we would write (where ;; ...
denotes comments).
where <cal-R>
corresponds to calligraphic R, and similarly for all the other letters.
Although, there seems to be a bug with TeXmacs where this is not enough when defining shortcuts in my-init-texmacs.scm
. Instead, following the comments made here, one needs to instead wrap the kbd-map
environment in a delayed ... lazy-keyboard-force
environment to make the shortcuts work:
Then, voila! We are essentially done. One can repeat this for any other shortcuts as desired. For example, I have performed this for whole alphabet.
Note: I believe in the following, instead of var
one may also use the term tab
for the same effect.
Step 4: Finishing Touches
We now save the file my-init-texmacs.scm
and restart TeXmacs by closing/quitting all active windows on TeXmacs and then starting a new instance of TeXmacs.
Demonstration
Here is a demonstration of the working code.
I hope this helps. If I have misunderstood anything, please feel free to let me know.