% This is an example document accompanying "LaTeX for Administrative
% Work"
% See www.dickimaw-books.com/latex/admin/ for the book details,
% including licence.
%
% arara: pdflatex
% arara: pdflatex
\documentclass{article}

\usepackage{lipsum}
\usepackage{etoolbox}

\author{Some One}
\title{Numbered Paragraphs Example}

\newcounter{para}
\newcommand*{\numberedparagraph}{%
  \refstepcounter{para}\thepara.\space
}

% To make the paragraph numbers appear in the margin:
%\newcommand*{\numberedparagraph}{%
%  \refstepcounter{para}\marginpar{\thepara.}%
%}

\makeatletter

\preto\section{\everypar{}}
\preto\subsection{\everypar{}}
\preto\subsubsection{\everypar{}}

\renewcommand{\@afterheading}{%
  \@nobreaktrue
  \everypar{%
    \if@nobreak
      \@nobreakfalse
      \clubpenalty\@M
      \if@afterindent
      \else
        {\setbox\z@\lastbox}%
      \fi
    \else
      \clubpenalty\@clubpenalty
      \everypar{\numberedparagraph}%
    \fi
    \numberedparagraph
  }%
}

\makeatother

\begin{document}

\maketitle

\section{Sample Section}

\lipsum[1-4]

Some\label{sample} sample text.
\lipsum[5-10]

\subsection{Sample Subsection}

\lipsum[11-15]

\section{Another Section}

\lipsum[16-30]

Cross-reference to paragraph~\ref{sample} on page~\pageref{sample}.

\end{document}
