Creating a scientific keypad for Mac

I wrote earlier about using an inexpensive numeric keypad as an emoji keyboard for Mac.

Since I like to think that I write for science as much as I write with emojis, it might also be useful to have a customized keyboard for symbols I frequently use in papers, reports and presentations.

The symbols I very frequently use are mathematic symbols/characters such as µ, δ, ε, λ — I use lower case ones more than the upper case versions. The exception to this is Σ, which I’ll often use in my notes to indicate summation of terms, and similarly Π, which I use to indicate products.

I do use math equation editors for for writing equations in papers, but for notes, sometimes it’s nice just to quickly access symbols. For example, in my group’s air pollution papers, you wouldn’t believe how many times we write about PM2.5 concentrations and need write units of ug/m3.

Aha! See I cheated above. I used “u” instead of the correct µ symbol in µg.

Oh oh! I cheated again. I used m3, when it should be m³.

Wouldn’t it be nice if I had a dedicated keyboard key for µ and a dedicated key for ³?

Or better yet, wouldn’t it be cool if I just pressed a single key, and my keyboard would type the correctly formated µg/m³ into my paper?

As I wrote in my other guide, the problem with Mac is that the most common keyboard remapping software Karabiner-Elements doesn’t make it easy to remap keys to unicode characters. There’s a series of steps that I used to solve this problem, which I’ll go through again below, but this time for a creating scientific keypad…

On a Mac, there are some options for accessing mathematical symbols.

Most Mac users already know that you can just press Ctrl + Command + Spacebar to bring up a software keyboard that allows you to select emoji to insert into text. It looks like below. But, where are the math symbols?! Looking at the bottom row, you can see this software keyboard includes face emojis, animal face emojis, shakes and hamburgers, etc… But come on, no math?!

How insulting — Where’s the math?!

It turns out, we need to work a bit harder to see math symbols. If you press on the icon in the upper right of the emoji window, you get to the full Character Viewer, which has a section for Math Symbols, and within that if you scroll (a lot) down, you’ll see µ, δ, ε, etc.

I also do something which is really stupid, but works. I Google search for “mu symbol”, and it will show me a list of results so that I can literally copy and paste a µ into the document I’m working on.

Some of you may also know that you can change the keyboard layer on a Mac by pressing the Option key and the Option + Shift keys, and this also allows you to enter in certain symbols. Here’s a guide with some examples. Option + m will actually type a µ character!

None of these solutions are as elegant or fun as having a physical hardware Science keyboard for my Mac.

I already use a software called Karabiner-Elements to remap keys on my main keyboard. And, so I thought that I could simply buy a cheap numeric keypad on Amazon, and then also use Karabiner-Elements to remap the keys on the numeric keypad to enter unicode for emojis. It turns out though it’s not obvious how to use Karabiner-Elements to enter unicode values.

Here’s how I solved it.

Bought a numeric keypad (I got this one for free from Amazon (paid ad)). But, there are many that would likely work. The link to the product above and below are ads.

(Paid ads)

Install Karabiner-Elements if you don’t already use it. Not Karabiner-Elements allows for “simple” key modifications, but it’s not possible at this current time to remap key presses into unicode. “Complex” key modifications allow you to enter unicode (more on this below).

On your Mac, in Systems Preferences, go to Keyboard settings. Under the Input Sources tab, press the + icon at the lower left, and add the “Unicode Hex input” keyboard. After doing so you should see this in your settings:

You can toggle between your keyboard input sources (e.g., in my case, the U.S. vs the Unicode Hex input) by pressing Ctrl + Spacebar. On my Mac, I can see in the upper-right of the menu bar what keyboard method I’m current using (that’s the because above in settings, there’s a check in the box for “Show input menu in menu bar”).

When your in the Unicode Hex input mode, you can enter unicode e.g., unicode for the μ symbol is U+03BC. The 03BC are hexidecimal characters. These characters are what you’d type into the Unicode Hex input keyboard. Do this by:

