# Automatic Paragraph Numbers (\everypar only for paragraphs and not for \section and so on)

I want to write a specification and each paragraph should automatically be numbered. I found something similar in a book about fitness training:

I prepared a small MWE (two-sided layout):

\documentclass{book}

\usepackage[english]{babel}
\usepackage[toc]{blindtext}

\begin{document}

\Blinddocument

\end{document}


Sadly I do not have a starting point for a solution. A manual solution would be to use margin notes.

Ideally the solution does not include a command I have to write before every paragraph.

## Update 1

Question/Answer Numbered paragraphs is pretty close:

\documentclass{article}
\usepackage[excludeor]{everyhook}
\usepackage{lipsum}
\usepackage{parskip} % I added this, Manuel Kuehner
\newcounter{paragraphs}[section]
\begin{document}
\PushPostHook{par}{%
\stepcounter{paragraphs}%
\llap{\thesection.\theparagraphs\ \kern\parindent}%
}
\section{Foo}
\lipsum
\section{Bar}
\lipsum
\end{document}


It creates an output like this:

So the output is not correct.

The problem is here that every section etc. also gets the additional numbering.

## Update 2

Here's another close solution (in German): http://texwelt.de/wissen/fragen/5020

But there's the same problem that I need to use a command for every number.

• A counter and \everypar is probably the way to go. I've written something like this ages ago - will see if I can find it. – Thruston Aug 29 '15 at 10:12
• Just a note: In Question tex.stackexchange.com/questions/10513 they all say that changing \everypar it not a good idea. – Dr. Manuel Kuehner Aug 29 '15 at 10:29
• Changing of some internals is always bad. However in your case I think it should be much easier to define a single command which puts a number at the beginning of the next paragraph. So you can avoid some complications with other packages and you are more flexibel (e.g. using a table or figure) – Marco Daniel Aug 29 '15 at 11:16
• My answer would be similar to this one: tex.stackexchange.com/questions/10513/… – Marco Daniel Aug 29 '15 at 12:01
• There are too many places where \par is used and a number should not appear: not only section titles, but also items in lists (including a single paragraph center environment). One could think to “conditional numbering”, disabling it in the special places. Not a task I'd undertake. – egreg Aug 29 '15 at 15:50

One approach using the linguex package:

\documentclass{article}
\usepackage{lipsum} % for dummy text
\usepackage{linguex}
% Counter format
\renewcommand{\ExLBr}{\bfseries}
\renewcommand{\ExRBr}{}
% http://tex.stackexchange.com/a/57279/11604
% Reset \ex. at each section
\usepackage{chngcntr}
\counterwithin{ExNo}{section}
\renewcommand{\Exarabic}{\thesection.\arabic}
\begin{document}
\section{First section}
\ex. \lipsum[2]\par
\ex. \lipsum[3]\par
\section{Second section}
\ex. \lipsum[3]\par
\end{document}


Edit: If yo do not want any command starting the paragraphs, use \everypar at your own risk ... you are warned in the comments.

In the next MWE, the macro \NumPar at the beginning of each section produce the same output that above. As example of the problems about using \everypar, note that a new section cancel the numeration but do not restore the default indentation of 1em, so you must restore it manually.

\documentclass{article}
\usepackage{lipsum}
\parindent1em
\begin{document}
\def\NumPar{%
\parskip0.5em%
\parindent0em%
\everypar={%
\hangindent3em%
\makebox[3em][l]{\bfseries\thesubsection}%
}}%
\section{First section}
\NumPar
\lipsum[2]\par
\lipsum[3]\par
\everypar{}
\lipsum[3]\par
\section{Second section}
\lipsum[3]\par
\lipsum[3]\par
\end{document}

• Is there a way to avoid the \ex.? – Dr. Manuel Kuehner Aug 29 '15 at 12:12
• @ManuelKuehner, see the edited answer – Fran Aug 29 '15 at 16:17
• Thanks a lot. Maybe I can add \NumPar to a \section-hook and then I do not need to add it manually. Hook (not quite) for Section: tex.stackexchange.com/questions/87996 – Dr. Manuel Kuehner Aug 29 '15 at 16:54
• Allow me a question. Why is \everypar reseted on every \section? Does this apply to \chapter and so on too? – Dr. Manuel Kuehner Aug 29 '15 at 19:30
• @ManuelKuehner Yes, because \everypar is used at low level by many other LaTeX commands, among these \@@startsectionso, is changed by any sectioning level. See here. – Fran Aug 29 '15 at 20:29

Another solution which is non-automatic, but a handy solution is using the enumitem package. Only itemize each paragraph in the description block:

\documentclass{article}
\usepackage{lipsum} % for dummy text
\usepackage{enumitem}
\begin{document}
\section{First section}
\begin{description}[style=unboxed,leftmargin=0.7cm]
\item[$\textbf{1.1}$]\lipsum[1]\par
\item[$\textbf{1.2}$]\lipsum[2]\par
\end{description}
\section{Second section}
\begin{description}[style=unboxed,leftmargin=0.7cm]
\item[$\textbf{2.1}$]\lipsum[3]\par
\end{description}
\end{document}

• As long as you're using enumitem, you might as well make it an enumerate and have the label automatically created for you. – Teepeemm Jul 19 '19 at 22:20