# Good keyboard layouts for typing (La)TeX

When typing (La)TeX some keys are used a lot more often then in plain text, especially \, {, }, [, ], $, ^ and _. On most keyboard layouts these keys are rather cumbersome to type. The English QWERTY keyboard is a lot better than the German QWERTZ, but is still far from optimal. Given that I mostly type mathematical texts in English, what keyboard layout would you recommend? Bonus points for the following: • Ability to type non-English Latin characters, especially German umlauts. • Some similarity to QWERTZ or QWERTY as I'm most used to these layouts (I currently use the US-International layout from Linux) • Ability to type math symbols directly (Greek letters, \times, etc.) - If you're a Mac user, you might be interested in this answer, which describes how I made a custom keyboard layout full of math symbols, greek letters, and so on. – John Wickerson Apr 22 '13 at 20:47 And if use Linux, you can be interested in this article in my blog... rlog.rgtti.com/2014/05/01/… --- HIH! – Rmano Sep 18 '14 at 11:41 ## 13 Answers Since you're asking for german umlauts: There is the Neo layout which is for german language. The wiki sounds rather interesting! There are even pages for TeX. (I have not used it myself, though). http://wiki.neo-layout.org/wiki/ and http://wiki.neo-layout.org/wiki/Neo%20f%C3%BCr%20Latex - Looks interesting, though it might take some time to learn to use it efficiently. – Caramdir Aug 18 '10 at 19:22 Layouts like that ask for a keyboard that can alter their own appearance while you are learning te new layout, like this one: artlebedev.com/everything/optimus Horribly expensive, unfortunately – Taco Hoekwater Aug 18 '10 at 21:03 Horribly expensive and without Linux support :( – Caramdir Aug 18 '10 at 21:51 I seems I never accepted any answer here. Since I ended up using Neo, I'm accepting this answer. Together with unicode-math Neo makes typing LaTeX more fun and produces more easily readable code. – Caramdir Nov 14 '10 at 17:10 @Martin: Maybe US International can be of use to you. Except for swapping Y and Z and the umlauts, the letters are in the same place as in QWERTZ, but the special keys are somewhat easier to reach. – Caramdir Mar 18 '12 at 16:19 Long, long ago in a galaxy far, far away, I attempted starting a blog. It didn't last, but one of the things I posted was about this very subject. When I deleted the blog, I kept the articles. So here's that one. I apologise for the length. A few years back I started to get what I think was RSI in my hands. I never got it officially diagnosed so I can't be sure, but all the symptoms seemed clear. It was worse when I was typing, and worst in my little fingers. Think about typing. How much work do the little fingers do compared to the others? As well as having their own letters, they also work many of the punctuation characters and the shift (and control) keys. I found I was often having to stretch my hand to type characters and this was putting a lot of strain on my little fingers. It's even worse when typing LaTeX documents. A quick scan through a thirty-page paper reveals that the five most typed characters are: • space 15525 • e 7266 • \ 6834 • o 5476 • t 5470 There then follow a few more lowercase letters, in 14th and 15th place are the parentheses (worryingly not the same number of each - must have some half-open intervals in there). 22nd is the underscore, 24th and 25th are the curly braces (quick check: the same number this time) with just over a thousand occurrences. The first number, 1, is way down the list with only 362 appearances. By the way, if you want to generate this list, there are probably more elegant ways but here's my two-minute hack: ~% cat paper.tex| \ perl -lne 'while ($_) {
$_ =~ s/(.)//;$count{$1}++}; END { @chars = sort {$count{$b} <=>$count{$a}} keys %count; while (@chars) {$c = shift @chars;
print "$c$count{$c}"; } }'  The backslash key is often hard to stretch to, the curly braces usually require shift (or Alt-Gr on some international keyboards). That's a lot of work for what is, as far as catching mammoths is concerned, something pretty useless. My solution was to modify the keyboard. No, not with a hammer. With a nifty little program called xmodmap. This is a UNIX program which allows you to modify what the keys on the keyboard actually do. I use it to put the backslash where the semi-colon is (after all, who uses a semi-colon these days?), swap the curly braces and square brackets, and swap the numbers with their symbols (so pressing '3' produces '#' and 'Shift+3' produces '3'). Unfortunately, this method isn't very portable and I have to set it up for each machine. The problem is that it is a translation table from what the keyboard currently does to what you want it to do, so you first have to know what it currently does. However, it's fairly simple to explain how to set it up. Suppose you want to put the backslash where the semi-colon is. First you need to find the keycode for the semi-colon. There are two ways to do this. Firstly, from a terminal run a program called xev. When you press a key in its window, it tells you lots of information about it in the terminal - including the keycode. The other way to do it is to run xmodmap -pke. This produces a list of all the current assignments from which you can read off the keycode for the semi-colon. ~% xmodmap -pke | grep semicolon keycode 47 = semicolon colon oslash Oslash  (Yeah, I'm on a Norwegian keyboard.) Now you just need to remap that: ~% xmodmap -e 'keycode 47 = backslash colon oslash Ooslash'  Lo and behold! Keyboard modified. Three things to note. Save the initial output of xmodmap -pke since if everything goes wrong typing: ~% xmodmap original_list  will reset it (though that might be difficult if you've reset all the keys! In that case, log out and log back in again). Secondly, to save you typing in all those commands every time, you can put them all in a file called, say, .xmodmap and put a line xmodmap ~/.xmodmap in your startup file. Gnome actually goes looking for these files and asks if you want to load them so you don't need to put them in your startup file. The final point is that you might want to consider having different keyboards for different tasks. I have a keyboard for writing LaTeX documents and a "normal" one for everything else; switching between them is easy using "hot keys". Several years after figuring this out, I discovered that I was alone neither in the problem nor in the solution. Greg Kuperberg has also written about this, though his solution uses XKB rather than xmodmap. Your mileage may vary. Here's the actual layout:  1 2 3 4 5 6 7 8 9 0 _ + ~ ! @ #$ % ^ & * ( ) - =