Pressing Ctrl + Spacebar to go into Unicode Hex input mode. Then press and hold down the Option key and then press the keys: 0 3 b c. Then release the Option key. You should then see the symbol μ typed into whatever document you’re working in. (Remeber to press Ctrl + Spacebar again afterwards to return to your normal keyboard input mode).

There are unicode defined for various math symbols and Greek characters. See this website for various symbols nicely categorized. Go through and pick the ones you commonly use, and make a note of the unicode, e.g., U+03BC for the mu symbol.

Most of the math symbols are 4 hexidecimal digits thankfully. But if you come across 5-digit unicode, see my other guide for how to handle them as Surrogate Pairs.

So above, we saw how we could use the Mac’s Unicode Hex Input mode to type the unicode for mu. Now how do we get Karabiner-Elements to enter these key strokes so that we can remap key presses from the numeric keypad? We need to setup “complex” modifications in Karabiner-Elements.

To setup “complex” modifications, open up Karabiner-Element’s configuration file in a text editor. This is a file called karabiner.json. On my computer it was located in this directory (substitute your username where mine is): /Users/edmundseto/.config/karabiner/karabiner.json

Make a backup of your original karabiner.json file in case you mess it up, and need to restore it. — You’ve been warned!

Instructions for modifying the json file for complex modifications is on Karabiner-Elements’ website here. But, it’s helpful to show an example of how I got unicode to work. This is what my karabiner.json looks like:

{
"global": {
... various stuff here...
},
"profiles": [
{
"complex_modifications": {
"parameters": {
... various stuff here...
},
"rules": [
{
...stick a complex modifications here...
},

{
...stick another complex modifications here...
}
],
"type": "basic"

}
]
... remaining stuff here....

Note that above I’ve got two spots for complex modifications. Each of these spots could be used for remaping a keypad press to a math symbol. And you can add more by just comma-separating the { } sections as I’ve shown.

Now what goes into the complex modifications section? It’s the code that tells Karabiner-Elements to replicate the key presses we did before for typing the mu symbol:

"description": "Math symbol mu.",
"manipulators": [
{
"conditions": [
{
"identifiers": [
{
"description": "2.4G Keyboard Mouse (MOSART Semi.)",
"product_id": 16641,
"vendor_id": 1578

}
],
"type": "device_if"
}
],
"from": {
"key_code": "keypad_1"

},
"to": [
{
"key_code": "spacebar",
"modifiers": [
"left_control"
]
},
{
"key_code": "0",
"modifiers": [
"left_option"
]
},
{
"key_code": "3",
"modifiers": [
"left_option"
]
},
{
"key_code": "b",
"modifiers": [
"left_option"
]
},
{
"key_code": "c",
"modifiers": [
"left_option"
]
},

{
"key_code": "spacebar",
"modifiers": [
"left_control"
]
}
],
“type”: “basic”
}
]

The above code goes into the earlier code that I boldfaced “…stick a complex modifications here…”. If you look at the code, you’ll see that it substitutes the numeric key 1 (keypad_1) for a series of keystrokes that will first activate the Unicode Hex input mode on Mac, then enter the keystokes for the unicode representing the mu symbol, and then it finishes by deactivating the Unicode Hex input mode.

Note the section above that’s in bold for product_id and vendor_id. This restricts this complex modification only to the physical keyboard device that matches these IDs. To get these, I opened Karabiner-Elements’ Settings, and under “Devices”, you’ll see a listing of all your input devices. Find the one that matches your numeric keypad device, and you’ll see the Vender ID and Product ID listed. You’ll want to change the code to use the IDs that match your specific device.

After making changes to the json file, save it. It should automatically be re-read by Karabiner-Elements, and will work without having to restart/reboot.

Try it out, by pressing the keypad (in my example keypad 1), and you should see a µ character typed into your document.

At this point, if you can add code for other symbols to the json file. You can also relabel the keycaps on your keypad to your math symbols.

Also, if you want an emoji keypad to go along with your science keyboard, there’s no reason why you couldn’t have two keypads! Or how about trying to customize one of these massive keypads?!

(Paid ad)

Enjoy!








As an Amazon Associate I earn from qualifying purchases.
Feature photo by Ok_Paleontologist on Reddit.