Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
So by "alt", do you mean the mac option key (⌥)? –  Matthew Leingang Apr 22 '13 at 15:04
    
Yep, the key labelled either as "opt ⌥" or as "alt ⌥" depending on your Mac model. –  John Wickerson Apr 22 '13 at 15:06
    
See also: tex.stackexchange.com/questions/1979/… –  Caramdir Apr 22 '13 at 21:01
add comment

1 Answer

up vote 21 down vote accepted

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 saving MathUnicode.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 the MathUnicode package in all my LaTeX files.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Created by John Wickerson, 07 Jan 2010.
% Updated 28 Mar 2010.
% For use with the MathUnicode keyboard layout.

\RequirePackage[T1]{fontenc}
\RequirePackage[utf8x]{inputenc}
\RequirePackage{amssymb}
\RequirePackage{stmaryrd}

\DeclareUnicodeCharacter{183}{\cdot}
\DeclareUnicodeCharacter{915}{\ensuremath{\Gamma}}
\DeclareUnicodeCharacter{916}{\ensuremath{\Delta}}
\DeclareUnicodeCharacter{918}{\ensuremath{\Zeta}}
\DeclareUnicodeCharacter{920}{\ensuremath{\Theta}}
\DeclareUnicodeCharacter{923}{\ensuremath{\Lambda}}
\DeclareUnicodeCharacter{926}{\ensuremath{\Xi}}
\DeclareUnicodeCharacter{928}{\ensuremath{\Pi}}
\DeclareUnicodeCharacter{931}{\ensuremath{\Sigma}}
\DeclareUnicodeCharacter{933}{\ensuremath{\Upsilon}}
\DeclareUnicodeCharacter{934}{\ensuremath{\Phi}}
\DeclareUnicodeCharacter{935}{\ensuremath{\Chi}}
\DeclareUnicodeCharacter{936}{\ensuremath{\Psi}}
\DeclareUnicodeCharacter{937}{\ensuremath{\Omega}}
\DeclareUnicodeCharacter{945}{\ensuremath{\alpha}}
\DeclareUnicodeCharacter{946}{\ensuremath{\beta}}
\DeclareUnicodeCharacter{947}{\ensuremath{\gamma}}
\DeclareUnicodeCharacter{948}{\ensuremath{\delta}}
\DeclareUnicodeCharacter{949}{\ensuremath{\epsilon}}
\DeclareUnicodeCharacter{950}{\ensuremath{\zeta}}
\DeclareUnicodeCharacter{951}{\ensuremath{\eta}}
\DeclareUnicodeCharacter{952}{\ensuremath{\theta}}
\DeclareUnicodeCharacter{953}{\ensuremath{\iota}}
\DeclareUnicodeCharacter{954}{\ensuremath{\kappa}}
\DeclareUnicodeCharacter{955}{\ensuremath{\lambda}}
\DeclareUnicodeCharacter{956}{\ensuremath{\mu}}
\DeclareUnicodeCharacter{957}{\ensuremath{\nu}}
\DeclareUnicodeCharacter{958}{\ensuremath{\xi}}
\DeclareUnicodeCharacter{959}{\ensuremath{\omicron}}
\DeclareUnicodeCharacter{960}{\ensuremath{\pi}}
\DeclareUnicodeCharacter{961}{\ensuremath{\rho}}
\DeclareUnicodeCharacter{963}{\ensuremath{\sigma}}
\DeclareUnicodeCharacter{964}{\ensuremath{\tau}}
\DeclareUnicodeCharacter{965}{\ensuremath{\upsilon}}
\DeclareUnicodeCharacter{966}{\ensuremath{\phi}}
\DeclareUnicodeCharacter{967}{\ensuremath{\chi}}
\DeclareUnicodeCharacter{968}{\ensuremath{\psi}}
\DeclareUnicodeCharacter{969}{\ensuremath{\omega}}
\DeclareUnicodeCharacter{8214}{\parallel}
\DeclareUnicodeCharacter{8450}{\mathbb{C}}
\DeclareUnicodeCharacter{8470}{\mathbb{N}}
\DeclareUnicodeCharacter{8474}{\mathbb{Q}}
\DeclareUnicodeCharacter{8477}{\mathbb{R}}
\DeclareUnicodeCharacter{8484}{\mathbb{Z}}
\DeclareUnicodeCharacter{8614}{\mathbin{\mapsto}}
\DeclareUnicodeCharacter{8656}{\Leftarrow}
\DeclareUnicodeCharacter{8657}{\Uparrow}
\DeclareUnicodeCharacter{8658}{\Rightarrow}
\DeclareUnicodeCharacter{8659}{\Downarrow}
\DeclareUnicodeCharacter{8669}{\rightsquigarrow}
\newcommand{\eqdef}{\stackrel{{\scriptsize\rm def}}{=}}
\DeclareUnicodeCharacter{8797}{\eqdef}
\DeclareUnicodeCharacter{8870}{\vdash}
\DeclareUnicodeCharacter{8873}{\Vdash}
\DeclareUnicodeCharacter{8871}{\models}
\DeclareUnicodeCharacter{9121}{\lceil}
\DeclareUnicodeCharacter{9123}{\lfloor}
\DeclareUnicodeCharacter{9124}{\rceil}
\DeclareUnicodeCharacter{9126}{\rfloor}
\DeclareUnicodeCharacter{9655}{\triangleright}
\DeclareUnicodeCharacter{9665}{\triangleleft}
\DeclareUnicodeCharacter{9671}{\diamond}
\DeclareUnicodeCharacter{9675}{\circ}
\DeclareUnicodeCharacter{10178}{\bot}
\DeclareUnicodeCharacter{10214}{\llbracket} % needs stmaryrd
\DeclareUnicodeCharacter{10215}{\rrbracket} % needs stmaryrd
\DeclareUnicodeCharacter{10229}{\longleftarrow}
\DeclareUnicodeCharacter{10230}{\longrightarrow}
\DeclareUnicodeCharacter{10231}{\longleftrightarrow}
\DeclareUnicodeCharacter{10232}{\Longleftarrow}
\DeclareUnicodeCharacter{10233}{\Longrightarrow}
\DeclareUnicodeCharacter{10234}{\Longleftrightarrow}
\DeclareUnicodeCharacter{10236}{\longmapsto}
\DeclareUnicodeCharacter{10238}{\Longmapsto} % needs stmaryrd
\DeclareUnicodeCharacter{10503}{\Mapsto}    % needs stmaryrd
\DeclareUnicodeCharacter{10971}{\mathrel{\not\hspace{-0.2em}\cap}}
\DeclareUnicodeCharacter{65294}{\ldotp}
\DeclareUnicodeCharacter{65372}{\mid}
share|improve this answer
2  
You could also use the newunicodechar-package, then instead of \DeclareUnicodeCharacter{951}{\ensuremath{\eta}} you can write \newunicodechar{η}{\ensuremath{\eta}}. –  ralfix Apr 22 '13 at 15:52
    
@ralfix Yes, that's a sensible suggestion. I tried it, though, and it seems that the newunicodechar package doesn't play well with the utf8x encoding, and my package doesn't play well without it. So I have to leave it as-is for the time being, unless somebody is able to clarify the situation... –  John Wickerson May 29 '13 at 9:46
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.