Unicode keyboard substitutions globally in MacOS

If like me you love the tab-completions in the julia REPL and in jupyter notebooks, and want to be able to use them everywhere in MacOS (for example while writing an email), you may find this useful. I generated this plist file which you can download and then drag into System Preferences > Keyboard > Text (straight into the substitutions box on the left). Now you should be able to use the unicode substitutions in most applications.

14 Likes

Wow, this is brilliant. Works like a charm!

This is almost great but for some reason \alpha and \beta complete to A and B, whereas \gamma and \delta work. They look fine in the Keyboard - Text box.

Yes, same here, that’s very odd. With just the following plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
    <dict>
        <key>phrase</key>
        <string>α</string>
        <key>shortcut</key>
        <string>\alpha</string>
    </dict>
    <dict>
        <key>phrase</key>
        <string>Α</string>
        <key>shortcut</key>
        <string>\Alpha</string>
    </dict>
</array>
</plist>

it works absolutely fine…

Here’s the julia code to generate the entire plist:

header = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>"""
footer = """</array>
</plist>"""

import REPL
symbols = union(REPL.REPLCompletions.latex_symbols,
                      REPL.REPLCompletions.emoji_symbols)
println(header)
for (command, character) in symbols
    item = """
        <dict>
            <key>phrase</key>
            <string>$character</string>
            <key>shortcut</key>
            <string>$command</string>
        </dict>
    """
	print(item)
end
println(footer)
3 Likes

Right! It turns out MacOS does some automatic capitalisation of substitutions, and so it was getting confused by \alpha and \Alpha both being defined (I still don’t fully understand what’s happening under the hood). The good news is that by simply deleting the \Alpha substitution (and all other capital letters), it now works perfectly, as MacOS automatically capitalises the alpha. So I’ve updated the plist in the above link. And here’s the updated julia code to generate the plist:

header = """<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>"""
footer = """</array>
</plist>"""

import REPL
symbols = union(REPL.REPLCompletions.latex_symbols,
                      REPL.REPLCompletions.emoji_symbols)
symbolset = Set(kv[1] for kv in symbols)
println(header)
for (command, character) in symbols
	if (lowercase(command) != command) & (lowercase(command) ∈ symbolset)
		continue
	end
    item = """
        <dict>
            <key>phrase</key>
            <string>$character</string>
            <key>shortcut</key>
            <string>$command</string>
        </dict>
    """
	print(item)
end
println(footer)

Edit: And if you find that some of the subscript shortcuts like \_i → ᵢ don’t work, then try deleting all the emojis from the substitutions table. My hypothesis is that there’s an undocumented limit on the number of substitutions (perhaps 2048?) and substitutions that are low in the alphabetical order (high in the table) get silently dropped after it is exceeded.

3 Likes

Unfortunately, the drag-n-drop part doesn’t work for me. I’m dragging the plist file into the substitutions box and the arrow also gets a little green plus sign but when I drop it nothing happens. I’m on Catalina 10.15.4

Update: The short plist with just \alpha and \Alpha from above works fine but the one in the gist does not. :frowning:

2 Likes

The following works fine for me: https://raw.githubusercontent.com/tslmy/latex-input-iOS-macOS/master/LaTeX.plist

2 Likes

Made an AutoHotkey script for Windows users: Unicode latex substitutions from julia for AutoHotkey · GitHub

The file needs to be resaved with UTF-8 BOM encoding, otherwise it spits out weird stuff. Also substitution needs to be completed with a Tab.

I’m having the same issue, and I’m on Mac Os Big Sur 11.6.