Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I really like spacing my LaTeX to stay organized, but I'm always scared that adding a space will affect the output when all I really wanted to do was separate the "code" a bit.

So most of the time I insert a "%" in the empty lines just to be safe, or I experiment. For example, I know (by playing with it) that the empty lines in the following are not doing any harm:

\documentclass{article}
\begin{document}

\title{My title}
\author{My author}
\date{\today}
\maketitle

\begin{abstract}
This is my abstract!
\end{abstract}

\section{Introduction}
Bla bla bla.
\end{document}

But I'm wondering, is there a steadfast rule that I can use to know right away if an empty line will affect output?

share|improve this question
add comment

3 Answers

up vote 10 down vote accepted

Basically, given that an empty line produces a \par token, the one rule I know is this: Empty lines are harmless when you know they (or the implied \par) will only be encountered in vertical mode. TeX starts in vertical mode, and it is in vertical mode between paragraphs, as well as at the top of many environments such as all the list environments, minipage, and floats. Also immediately after these environments (but not after a displayed equation, usually).

share|improve this answer
    
You didn't ask, but a similar statement holds for the implied space at the end of an input line not ending with a comment or control sequence. Except spaces are, of course, also harmless in math. –  Harald Hanche-Olsen Jan 26 '11 at 9:06
    
This rule is too simplistic really: You are in vertical modeafter \end{itemize} or \end{center} but a blank line is significant: If it is not there the following text is treated as a continuation of the text before the display and not indented, if it is there then it forms a paragraph break and following text starts a new paragraph/ (Technically you are in vertical mode but \par does not have its primitive definition so is not ignored, but that's an implementation detail) –  David Carlisle May 9 at 8:37
add comment

Within the body of your document, the most basic rule of thumb is: Only use empty lines to separate paragraphs.

So in your example it is fine to say

\section{Introduction}

Bla bla bla.

\end{document}

Because the “Bla bla bla.” is, presumably, a paragraph on its own.

Also because of this you shouldn't add empty lines between an equation and its surrounding text if they do belong to the same paragraph. In this case, if you want some extra space in your source code, you should insert %'s to comment out the line, e.g.

... and then we find out that
%
\begin{equation}
z^2 = x^2 + y^y \;,
\end{equation}
%
which is rather nice.

And then another paragraph here ...
share|improve this answer
add comment

When starting a list environment (or an environment based on list, e.g. quote), absence or presence of an empty line before \begin{<list>} will result in different vertical spacing before and after (!) the list. Without an empty line, the spacing is equal to \topsep; with an empty line, the spacing equals \topsep plus \partopsep.

(In the following MWE, I used the enumitem package to set both \topsep and \partopsep to 6pt to highlight the effect.)

\documentclass[12pt]{article}

\usepackage{enumitem}
\setlist{topsep=6pt,partopsep=6pt}

\begin{document}

\section{Lists within paragraphs}

Some text.
%
\begin{itemize}
\item A list item
\end{itemize}

Some text.

\section{Lists as paragraphs}

Some text.

\begin{itemize}
\item A list item
\end{itemize}

Some text.

\end{document}
share|improve this answer
add comment

Your Answer

 
discard

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.