Curly letters with tab shortcut

I know that blackboard (i.e. \mathbb) can be inserted by holding shift and pressing the letter twice, e.g. shift + R + R produces \mathbb{R}.

Is there a way to do something similar with curly letters (i.e. \mathcal)? For example, is it possible to either do:

  • Shift + B + B + tab
  • Shift + B + B + B
  • B + tab + ... + tab
    to produce a curly B, \mathcal{B} (and same with all the other letters)?

Copying a letter R obtained with \mathcal to “TeXmacs Scheme” I obtain (with "font" "cal" "R") (one can see it from source mode as well).
Given this, you need to supply a keyboard shortcut for that construct.
With a few searches I found that there is a shortcut that does that:

("font C" (make-with "math-font" "cal"))

(see math/math-kbd.scm), but I do not know how to use it. If anyone knows, then you don’t need to make up a keyboard shortcut yourself.
In the manual I found out the section “Typing mathematical symbols”, where I learned how to do bold calligraphic symbols, which is almost what you want.
Maybe someone knows how to type the "font C" keyboard shortcut or what is the shortcut for regular calligraphic symbols.

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.
25

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
59

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).
15
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:
21

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.

2 Likes

I did not yet read in detail your post but it looks nice. Perhaps one could link to this post in the TeXmacs blog. I did write post on topic on the blog (https://texmacs.github.io/notes/docs/menu-shortcuts.html) but it may be worth adding a link to this step-by-step illustrated guide as well.

This is not necessarily the case. That’s why you will often see “delays” in keyboard shortcuts, to make sure the user’s shortcut definition comes last.

Edit: I see now you discovered this as well. This is not a bug though. This kind of lazy definitions are done so that they can be done when the CPU is idle without slowing down startup.