TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

            \subsection    etc.

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

share|improve this question
possibly related question: tex.stackexchange.com/questions/26102/… – doncherry Dec 17 '11 at 16:31
Whilst I think this is a bad idea in general, it could be useful for table or figure environments, and especially for TikZ. – qubyte Dec 17 '11 at 17:59
Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – Jubobs Jan 28 '14 at 1:02
up vote 12 down vote accepted

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.

share|improve this answer
Is there a way to make the editor/front end do this by default because indenting every single line is a bit tedious; or maybe there is s front end/editor that supports this? – Samantha Catania Dec 17 '11 at 16:28
@SamanthaCatania you need to tell us what editor you use. – Bruno Le Floch Dec 17 '11 at 16:50
@BrunoLeFloch I run a mac; my personal favorite is texmaker but anything is fine (as long as it runs on a mac) – Samantha Catania Dec 17 '11 at 16:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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