New-lines in tex source. What are the rules?

I recently discovered that if I put a % symbol above and below my equations when I used and that my output PDF is made more compact, as tex interprets a new line as a new paragraph.

Previously I had been using \noindent to prevent indentation after equations and other structures such as \begin{itemize}.

Here is an example:

\subsection{Why Quantum Field Theory?}

Quantum Field Theory inevitably emerges from quantum mechanics'' + relativity''. It is the language of the Standard Model of Particle Physics. (QFT + Gauge Symmetry.)

\begin{itemize}
\item {QFT + Gauge $\to$ All of Nature - Gravity}
\end{itemize}

\noindent
Particle collision cross section calculations are done in the framework of QFT.


And here is another example from a different section.

\subsection{Hamiltonian Formalism}

Equivalent to the Lagrangian formalism is the Hamiltonian formalism. The conjugate momentum is defined $p_i=\pderiv{L}{\dot{q}_i}$.\footnote{Note that this does \textit{not} correspond to the momentum in all systems.} The Hamiltonian is obtained from a Legendre Transform [proof]

$$H(q_i,p_i)=\sum_i p_i \dot{q}_i-L(q_i,\dot{q}_i)$$

\noindent
For a single particle $L=\tfrac{1}{2}m\dot{x}^2-V(x)$. $\pderiv{L}{\dot{x}}=m\dot{x}$, $H(x,p)=\tfrac{1}{2}m\dot{x}^2+V(x)$, which in this case corresponds to the total energy.

Newtons Law can be derived,

$\deriv{}{t}\left(\pderiv{L}{\dot{x}}\right)=m\ddot{x}=\deriv{V(x)}{x}=F(x)$

\noindent
Hamiltons Equations are used to derive equations of motion

\begin{align}
\pderiv{H}{q_i}&=-\dot{p}_i\\\pderiv{H}{p_i}&=\dot{q}_i
\end{align}


You can see I've used \noindent a lot to get the indentation right.

I now think that I might be writing my tex code in a way which is non-optimal.

Is it better practice to put %'s on all blank lines where I do not want a new paragraph to start?

• A blank line is interpreted as a paragraph break. A % "erases" the remainder of the input line (including the terminating linefeed, which is typically interpreted as a space). Both of those circumstances potentially bring into play vertical spacing mechanisms that are built into LaTeX. For example, \parskip is a vertical length associated with paragraph breaks. – Steven B. Segletes Dec 22 '16 at 14:24
• See tex.stackexchange.com/questions/7453/… for discussion of % and tex.stackexchange.com/questions/41476/… for vertical spacing lengths associated with LaTeX. – Steven B. Segletes Dec 22 '16 at 14:30
• The better practice comes from not using \noindent to 'fake' not starting a new paragraph. If it is not a new paragraph, don't leave a blank line. What makes better sense for input markup is a different question. Because I do like to have environments separated from the main text, but because it is 'wrong' to use \noindent to 'fix' the blank space, the alternative is to use % to otherwise 'hide' the blank lines: this gives visually separates environments in the input file without creating new (semantic) paragraphs in the output that are 'cancelled' or 'hidden' by means of a \noindent – jon Dec 23 '16 at 7:01

Examine the examples here, to see that a blank line indicates a paragraph break, but placing a % eliminates the interpretation of the rest of the line, including the linebreak.

Note that if a linebreak is followed by a non-blank line, the linebreak is interpreted as a space.

\documentclass{article}
\usepackage[T1]{fontenc}
\begin{document}
a
b

c

\noindent is interpreted as a <sp> b <sp> <par> c''

a%
b

c

\noindent is interpreted as a b <sp> <par> c''

a
b
%
c

\noindent is interpreted as a <sp> b <sp> c''

a%
b
%
c

\noindent is interpreted as a b <sp> c''

a%
b%
%
c

\noindent is interpreted as a b c''

\end{document}


Never ever leave a blank line before a math display. Never use \noindent in a document (well, hardly ever): using it more than once or twice means there's something wrong in your way of typing.

You can comment an otherwise blank line, but with decent syntax coloring you don't really need such tricks.

\subsection{Hamiltonian Formalism}

Equivalent to the Lagrangian formalism is the Hamiltonian formalism. The conjugate
momentum is defined $p_i=\pderiv{L}{\dot{q}_i}$.\footnote{Note that this does
\textit{not} correspond to the momentum in all systems.} The Hamiltonian is
obtained from a Legendre Transform [proof]
$$H(q_i,p_i)=\sum_i p_i \dot{q}_i-L(q_i,\dot{q}_i)$$
For a single particle $L=\tfrac{1}{2}m\dot{x}^2-V(x)$.
$\pderiv{L}{\dot{x}}=m\dot{x}$, $H(x,p)=\tfrac{1}{2}m\dot{x}^2+V(x)$, which in
this case corresponds to the total energy.

Newtons Law can be derived,
\begin{equation*}
\deriv{}{t}\left(\pderiv{L}{\dot{x}}\right)=m\ddot{x}=\deriv{V(x)}{x}=F(x)
\end{equation*}
Hamiltons Equations are used to derive equations of motion
\begin{align}
\pderiv{H}{q_i} &= -\dot{p}_i \\
\pderiv{H}{p_i} &= \dot{q}_i
\end{align}


Note equation* instead of equation: it's easier to remove or add a * instead of changing $ and $ into and or vice versa.

If you do not want to end the paragraph it is clearest not to add the end of paragraph instruction (blank line) . Adding it then commenting it out works but is more convoluted than necessary. Ending the paragraph then starting a new one with noindent is completely different and should be rarely needed