I would like my LaTeX files to contain Unicode characters. For instance, I want to see
∃x.x ⟶ β
in my text editor, rather than
\exists x\ldotp x\longrightarrow\beta
Also, I would like to type these characters directly from my keyboard. For instance, I want
- to get "∃" by typing altE,
- to get "β" by typing altb, and
- to get "⟶" by typing alt-->.
I'm running Mac OS X, and my keyboard has a British layout.
Best Answer
There are two separate tasks here: making your keyboard produce the various Unicode symbols, and making those symbols meaningful to LaTeX.
1. Producing Unicode symbols from your keyboard
If you're on a Mac, make a
.keylayout
file, put it in the~/Library/Keyboard Layouts
directory, then log out and back in again. Your new keyboard layout should now appear in System Preferences > Language & Text > Input Sources.But how does one create this keylayout? I used an editor (such as Ukelele) but also ended up doing quite a bit of tweaking by hand. Keylayouts are written in XML, following Apple's specification. My keylayout is called
MathUnicode.keylayout
, and can be downloaded here. It is based on the British keylayout. I have given my keylayout a custom icon by savingMathUnicode.icns
(which can be downloaded here) in the same directory.I list below all of the key bindings in my layout. Note that, for instance, alt--> (which produces
⟶
) means "type --> while holding down the alt key". Note also that I have generally avoided notating the shift key (preferring P over shiftp, and so on) except where it makes the mnemonic more memorable.α (alpha) alta
β (beta) altb
γ (gamma) altg
Γ (Gamma) altG
δ (delta) altd
Δ (Delta) altD
ε (epsilon) alte
ζ (zeta) altz
η (eta) alth
θ (theta) alto
Θ (Theta) altO
ι (iota) alti
κ (kappa) altk
λ (lambda) altl
Λ (Lambda) altL
μ (mu) altm
ν (nu) altn
ξ (xi) altx
Ξ (Xi) altX
π (pi) altp
Π (Pi) altP
ρ (rho) altr
σ (sigma) alts
Σ (Sigma) altS
τ (tau) altt
υ (upsilon) altu
φ (phi) (altf
Φ (Phi) altF
χ (chi) altc
ψ (psi) alty
Ψ (Psi) altY
ω (omega) altw
Ω (Omega) altW
ℂ (complex numbers) altC
ℕ (naturals) altN
ℚ (rationals) altQ
ℝ (reals) altR
ℤ (integers) altZ
” (closing double quotes) alt'
“ (opening double quotes) alt`
¶ (paragraph) alt§
° (degrees) alt±
… (ellipsis) alt;
⌊ (lower left bracket) alt[
⌋ (lower right bracket) alt]
⌈ (upper left bracket) altshift[
⌉ (upper right bracket) altshift]
〈 (left angled bracket) alt<
〉(right angled bracket) alt>
⟦ (double left bracket) alt|[
⟧ (double right bracket) alt|]
↑ (up arrow) alt6
↓ (down arrow) alt7
⇑ (double up arrow) altshift6
⇓ (double down arrow) altshift7
← (left arrow) alt<-
→ (right arrow) alt->
↔ (left right arrow) alt<->
⇐ (double left arrow) alt<=
⇒ (double right arrow) alt=>
⇔ (double left right arrow) alt<=>
⟵ (long left arrow) alt<--
⟶ (long right arrow) alt-->
⟷ (long left right arrow) alt<-->
⟸ (long double left arrow) alt<==
⟹ (long double right arrow) alt==>
⟺ (long double left right arrow) alt<==>
↦ (maps-to) alt|->
⤇ (double maps-to) alt|=>
⟼ (long maps-to) alt|-->
⟾ (long double maps-to) alt|==>
⇀ (right harpoon) alt--`
⇝ (squiggly right arrow) alt~>
¬ (logical not) alt~
∨ (logical disjunction) alt\
∧ (logical conjunction) alt/\
∀ (for all) altA
∃ (exists) altE
∄ (does not exist) alt/E
.(ldotp, the dot in
∃x. p
) alt,⊦ (turnstile) alt|-
⊩ (double turnstile) alt||-
⊧ (models) alt|=
⟂ (bottom) alt _ | or alt| _
∅ (empty set) alt/0
∈ (member of) alt:
∉ (not member of) alt/:
∪ (union) altU
∩ (intersection) altI
⫛ (does not intersect) alt/I
⊂ (strict subset) alt(
⊃ (strict superset) alt)
⊆ (subset or equal) alt _ (
⊇ (superset or equal) alt _ )
∗ (centred asterisk) alt*
÷ (division) altshift/
× (times) alt8
| (bar) alt|
‖ (double bar) alt||
∤ (not bar) alt/|
◁ (left triangle) alt<|
▷ (right triangle) alt|>
◇ (diamond) alt<>
∘ (circle) alt0
· (centred dot) alt.
⊗ (circled times) alt08
⊛ (circled asterisk) alt0*
⊖ (circled minus) alt0-
⊕ (circled plus) alt0+
⊘ (circled slash) alt0/
⊙ (circled dot) alt0.
≝ (defined equal) altshift=
≠ (not equal) alt/= or alt=/
≡ (equivalent) alt==
≈ (approx) alt~~
≤ (less than or equal) alt _ < or alt< _
≥ (greater than or equal) alt _ >
∴ (therefore) altT
∵ (because) altB
∞ (infinity) alt9
∇ (nabla) altV
² (squared) altshift2
³ (cubed) altshift3
√ (root) altv
I have used this set-up for several years now, and am very happy with it. It is particularly useful when composing mathematical emails, where LaTeX is not available. The only snag I have found is that in some programs, some keyboard shortcuts that use alt no longer work. To tackle this, I configured the keyboard shortcut cmdspace so that I can switch back to my default British layout whenever necessary.
2. Getting LaTeX to understand Unicode symbols
Note: you're probably better off using XeTeX if you want Unicode in your LaTeX source files. But let's suppose you want to stick with vanilla LaTeX for the time being.
I save the following in the file
MathUnicode.sty
and include theMathUnicode
package in all my LaTeX files (that is, by putting\usepackage{MathUnicode}
in the preamble).