TAB Q W E R T Y U I O P [ ]
q w e r t y u i o p { }

Ctrl A S D F G H J K L : " |
a s d f g h j k l \ ' /

Shift > Z X C V B N M < > ? Shift
< z x c v b n m , . ;


In addition, the "weird" keys along the bottom are mapped to various modifiers which give me access to other characters (most usually, øæå, as I'm in Norway). This is actually done with a two-stage xmodmaprc: the first stage changes my Scandinavian keyboard into something I'm a little more used to; the second stage does the TeX-related changes. I have one hotkey that starts Emacs and changes the keyboard all in one go!

-
Good post. Could you show the layout you use? (The Gnome keyboard applet has a "show current keyboard layout" command, but I don't know if it works with xmodmap.) – Caramdir Aug 18 '10 at 19:25
Thank you. Switching shift and normal version of the numbers row is a qood idea. – Caramdir Aug 18 '10 at 21:50
I have settled for a slightly less radical approach: I stick with the basic Norwegian keyboard layout, but I add some AltGr-combinations. Most importantly, with just AltGr held down I can type hjkl and get $$[{. These are very easy to type without moving the hands. With shift I have |)]}, but I need these a lot less, especially since I like to have emacs automagically insert a matching right bracket when I type a left one. – Harald Hanche-Olsen Nov 22 '10 at 15:04 @Harald: neat, though I find AltGr as awkward as shift on my keyboard (some hybrid Scandinavian board). One of these days I'll learn all the emacs shortcuts for LaTeX documents ... oh, I forgot, I don't need to: M-x put-brain-in-emacs-mode. – Loop Space Nov 22 '10 at 15:40 "who uses semicolon these days?" from the tikz-magician. Really? Also, CSS? – Seamus Aug 3 '11 at 10:18 ## Quick advice Get a good keyboard, get a good text editor, and practice. ## Detailed suggestions A good programming keyboard will make your fingers happy with no re-mapping. Personally, I use the Happy Hacking Keyboard Professional II. I find that I can still type around 40 WPM, even stumbling over LaTeX syntax, when using this keyboard. A good text editor with syntax highlighting and auto-complete will make writing LaTeX documents much, much easier. I got the keyboard above when I was using GNU Emacs, since it replaces the Caps-Lock key with a control key (you can accomplish the same with software remapping). Since then, I've used MacVIM, which uses a nice LaTeX Bundle. Currently, I use TextMate. If you're on Windows, you can use the similar E-Text Editor. I switched to TextMate because working with tables is much, much easier with the included bundle. TextMate also auto closes the (),,[], and {} sequences, plus others. It also handles quoting automatically (typing two backticks closes with straight quotes). I find the shortcuts for automatically closing environments is helpful, as well. The one thing I picked up from Andrew Stacey's post is that your most common characters are going to be alpha characters. Typing math is going to be equally painful on most layouts. I find with enough practice, my fingers find special characters easily enough. If you're interested is gaining speed from typing alpha characters, I hear Dvorak is all the nerd-rage, but its efficacy is dubious. ## Special characters For printing special characters... that's why I use LaTeX. To me, typing \alpha is a lot easier than remembering an alt-code or option-key press, and faster than hunting and pecking on a character map. Umlauts, graves (or diacrticals), and special math characters are best expressed using the LaTeX macros, in my opinion. It avoids any problems that might arise when sharing files with others (no worries about UTF compatibilities). For instance, it's easy to type ü on my Mac, but it's just as simple to type \"u in LaTeX. - Made the links working. For me \"u is a lot slower then just ü. The first one is ALT_R+(key left of 0) SHIFT+2 u on a German keyboard (though it is better on an English keyboard). Vim-LaTeX (which I use) has many remappings, but they all use the top left key on the keyboard, which is not exactly easy to reach. – Caramdir Aug 19 '10 at 8:51 Thanks for help with the links! Also, didn't know that about Vim-LaTeX. Like most packages, I'm afraid I didn't use it to its full potential. :) – jrhorn424 Aug 19 '10 at 15:09 Small correction to my comment above: on a German keyboard, the backslash is to the right of 0 and not the left. – Caramdir Aug 3 '11 at 4:00 Dvorak's efficacy may be dubious (I have heard from many that their typing speed didn't increase but hand strain decreased), but that article ("Fable of the Keys") is not an unbiased one. The authors 'are economists opposed to an "excessive inertia" theory, for which QWERTY is often cited as an example. Rather than try to prove their point with a generally valid argument, they simply attack Dvorak as a dubious replacement for QWERTY.' So it's not an unbiased study that it (possibly) pretends to be. See "Fable of the Fable" at dvorak.mwbrooks.com/dissent.html for an opposite view. – ShreevatsaR Dec 2 '11 at 11:50 @ShreevatsaR, you could make a similar comment about practically any social science piece you didn't agree with. I'm not sure how you're using bias, but if it means "taking a contrary position and showing evidence that supports your position", there's no hope for science. – jrhorn424 Dec 6 '11 at 20:20 Not a full layout, but I rebound (in Emacs) ; (on a English Qwerty layout under my right pinky) to insert \, and inserting three backslashes in a row (since \\ is meaningful) inserts {} with the cursor in between. Since I very rarely use semicolons in LaTeX it has been great. I thought I might get confused when switching to other languages like GAP or C that use lots of semicolons, but actually I haven't. This idea came grew out of similar ideas from Gurmeet Manku. For example he types (and I stole) .. to produce [], again with the cursor in between. This seems quite "funky", but I found it very easy to get used to and quite helpful. I also use M-e to insert  and then again will change it to . A few tricks like this can go a long ways. The only drawback is they are editor dependent. - I use the vim editor, which I think partially solves your issues despite not being a keyboard layout. There's a bit of a learning curve, but I found it much easier learning vim than trying to switch to a Dvorak keyboard layout. Vim is highly programmable so with some LaTeX, snippet and delimiter plugins you can simplify a lot of the typing, with the added bonus of very simple latex compilation and parsing of the error log from within the editor. Some plugins I find useful: SnipMate lets you make snippets, where you type say desc, hit TAB and it turns into \begin{description} \item[] \end{description}  where the cursor is in the square brackets of \item making it easy to start a list without ever hitting any of the annoyingly placed \[]{} keys. delimitMate automatically fills in delimiters (quotes, brackets, parentheses...) so you don't have to type as many. LatexBox provides a bunch of simple helpful additions like autocomplete of standard commands, and simple wrapping of text in a latex command/environment, which works as follows: You have typed some text: ...the experiment showed a detrimental effect on...  But you now want to wrap detrimental in some macro (e.g. \emph), so you select it and hit a shortcut (F5 by default I think, but easily customised) and it adds in the \{ and } for you, and puts the cursor after the \ ready for you to type your macro: ...the experiment showed a \|{detrimental} effect on...  where | is the cursor position. There's another key to wrap a selection in a new environment. Further customisation lets you do things like highlight text and hit a shortcut (cmd+I for me) to wrap it in \emph{ and }. So as you can see you avoid actually having to hit those keys a lot with some customisation. Another very popular one is Vim-Latex-Suite (I personally find that one does a bit too much, but a lot of people use it and find it very useful). That provides you very simple short-cuts for entering environments, greek symbols, etc. To be honest, I guess I should recommend checking this out first and if you find it's a bit too complex try the ones above as simpler alternatives. I've also used the TextMate editor (Mac OS X only), which is where the snipMate and delimitMate plugins get their inspiration, which provides a lot of these features in a more "traditional" editor. It's not as cheap (since its not free) and doesn't work on Linux/Windows. - I guess I should have stated in the question that I already use Vim with LaTeX-Suite. I think there was a question about editors a while ago. You might want to add your answer there. – Caramdir Aug 19 '10 at 8:55 @Caramdir: could you please review this q here? I am trying to find out some way to write only equations -- when VLS does not start (eq to write equations for Math.SE -- so trying to find a way to toggle it but this question raises new ideas, investigating. – hhh Mar 29 '12 at 13:36 ...about the F5 -key, here a small problem. Could you check it? – hhh Mar 29 '12 at 14:53 Dvorak is superior in speed and efficiency than Qwerty because your fingers need to move much less, increasing your stamina. Extension to Stenographic keyboard Plover possible. Limitation special keys and deadkeys but development is going on. For me, Vim was one night story but Dvorak two weeks story until I reached the same efficiency than in Qwerty. But again so personal and subjective how fast one can learn in specific situations. – Masi Feb 16 at 13:42 - ...although I do use the kbd, I am still skeptical about it. I had a QWERTY pianist that could move his fingers in unbelievable speed/accucrasy/elegancy (no noise etc) -- one should never think that one kbd makes you better in something, there are much more puzzles to look at. He always tried to minimize the time on computer -- the guy hated computers but he was a real genious in C/etc...now there is something think about. Perhaps one needs to become a DVO-pianist :P – hhh Mar 29 '12 at 14:05 The deadkey support is deficient in Dvorak in many OS. OS X Dvorak has good Scandinavian and German support. Linux bad. Chromebook is far behind but 2nd priority bug about the issue here code.google.com/p/chromium/issues/… Dvorak extends well to be used as typographing layout in extension with stenographing system Plover. Much less strain to your hands. It took me 2 weeks intensive straining and mental straining until I reached my Qwerty speed with Dvorak. – Masi Feb 16 at 13:38 Egrep emphasizes here that Dvorak is deficient in special keys tex.stackexchange.com/q/294200/13173. I think he is right. I think we need better roadmap here about what to do for improvements. Could you please add some descriptions of Dvorak here, not only having link-only-answer. – Masi Feb 16 at 13:44 A couple of keyboardy related things. I use emacs which makes things easier in a number of ways. For example, I have things set up so when I type  I get  with the cursor between the two dollar signs. Neat. I can add macros and environments through some simple commands, which also cuts down the number of "difficult" keys I have to type. Emacs does, however, make extensive use of the Ctrl and Alt keys, so these become more important. They are not particularly well placed for such heavy use. I never use CAPS LOCK (since I can use emacs commands to uppercase words/regions at my leisure) so remapping the Caps Lock key to be another Ctrl saves me some little-finger exertions. Also, for umlauts and the like, Ubuntu's Compose Key is a neat feature. (I personally find it easier to write \"u than ü, but that's just me...) - You use dollars!?! – Loop Space Aug 3 '11 at 10:38 What, rather than \( and $$? I bet I could change it so that $ put me between $$ and $$ but what would I gain from that? Also, it's smart enough that if I type \$ it doesn't double the dollar sign... – Seamus Aug 3 '11 at 10:40

I now use a czech programmer keybord (custom made) which has the special symbols in the english number row accessible by using right alt and the rest of important symbols ({}[]\/=) are on the home row (ASDF...) again with right alt. Very convenient.

-

I completely gave up trying to use "national" keyboards to type anything. When you're a programmer, you need to have easy access to the same keys the designer(s) of the language had easy access to on his or her own keyboard, and that holds for TeX, too. I use both QWERTY or Dvorak keyboards (where the "special" characters are at the same location as on QWERTY), with shortcuts to typeset the different accented characters for the languages that need it (my favourite layout is a Compose-like key as on Sun keyboards, but dead keys are OK too, although usually leas general).

-
...which leads to the question: what keyboard did Knuth use c1980? – Charles Stewart Aug 18 '10 at 19:30
So if you change the programming language, you switch the keyboard? - Oh, you never cheat on TeX, I forgot :) I am perfectly happy with my german OS X keyboard (except for the CAPS LOCK now being a control key) most of the time the computer is waiting for me to stop thinking and hitting a key again. – topskip Aug 18 '10 at 20:17
Patrick: No, because the special characters are the same, obviously. Basically, what you need is mostly the shifted version of the numeric row in the American keyboard (! @ # \$ % ^ etc.), plus a few punctuation marks. Some keyboards make these characters very painful to type. @Charles: This is documented in the manual for TeX 78. He had a few extra symbols like an upward-pointing arrow and a downward-pointing arrow, which he used, but he gave them an ASCII equivalent (in this case, ^ and _ for superscript and subscript). – Arthur Reutenauer Aug 18 '10 at 23:31

Following up on Andrew Stacey's answer, I have this in my .Xmodmap:

keysym Alt_R = Multi_key


That makes the right alt behave as a Compose key: first you press this key, then a combination of keys. There is a list of valid combinations (depending on your locale), and once you reach something that is valid, the combination is output. So, for example, Schröder is:

S,c,h,r,Alt-R,",o,d,e,r

Many keyboard layouts on linux have shift+Alt_R or the right windows key as Multi_key by default, but I find the first a that a lot harder to type, probably because I am lefthanded, and my keyboard does not have windows keys.

Further, I use a Qwerty US 102-key keyboard that migrated with me from an old Compaq ever since the nineties.

-

I am recently started to use autohotkey. You can write your own little macros. I started to program some macros- easily accessable by hitting space+letter. I think this could save a little time in typing. The same tool also allows remapping of keys

Space & t::
Send, \begin{{}table{}}{[}{!}htb{]}{enter}
send, \centering{enter}
send, \caption{{}{}}{enter}
send, \label{{}tab{:}{}}{enter}{enter}
send, \end{{}table{}}{UP}
return

-
Useful, but I usually use Vim, so I can define shortcuts like that right in the editor. – Caramdir Aug 18 '10 at 21:55

I have come to like US international (us altgr-intl for setxkbmap`). It combines coding advantages and familiarity of QWERTY over (German) QWERTZ with accessibility of most typical characters in Western European languages. It might not be as optimised as some other layouts (allegedly) are but it does the job while not skrewing you (too much) when you end up typing on someone else's machine or having guests.

-