[Tex/LaTex] Source Code Indentation

indentationsourcecode

I was wondering if it is possible to indent the code like in most programming languages as shown below:

\part
    \chapter
        \section
            \subsection    etc.

This would make the source code much more readable. So is it possible? If yes how?

Best Answer

Yes, it is possible. Spaces at the begin of source lines is always ignored by TeX. However, I disagree that it is more readable for a normal document. Having several paragraphs of a, say \subsubsection indented by many spaces is not really readable to me. Instead I normally add certain separation lines before the sectioning commands, like 80-120x %. You can use two or more of them for higher sectioning commands. Multiple chapters and parts should be not in one source file anyway, IMHO, but instead split over several files which are then included in the main document using \include or \input.

If you question is actually about how to do this automatically then note that this is of course editor dependent. I don't know any editor which does that for sectioning commands. It might be possible to configure the more advanced ones, but for that we would need to know which one you are using.