# Using memoir, how do I number paragraphs?

I am trying to implement paragraph numbering with memoir. I would like the numbers to be

1. in the outside margin,
2. flush against the text block, and
3. vertically aligned with the first line of the paragraph.

Combining various bits of code I found here at Stack Exchange, I have

\documentclass[12pt]{memoir}
\pagestyle{empty}

\usepackage{lipsum}

\strictpagecheck
\newcounter{PN}
\marginparmargin{outer}

%% ATTEMPT A

%% ATTEMPT B

\begin{document}

\pnum\lipsum[\value{PN}]

\pnum\lipsum[\value{PN}]

\end{document}


Both attempt A and attempt B are close. But A puts the numbers too high, so that they are between the last line of the previous paragraph and the first line of the current paragraph, while B puts the numbers too low, so that they are between the first and second lines of the current paragraph.

Any suggestions would be appreciated.

EDIT: My Response to the Responses

The suggestions from both Mike Renfro and Gonzalo Medina were helpful (and I flagged them as such). In my actual document, I change the style of the chapter titles, and this for some reason causes the paragraph numbers to be shifted on the first page of each chapter. (If I do not apply the custom chapter style, this issue goes away.) I ultimately chose Mike's answer because it doesn't have this issue. Thanks to both of you (and lockstep). Also, I didn't know about the \stepcounter command; that's more elegant.

-

Working from Gonzalo's answer, but using memoir's built-in marginal note capabilities (see section 12.3 of the memoir manual):

\documentclass[12pt]{memoir}
\pagestyle{empty}
\usepackage{lipsum}
\newcounter{PN}
\sideparmargin{outer}
\newcommand\pnum{%
\stepcounter{PN}\sidepar{\arabic{PN}}}
\begin{document}
\pnum\lipsum[\value{PN}]
\pnum\lipsum[\value{PN}]
\end{document}

-

Perhaps using \marginnote from the marginnote package?

\documentclass[12pt]{memoir}
\pagestyle{empty}
\usepackage{marginnote}
\usepackage{lipsum}

\strictpagecheck
\newcounter{PN}
\marginparmargin{outer}

\newcommand\pnum{%
\stepcounter{PN}\marginnote{\mpjustification\arabic{PN}}}

\begin{document}

\pnum\lipsum[\value{PN}]

\pnum\lipsum[\value{PN}]

\end{document}


If you want something automatic (up to certain extent) you can use \everypar:

\documentclass[12pt]{memoir}
\usepackage{lipsum}

\newcounter{PN}
\marginparmargin{outer}

\reversemarginpar

\newcommand\countpar{%
\everypar{\stepcounter{PN}\marginpar{\arabic{PN}}}%
}
\newcommand\mcountpar{%
\stepcounter{PN}\marginpar{\arabic{PN}}%
}

\pagestyle{empty}

\begin{document}
\countpar
\lipsum[1-2]

\begin{enumerate}
\item \mbox{}\mcountpar\lipsum[2]
\end{enumerate}

\end{document}


\stepcounter{PN} could be changed to \refstepcounter{PN} if one wants to cross-reference paragraphs (Thanks to lockstep for pointing out this).

-