1

My goal is to typeset mathematics/physics more efficiently and more readable by remapping my keys to use the proper Unicode symbols.

Therefore, I want to remap my keys, such that pressing Alt Gr + Letter outputs special Unicode symbols, e.g. Alt Gr + a outputs , Alt Gr+ Shift + l outputs , or Alt Gr + h outputs ℏ.

I use Fedora and the solution should work under X11 and Wayland. It should also be (without too much work) "portable", e.g. to a laptop with another operating system (e.g. PopOS).

I searched online and (surprisingly because it seems like a fairly simple and not too uncommon task) did not find any recent, comprehensible guides on how to do that.

Can someone help me with that?

1 Answers1

0

This worked and was tested in X11, and should work for Wayland as well as per this discussion about the Wayland protocol. This method will be portable to any operating system using Xorg. Here is what has worked for me:

  1. Create a directory to save your custom keymap to, I like to create a .settings folder in my home directory, and create a subfolder named keyboard just to keep things organized.

  2. Create a file that will contain your keymap, say uc (a play on the 'us' keymap, but with a 'c' custom) with the following lines

default partial alphanumeric_keys
xkb_symbols "uc" {
    name[Group1]="uc";
    include "us(basic)"
    include "level3(ralt_switch_multikey)"

};

Here we basically just copy the default us keymap with the line include "us(basic)", and I chose to set the right alt to be my level 3 shift, which will be our custom symbols. This choice was somewhat arbitrary, and there are many other options you could choose that are all listed in the file

/usr/share/X11/xkb/symbols/level3

At this point run the following command to ensure that there are no typos or errors in our script setxkbmap ./uc.

  1. Let's add the symbols we want to our keyboard layout. For example, I am going to add the symbol U2200 (for all symbol) to the letter a. This is done by adding the following line beneath the second include statement:
key <AC01> { [a, A, U2200 ] };

Saving this file and running setxkbmap ./uc will now add that symbol to the keyboard, and by holding the right alt key down, pressing a produces a ∀ symbol. In this line, the <AC01> means we are going to be defining the a key on the keyboard, in the xkb_symbols section in this document, the rows of the keyboard are denoted AA, AB, AC, AD, and AE from bottom to top, and individual keys are listed 01 to the end of the keyboard (I haven't experimented much with this, but modifier keys and Tab are not counted, so z, a, and q are all key number 01 in their row), so the key AC01 is the first non-modifier key on the third row up of the keyboard, or rather, the a key. We then tell xkb to set the values of this key to a, A, and U2200 for levels one, two and three, respectively. Don't forget to list the actual letters for the key first, or you will not be able to type those characters after setting this as your keymap. Doing this for each of the keys you wish to edit will give you the symbols you wish to add to your keymap.

At this point, we have done enough to be able to set this as our keymap. To see how to make these changes permanent and be able to access our new keymap in keyboard menus in system settings, see my other answer here. This basically consists of linking this file to the right spot, and adding an entry for it in the evdev.xml file so your system can access it.

Good luck!

  • Thank you for your answer! I created the file, as you describe in step 2., and copied the lines you provided, but running the command setxkbmap ./uc leads to the error: Error loading new keyboard description. I am sure, that I just copied your lines of code and that I am in the right folder, with the right filename. I tried to debug it by myself and looked into some files in /usr/share/X11/xkb/symbols/, but your syntax seems right. (I tried putting first the includes and then the name, but this hasn't helped.) Do you have any idea,where this error could come from,or how to debug it? – Sinthoras May 21 '23 at 16:53
  • @Sinthoras I too ran into this same issue a while ago (and forgot to update this) if I recall correctly, what ended up working for me was creating a symlink to the file in the xkb directory. The instructions to do this are posted in another answer of mine, the link is in the last paragraph of this answer here. Hopefully that helps! – Braden Carlson May 21 '23 at 20:13
  • This almost worked. When I use the command setxkbmap the changes get applied, but the second part, making them permanent, did not work. I added my layout to the evdev.xml, (and rebooted afterwards,) but the layout does not show up in input sources in the keyboard settings. (I use gnome.) I'll accept this answer anyway, since it is really helpful. Do you have any idea, why the layout would not show up? – Sinthoras May 30 '23 at 21:19
  • @Sinthoras hmm, I'm not sure why that wouldn't be working. I have looked through the files where I created and evdev.xml is the only file I changed. There may be other files in the directory where evdev.xml is found that need to be changed? – Braden Carlson Jun 09 '23 at 04:12
  • I've got no idea. I could not find anything. – Sinthoras Jul 02 '23 at 20:38