# What are the standard styles to format LaTeX source code?

In any other programming languages, we have several ways to format our source code. For example, some of the standard styles are:

1. Allman(ANSI)
2. K&R
3. GNU
....

Within LaTeX, I couldn't find a neat way to clean my code. Most of the time, I usually make them align with each other like so:

An example from TikZ Automaton

\begin{tikzpicture}[shorten >=1pt, node distance=3cm,auto,on grid,initial text=, every state/.style={minimum size=3mm,draw=blue!50,very thick,fill=blue!20}]
\node[state]            (q_1)                           {$q_1$};
\node[state]            (q_2)   [right=of q_1]          {$q_2$};
\node[state,accepting]  (q_3)   [right=of q_2]          {$q_3$};

\path[->]
(q_1) edge                      node             {a}        (q_2)
(q_1) edge  [loop left]         node             {b}        (q_1)

(q_2) edge  [bend right]        node[yshift=4mm] {a}        (q_1)
(q_2) edge                      node             {b}        (q_3)

(q_3) edge  [bend left]         node             {a}        (q_1)
(q_3) edge  [loop right]        node             {b}        (q_3)
;
\end{tikzpicture}


Needless to say, manually doing this is very time-consuming and tedious. Additionally, since it does not follow any rule, the format won't be consistent and it could vary from file to file. So my question is, is there a standard style for formatting .tex source code?

-
The formatting you give in the example is inconsistent itself: sometimes a space but in other cases not before square brackets, random spaces inside the options themselves, random amount of spaces (or did you use tabs?) between columns. Besides, formatting TikZ is a whole different story, opposed to formatting TeX. –  Pieter Jul 30 '11 at 7:43
Thanks for the quick response. Yes, I often use tabs between columns, but sometimes I use spaces when the line gets too long. –  Chan Jul 30 '11 at 7:46
Please let questions long enough open so that other people can post answers as well. There is no need to accept the first answer quickly. –  Martin Scharrer Jul 30 '11 at 10:23
@Martin Scharrer: I really apologize for being rush. I will wait a bit more next time. Feel free to post your answer since I think other people including me definitely appreciate it. Thank you. –  Chan Jul 31 '11 at 1:17
@Chan: Thanks. I wasn't talking about a potential answer of mine in this case but meant it as a general rule. See the Should we wait a bit before accepting answers? post on TeX - LaTeX Meta for details. –  Martin Scharrer Jul 31 '11 at 9:01
show 1 more comment

+1 I must agree with your answer. TeX is more close to human languages and require us to improve its readability based on the context. Thank you. –  Chan Jul 30 '11 at 9:50