As far as I can see, the tab key doesn't do anything and can therefore be used safely without altering the output.

I googled it but I haven't found anything. It's usually all about the tab command.

  • 1
    You've tagged this with "editors". If your question is about a specific editor then you should say which editor. If it is about how a tab character in (La)TeX code is interpreted by e.g. pdflatex then a different tag would probably be better. – Torbjørn T. May 24 '16 at 11:02
  • There are some special cases, when tabs can break thinks, see e.g. indention of fragile frames in beamer. – samcarter_is_at_topanswers.xyz May 24 '16 at 23:58

The effect of the tab key is entirely dependent on how the OS interprets that key, how the editor treats the result of the OS's interpretation and, finally, how TeX interprets the result of the editor's treatment in the particular context.

On my machine, Kile is currently configured so that pressing the tab key inserts spaces if I am editing a file with the mode set to LaTeX. By default, that's currently true for all .tex files, for example, and some other source files.

Until recently, I had Kile configured to insert a tab character in this kind of case. However, this turns out to cause various issues, so I altered the configuration.

There is nothing sacrosanct about the connection between the key labelled tab and the insertion of a tab character. And the editor may well transform the input further whether it is a tab character or not.

This point might seem pedantic. But it is not. Because if pressing the tab key influences the typeset document in a way you don't like, you have options.

One is to quit using the key in problematic places. I could have resolved the issues caused by tab characters in this way: I could have used the space bar instead. But that would be a pain. I want a particular number of spaces in particular places. I don't want to have to insert the correct number in the correct place.

But that's not the only option. The other option is to alter the effect of the key on the source code.

This can be done at the level of the OS/desktop environment/GUI or terminal configuration. This is a good choice if, like me, you find CapsLock a pain because you don't realise you've switched it on. You can turn CapsLock into, say, another Ctrl key or use it for character composition.

Or it can be done by the editor, which is a better choice for this kind of case. Not only does it avoid altering the effect of the key in applications not related to TeX. It also permits much more fine-grained control. You might want the key to do something different in .bib files, say. Or in .sh files.

  • I should make clear that the reason I had problems with tab characters and wanted spaces instead was not to do with the way TeX treated them on compilation. I don't remember why it was, but it was either editor related or scripting related. (Maybe both.) – cfr May 24 '16 at 23:23

Let's look at latex.ltx, where we find

277 \catcode`\{=1 % left brace is begin-group character
278 \catcode`\}=2 % right brace is end-group character
279 \catcode`\$=3 % dollar sign is math shift
280 \catcode`\&=4 % ampersand is alignment tab
281 \catcode`\#=6 % hash mark is macro parameter character
282 \catcode`\^=7 % circumflex and uparrow are for superscripts
283 \catcode`\_=8 % underline and downarrow are for subscripts
284 \catcode`\^^I=10 % ascii tab is a blank space

This is essentially taken unchanged from the start of plain.tex and the last line is what is of interest for the question at hand.

It says that the ASCII character number 9 is assigned category code 10. Wait, where is number 9? According to TeX conventions, ^^I is the same as typing the character that differ by 64 from I (plus or minus, depending on which gives a code point between 0 and 127). Since I is position 73 in ASCII and 73+64=137>127, we do 73-64=9. According to TeX's rules, the concoction


is the same as typing \catcode 9=10.

Category code 10 means “blank space” and, basically, all characters having this category code behaves the same. So the <tab> character is ignored at the beginning of lines and after control words, but produces a blank space in the same contexts where a normal space (character code 32) would.

Of course, one can change the category code so the character behaves differently. For instance,


a   b

(between a and b there's a <tab> character, which might be lost in copy-paste in this site) would produce

enter image description here

because the Computer Modern font in OT1 encoding has Ψ in slot 9.

However, if category codes are not changed, <tab> is the same as a space (or a run of spaces, because of standard TeX rules).

What the <tab> character does in the editor window is another matter. For instance in my settings for Aquamacs (an Emacs variant for Mac OS X) the <tab> character does exactly nothing. Some editors might produce a run of spaces, others a real <tab> characters, others may use it for moving to marked points.


You can use tab in your document without altering the output.

You can then indent your code for a better readability.

For example, emacs have a functionnality to indent the code in automatic way and I suppose that most of editors have it.

  • Thanks. I just wanted to get sure, that it doesn't behave like <CR> and %<CR> i. e. – MaestroGlanz May 24 '16 at 10:31
  • 3
    "without altering the output" has to be read with care. If (as in emacs) tab is a control key that formats the document, it does whatever it does. If the tab character is passed to TeX then it (normally) has the same effect as space. So it affects the output or not depending where it is used. a<tab>b does not typeset as ab – David Carlisle May 24 '16 at 10:50

It seems to be ignored only at the beginning of a line. The following code has the same output in PDFLaTeX, XeLaTeX, LuaLaTeX, TeX->DVI->PS->PDF and TeX->DVI->PDF:



            tab tab tab tab tab tab 


It always looks like this:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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