%%% File: numberpar.sty
%
% Use as:
%        \documentstyle[...,numberpar,...]{whatever}
%
% An attempt at numbering paragraphs, as is supposed to be ``good
% practice'' in preparation of legal opinions.
%
% Author: Robin Fairbairns (rf@cl.cam.ac.uk), with help from several
%         readers and posters of/to comp.text.tex
% Derived (first pass) from Denys Duchier's `secret.sty'
%
% Modified extensively at Softway by Peter Chubb to handle
% latexinfo constructs and paragraphs numbered within sections.
%
%  All the documentation you're going to get:
%
% Start paragraph numbering with \numberpars, stop it again with
% \nonumberpars
%
% Has a tendency to get confused by all sorts of things; won't number
% paragraphs in lists, etc., but will number section headings...
%
% Improvements to this code would be *most* welcome...
%
\newcounter{par@number}
%
% Paragraphs are numbered within the smallest enclosing unit.
\@addtoreset{par@number}{part}
\@addtoreset{par@number}{chapter}
\@addtoreset{par@number}{section}
\@addtoreset{par@number}{subsection}
\@addtoreset{par@number}{subsubsection}
\@addtoreset{par@number}{paragraph}
\@addtoreset{par@number}{subparagraph}

% Whether or not paragraph numbers are being generated
\newif\if@numberingpars   \@numberingparsfalse
% Whether or not the next paragraph is to be indented.
\newif\if@nparindent \@nparindenttrue
% Whether or not the next par is to be numbered.  Reset by everypar.
\newif\if@npar \@npartrue

% Save everypar, because LaTeX steals it for almost everything.
 \let\Realeverypar\everypar
 \newtoks\npeverypar  \npeverypar{}

 \def\everypar#1{\Realeverypar{#1\if@numberingpars\the\npeverypar\fi}}

% subvert \list, since it has the tendency to muck about with \everypar
  \let\@@list\list
  \let\@@endlist\endlist

  \def\list#1#2{\def\everypar##1{\Realeverypar{##1}}\@@list{#1}{#2}}
  \def\endlist{\@@endlist
               \def\everypar##1{\Realeverypar{\the\npeverypar##1}}}

% subvert \footnote, to avoid numbering _them_
  \let\@@footnote\footnote
  \def\footnote{\@ifnextchar[{\@@xxfootnote}{\@@xfootnote}}
  \def\@@xxfootnote[#1]#2{\if@numberingpars\@numberingparsfalse
                          \@@footnote[#1]{#2}\@numberingparstrue
                          \else\@@footnote[#1]{#2}\fi}
  \def\@@xfootnote#1{\if@numberingpars\@numberingparsfalse
                      \@@footnote{#1}\@numberingparstrue
                      \else\@@footnote{#1}\fi}

% We don't really want section headers to have paragraph numbers.

\def\@startsection#1#2#3#4#5#6{\if@noskipsec \leavevmode \fi
   \@nparfalse\par \@tempskipa #4\relax
   \@afterindenttrue
   \ifdim \@tempskipa <\z@ \@tempskipa -\@tempskipa \@afterindentfalse\fi
   \if@nobreak \everypar{}\else
     \addpenalty{\@secpenalty}\addvspace{\@tempskipa}\fi \@ifstar
     {\@ssect{#3}{#4}{#5}{#6}}{\@dblarg{\@sect{#1}{#2}{#3}{#4}{#5}{#6}}}}
 
\def\@xsect#1{\@tempskipa #1\relax
      \ifdim \@tempskipa>\z@
       \par \nobreak
       \vskip \@tempskipa
       \@afterheading\global\@npartrue\global\@nparindentfalse
    \else \global\@nobreakfalse \global\@noskipsectrue
       \everypar{\if@noskipsec \global\@noskipsecfalse\global\@nparindentfalse
                   \clubpenalty\@M \hskip -\parindent
                   \begingroup \@svsechd \endgroup \unskip
                   \hskip -#1\relax  % relax added 14 Jan 91
                  \else \clubpenalty \@clubpenalty
                    \everypar{}\fi}\fi\ignorespaces}%

\def\@begintheorem#1#2{\@nparfalse\trivlist \@nparfalse\item[\hskip \labelsep{\bf #1\ #2}]\it} 

% We subvert verbatim like LaTeXInfo environments
% This is the definition that ^M gets inside \lisp and \example, etc.
{\obeyspaces%
\gdef\lisppar{\null\@nparfalse\endgraf}}

% And float environments.  No real paragraphs in a float!
\def\@xfloat#1[#2]{\global\@nparfalse%
   \ifhmode \@bsphack\@floatpenalty -\@Mii\else
   \@floatpenalty-\@Miii\fi\def\@captype{#1}\ifinner
      \@parmoderr\@floatpenalty\z@
    \else\@next\@currbox\@freelist{\@tempcnta\csname ftype@#1\endcsname
       \multiply\@tempcnta\@xxxii\advance\@tempcnta\sixt@@n
       \@tfor \@tempa :=#2\do
                        {\if\@tempa h\advance\@tempcnta \@ne\fi
                         \if\@tempa t\advance\@tempcnta \tw@\fi
                         \if\@tempa b\advance\@tempcnta 4\relax\fi
                         \if\@tempa p\advance\@tempcnta 8\relax\fi
         }\global\count\@currbox\@tempcnta}\@fltovf\fi
    \global\setbox\@currbox\vbox\bgroup
%    \boxmaxdepth\z@     % commented out 15 Dec 87
    \hsize\columnwidth \@parboxrestore}
 
\def\end@float{\par\vskip\z@\egroup %% \par\vskip\z@ added 15 Dec 87
   \ifnum\@floatpenalty <\z@
     \@cons\@currlist\@currbox
     \ifdim \ht\@currbox >\textheight
%% RmS 91/11/06 added warning message
% perhaps we should use an error message
        \@warning{Float larger than \string\textheight}%
        \ht\@currbox\textheight \fi
     \ifnum\@floatpenalty <-\@Mii
        \penalty -\@Miv
        \@tempdima\prevdepth    %% saving and restoring \prevdepth added
        \vbox{}%                %% 26 May 87 to prevent extra vertical
        \prevdepth \@tempdima   %% space when used in vertical mode
        \penalty\@floatpenalty
%% RmS 92/03/18 changed \@esphack to \@Esphack
      \else \vadjust{\penalty -\@Miv \vbox{}\penalty\@floatpenalty}\@Esphack
     \fi\fi   \global\@npartrue
	}


\let\@node\node
\def\node{\global\@nparfalse\@node}
\let\@noindent\noindent
\def\noindent{\global\@nparindentfalse\@noindent}

\def\numberpars{\npeverypar{\if@npar\stepcounter{par@number}\llap
  {{\small\@currentlabel/\arabic{par@number}\qquad}%
%	\if@afterindent\@nparindentfalse\fi
%	\if@endpe\@nparindentfalse\fi
%	\if@nparindent\hskip\parindent\else\global\@nparindenttrue\fi
	\setbox0=\lastbox\hskip\wd0\box0
	\hskip\labelsep\hskip\leftskip
	\if@inlabel\hskip\wd\@labels\fi
  }\fi\global\@npartrue}\global\@numberingparstrue
  \@ifstar{\setcounter{par@number}{0}}{}}
%
\def\nonumberpars{%\npeverypar{}
                  \@numberingparsfalse}
%
%\tracingall
\endinput
