[Tex/LaTex] Tabs versus spaces for indenting TeX documents

editorstex-core

The title tells it all. What is a "correct" way to indent TeX documents?

Different programming languages have different conventions. Python recommends 4 spaces. Your Makefile will not even work if you do not use tab for indenting. Generally normalized (Allman style) BSD C code is indented with tabs of width 8.

Being an OpenBSD user I tend to use tab (set to 8 characters) to indent all my code including TeX except Python. However due to the fact that I use NVI with displayed line numbers the effective width of my terminal is only 72 characters which, coupled with 8 character indentation, makes some of my TeX documents difficult to read.

On another hand quick look at my

/usr/local/share/texmf-dist/tex/latex

directory reveals that LaTeX style files are indented with two spaces. Is that true in general? Should I use the same convention for LaTeX documents too?

Best Answer

What is a "correct" way to indent TeX documents?

I believe there is no "correct" way -- certainly no single correct way -- to indent input lines of an ordinary TeX or LaTeX document. (The situation may be different for input that adheres to LaTeX3 coding methods, but I'm not sure of that.) As long as TeX can parse the input, it's completely agnostic as to the form of the input it receives. Any indentation practices -- whether indenting with "soft tabs" or "hard" spaces, and whether the indentation amounts to 2, 4, or 8 spaces -- are therefore entirely cosmetic and voluntary in nature. To be sure, I don't believe anyone in their right mind would advocate not using some rule for indenting parts of one's TeX code.

A separate thought: In order to raise the readability of TeX input code, a technique that is probably as important as (or possibly even more important than) adopting some rule for indentation is using vertical whitespace liberally and consistently -- between paragraphs, above a sectioning command, before and after a \newenvironment statement, before and after a LaTeX float, etc.

Related Question