macekmar/math-keyboard

Scripts for writing (mathematical) unicode characters

★ 0Forks 0PythonGitHub ↗Compare

README

README

This repository contains scripts for macOS (using Hammerspoon) and Windows (planned, using AutoHotKey) for easy input of Unicode characters (and their LaTeX codes). It is inspired by the space-cadet keyboard and the pain of writing equations in emails or comments in PDF files.

The simplest and most common way to customize the behavior is by editing the Markdown tables and then rerunning the scripts.

Use of scripts

If everything goes well, Cmd + F12 should toggle between Unicode and LaTeX output modes. The following key combinations should produce

  • Caps Lock + d → δ or \delta
  • Caps Lock + Shift + d → Δ or \Delta
  • F12 + d → ∂ or \partial
  • F12 + Shift + d → ∇ or \nabla

Table of mappings

Currently, each keyboard key supports four combinations. These combinations are saved in the Markdown tables (Table_X.md) of five columns. The table is organized by keyboard lines (1234... vs asdf...). The first two columns use CapsLock and CapsLock + Shift (which we call hyper) and are mainly for Greek charecters. The last two columns use F12 (which we call meta) and are mainly for mathematical operators.

Note, that we map q to α because Hammerspoon has (had?) a problem with using a.

macOS

Setup of modifier keys for macOS

You need two programs:

The first one maps keys to something else. It is not strictly needed, since one could use only the existing keys for modifiers, e.g., F11 or F12. In this setup, I use Karabiner to map the Caps Lock key to F19.

Karabiner

In karabiner > Settings > Complex Modifications, click on Add your own rule and insert the following codes, which are in karabiner.md. Note, that I only modify the Caps Lock (it maps to F19). You can find Karabiner as a karabiner icon in the top bar.

Hammerspoon

  1. Parse the desired table (e.g., for Unicode mapping in Table_unicode.md) into a dictionary (use parse_table.parse_table).
  2. Write down the Lua configuration files for Hammerspoon (use mac.mac.write_config)
  3. Copy the scripts unicode.lua and latex.lua into ~/.hammerspoon/.
  4. Load the configuration file into Hammerspoon: Hammerspoon > Open Config and copy the contents of mac/init.lua.

You should write both scripts: for Unicode and LaTeX. Everything is in write_config.py.

If you prefer to store the script in a different location (than ~/.hammerspoon/) or named differently, you can change variables config1 and config2 in mac/init.lua

If you only want one script (Unicode without LaTeX), I guess this init.lua script should work:

pasteboard = hs.pasteboard.uniquePasteboard()

-- Define the paths to your configuration files
local config1 = os.getenv("HOME") .. "/.hammerspoon/unicode.lua"
dofile(config1)

Windows

TODO

Contributors

macekmar

Issues