Empty line (in code) before enumerate environment

I like my code to look like this:

\documentclass{article}
\begin{document}

\begin{enumerate}
\item test text

\begin{enumerate}
\item 1
\item 2
\item 3
\item 4
\item 5
\end{enumerate}
\end{enumerate}

\end{document}


For the sake of readability I like to put a blank line before a new environment starts. In the particular case I'm considering, the blank line adds some vertical space between the item from the first level enumerate and the first item from the second level enumerate.

So my question is: is there a best practice to format code related to blank lines before environments start? Should I avoid it? Should I comment out the blank line?

Clarification:

I'm talking about the vertical space between "test text" and "1". But, I'm not asking for a way to remove the extra space added by the blank like, I already know how to do that. My reasoning is the following:

Since adding a blank like before a new enumerate adds vertical space, it means that that blank line is meaningful for TeX. Since it is meaningful for TeX, is it OK to use it for the mere purpose of formatting code or should I avoid it?

-
A blank line signals a paragraph break, which makes sense before and after enumerations as well. To set off your enumeration for visibility, you can use a line containing just a comment character (% at the start of an empty line). – alexis Dec 16 '13 at 22:30

A blank line in TeX input is a command it is equivalent to \par so you should not put it in places where you don't want to start a new paragraph. Like any command, if you want to put it in the source file for some reason, but don't want it to be executed, then you need to comment it out, but generally it's simpler not to put it there in the first place:-)

-
To clarify your statement, you're suggesting something like this. – Werner Dec 16 '13 at 22:28
So the general rule should be: insert a blank line only if you want a \par, right? Forgive the personal question, but do you write your code this way? – Mason Dec 16 '13 at 22:29
@Mason a blank line is \par it is reported as the \par token by TeX's input scanner before macros see the input. Try putting \show followed by a blank line. TeX will stop and show the token as \par not as an end of line character. – David Carlisle Dec 16 '13 at 22:34
@Werner yes or simpler without the blank line at all. – David Carlisle Dec 16 '13 at 22:35
@Mason I can't speak on behalf of David, but I do. There are many places where blank line never appears: before any displayed equation (to prevent pagebreak there); in your situation (I always format the code such that one item of the outer list is one block of code, and I never go deeper than 2 lists, it's a nonsense to do it); inside a macro definition (I use explicit \par if I really need it, to avoid later confusion whether it was an intention), ... – yo' Dec 16 '13 at 22:36

The blank line causes LaTeX to add \partopsep glue to the inner enumerate. With enumitem it's easy to show that setting this parameter to zero produces identical output:

\documentclass{article}
\usepackage{enumitem}

\setlength{\parindent}{0pt}

\begin{document}

Normal setting

\fbox{\begin{minipage}[t]{.4\textwidth}
\begin{enumerate}
\item test text

\begin{enumerate}
\item 1
\item 2
\item 3
\item 4
\item 5
\end{enumerate}
\end{enumerate}
\end{minipage}}
\fbox{\begin{minipage}[t]{.4\textwidth}
\begin{enumerate}
\item test text
\begin{enumerate}
\item 1
\item 2
\item 3
\item 4
\item 5
\end{enumerate}
\end{enumerate}
\end{minipage}}

\bigskip

With zero partopsep

\fbox{\begin{minipage}[t]{.4\textwidth}
\begin{enumerate}[partopsep=0pt]
\item test text

\begin{enumerate}
\item 1
\item 2
\item 3
\item 4
\item 5
\end{enumerate}
\end{enumerate}
\end{minipage}}
\fbox{\begin{minipage}[t]{.4\textwidth}
\begin{enumerate}[]
\item test text
\begin{enumerate}
\item 1
\item 2
\item 3
\item 4
\item 5
\end{enumerate}
\end{enumerate}
\end{minipage}}

\end{document}


My opinion is that a blank line shouldn't be there, unless you want a new paragraph to start. In the generality of cases (tabular and array are exceptions) a blank line in LaTeX is significant and should not be used just to enhance readability of the source.

A percent symbol would do without creating a paragraph break:

\documentclass{article}
\begin{document}

\begin{enumerate}
\item test text
%
\begin{enumerate}
\item 1
\item 2
\item 3
\item 4
\item 5
\end{enumerate}
\end{enumerate}

\end{document}


However, I would simply write

\documentclass{article}
\begin{document}

\begin{enumerate}
\item test text
\begin{enumerate}
\item 1
\item 2
\item 3
\item 4
\item 5
\end{enumerate}
\end{enumerate}

\end{document}


with much less indentation. Personal preference, of course.

-

You can always define a macro \eatpar which would "eat the empty line(s)". However, I don't think that this solution would make the code more readable:

\documentclass[twocolumn]{article}

\makeatletter
\newcommand\eatpar{\@ifnextchar\par{\expandafter\eatpar\@gobble}\relax}
\makeatother

\begin{document}

\begin{enumerate}
\item test text

\begin{enumerate}
\item 1
\item 2
\item 3
\item 4
\item 5
\end{enumerate}
\end{enumerate}

\newpage

\begin{enumerate}
\item test text
\eatpar

\begin{enumerate}
\item 1
\item 2
\item 3
\item 4
\item 5
\end{enumerate}
\end{enumerate}

\end{document}


(The first one is without anything, for comparison.)

-