# Automatic numbering of paragraphs in the margin

I want a way to number paragraphs automatically in a way that doesn't require explicit extra code at the end of every paragraph in a document built on LaTeX3. I want the paragraph numbers to appear in the left margin or maybe the outside margin if it's a two-sided document. Ideally I'd like a mechanism to start, pause, resume, stop, and reset the numbering. And preferably have a way to control the display of the number, probably prefix it with a paragraph mark. Basically something like the lineno package.

I feel this should be a solved problem already but I can't find any suitable packages. The nearest on tex stackexchange seems to be this but I'm not sure how to adapt it.

## MWE

\documentclass[11pt]{article}

\usepackage{lipsum}

% This part needs replacing
\usepackage{marginnote}\reversemarginpar

\begin{document}

\marginnote{\P1}First paragraph.

\marginnote{\P2}Second paragraph.

The above two paragraphs illustrate the desired outcome but have to be done explicitly in the source. The aim is for paragraphs like this and subsequent ones to be numbered automatically.

\lipsum[1-2]

\end{document}


Well you can use the new para hooks. But the main problem is not to add something, but to prevent that it gets added in places where you don't want it, paragraphs are in more places than you expect. Use some boolean e.g. from the etoolbox package that you can switch on and off.

\documentclass[11pt]{article}

\usepackage{lipsum,etoolbox}

\newbool{myparbool}
\booltrue{myparbool}
\newcounter{mypar}
\begin{document}

\boolfalse{myparbool}
\section{Section}
\booltrue{myparbool}

First paragraph.

Second paragraph.

The above two paragraphs illustrate the desired outcome but have to be done explicitly in the source. The aim is for paragraphs like this and subsequent ones to be numbered automatically.

\lipsum[1-2]

\end{document}


• Magnificent, thank you. Exactly what I wanted. I know what you mean about paragraphs getting everywhere! Apr 29 at 14:46

Another alternative, if you're not using it for anything else, is to use the "paragraph" sectioning command:

\documentclass[12pt]{article}
\usepackage{titlesec}
\setcounter{secnumdepth}{5}
\titlespacing{\paragraph}{0pt}{0pt}{0pt}
\usepackage{lipsum}
\begin{document}

\paragraph{} \lipsum[5]
\paragraph{} \lipsum[6]
\paragraph{} Another paragraph.

No longer numbered.

\end{document}


• Thank you for the alternative. I want to avoid having any extra commands to cause a paragraph to be numbered but this solution is great for when you want a minority of simple paragraphs numbered. I fiddled with \paragraph but hadn't spotted the functionality in titlesec. So thank you for that. Apr 29 at 14:49