## Unicode in LaTeX

The way I type LaTeX has changed significantly in the past couple of months. I now type most of my math formulae in unicode, which makes the source code much more readable.

A few months ago, I might have written

$\lambda/\mu=\kappa/\nu \Rightarrow \exists \Theta,\forall i, \sum_{j\in\mathbb{N}} E[D_{i,j}]=\Theta$

to display

$\lambda/\mu=\kappa/\nu \Rightarrow \exists \Theta,\forall i, \sum_{j\in\mathbb{N}} E[D_{i,j}]=\Theta$.

Now, to type the same equation, my LaTeX source code looks like this:

$λ/μ=κ/ν ⇒ ∃Θ,∀i, ∑_{j∈ℕ} E[D_{i,j}]=Θ$

which produces exactly the same output. The source code is much easier to read; it is also slightly easier to type. Here is how the magic works:

\usepackage[utf8x]{inputenc}
\usepackage{amssymb}
• A number of special characters (including all Greek letters) were already easily available to me because I use a bépo keyboard (if you are a French speaker, you should try it out); otherwise, all characters are available using any keyboard to users of a Unix-like OS thanks to this great .XCompose file. For example, to get ℕ, use the keys Compose+|+N (pretty intuitive, and faster than typing \mathbb{N}). To get ∃, use Compose+E+E; to get ∈, use Compose+i+n, and so on.
• There are two issues with this solution: first, the unicode symbol α maps to \textalpha instead of \alpha; second, the blackboard letters map to \mathbbm instead of \mathbb. This can lead to errors, but I wrote this file which solves the issue by including in the preamble:
\input{greektex.tex}

This is useful for LaTeX, but also for all other places where you might want to type math: thanks to this .XCompose file, typing math in a blog post, tweet or e-mail becomes easy (for example, this is the last blog post where I will use WordPress’ \$latex syntax). And if there ever is a LaTeX formula that you cannot access from your keyboard, you can use a website such as unicodeit.net which converts LaTeX source code to unicode.

Tags: ,

### 5 Responses to “Unicode in LaTeX”

1. Dennis Says:

Hi Robin, this is a very nice idea. After a little search I found a similar emacs mode http://www.emacswiki.org/emacs/TeXInputMethod which I will try using although it’s not quite as comprehensive e.g. for blackboard letters.

2. Nicolas Chopin Says:

Hi, interesting, but I wonder if journals and co-authors would accept such a latex file. For instance, your co-author may open the file in an editor that does not recognise automatically utf-8, or the journal editor may not be used to process utf-8 files.

Also, I’ll never try an alternative keyboard layout: First, it is really hard work to get used to a different layout, and second, it’s a pain to use an alternative layout on a laptop for instance (epecially if you share the laptop with the rest of your family!).

Back to the first point, I always thought the best approach would be on one side to maintain latex files that uses ASCII encoding, e.g. \'{e} for é and so on, and on the other side to have an editor that interprets these on the screen, i.e. renders é. I think WinEdt on Windows does that. Lyx does that too in some sense.

• Robin Ryder Says:

I think pretty much all modern editors recognize utf-8. I would argue that utf-8 actually *decreases* the probability that a file not be recognized: I have had many situations where I could not read a .tex file written by someone on a Mac, because they used a Mac encoding. Still, I understand your point: this technique is at least useful for productions which are less collaborative (e.g. lecture notes, beamer slides…).

Regarding the alternative layout: I only use it at work, on a computer I am the only one to use; switching between layouts is not a problem. It took me a bit of time to get used to the new one, but my typing is now measurably faster, since the new layout is optimized to minimize the distance fingers have to travel. All in all, it saves me time, and helps prevent RSI.

3. Richard Everitt Says:

Have you ever used lyx? I find this a really nice way of doing things.

• Robin Ryder Says:

I have tried Lyx, but this method is more general (it applies not only to LaTeX, but also to e-mail, blogging, etc.). Also, I prefer the flexibility given by working directly with the LaTeX syntax, but that is because I like to nitpick.