3

I have a environment to number the paragraphs in it, if I have to ignore some paragraphs in the environment which needn't be numbered, eg: I want to ignore numbering of the \lipsum[6-7], how to make it?

The whole codes of the environment are here:

 \documentclass{book}
\usepackage{mparhack}   % get marginpars to always show up on the correct side (need to compile twice)
\usepackage{lipsum}     % for dummy text

% change this to get the formatting you want
\newcommand{\parnum}{\bfseries\arabic{parcount}}
\newcounter{parcount}
\newenvironment{parnumbers}{%
\par%
   \everypar{\stepcounter{parcount}\leavevmode\marginpar[\hfill\parnum]
{\parnum}}%
\setcounter{parcount}{0}%to restart numbering in every environment
}{}

\begin{document}
\begin{parnumbers}
\lipsum[1-4]
\end{parnumbers}

\begin{parnumbers}
\lipsum[5-8]
\end{parnumbers}

\begin{parnumbers}
\lipsum[9-10]
\end{parnumbers}

\end{document}
0

2 Answers 2

4

You can define a starred version of parnumbers environment like (My method may be rude though)

\newenvironment{parnumbers*}{%
\par%
   \everypar{\stepcounter{parcount}\leavevmode\marginpar[\hfill]
{}}%
\setcounter{parcount}{0}%to restart numbering in every environment
}{}

Then

\begin{parnumbers}
\lipsum[5]
\begin{parnumbers*}
\lipsum[6-7]
\end{parnumbers*}
\lipsum[8]
\end{parnumbers}

should do the job.

The complete MWE:

\documentclass{book}
\usepackage{mparhack}   % get marginpars to always show up on the correct side (need to compile twice)
\usepackage{lipsum}     % for dummy text

% change this to get the formatting you want
\newcommand{\parnum}{\bfseries\arabic{parcount}}
\newcounter{parcount}
\newenvironment{parnumbers}{%
\par%
   \everypar{\stepcounter{parcount}\leavevmode\marginpar[\hfill\parnum]
{\parnum}}%
\setcounter{parcount}{0}%to restart numbering in every environment
}{}

\newenvironment{parnumbers*}{%
\par%
   \everypar{\stepcounter{parcount}\leavevmode\marginpar[\hfill]
{}}%
\setcounter{parcount}{0}%to restart numbering in every environment
}{}

\begin{document}
\begin{parnumbers}
\lipsum[1-4]
\end{parnumbers}

\begin{parnumbers}
\lipsum[5]
\begin{parnumbers*}
\lipsum[6-7]
\end{parnumbers*}
\lipsum[8]
\end{parnumbers}

\begin{parnumbers}
\lipsum[9-10]
\end{parnumbers}

\end{document}

enter image description here

3
  • Thank you for your reply.But there are still two problems:(1) it isn't exactly resolve the problem, I want ignore lipsum[6-7], so lipsum 5's number is '1', lipsum 8's number is 2,not 3. (2)Could it be a command form, not a environment form?
    – WonderTree
    Jul 15, 2012 at 9:45
  • But with your resolution lipsum 8's number is 3.
    – WonderTree
    Jul 15, 2012 at 9:53
  • OK, after I deleted \stepcounter{parcount} and \setcounter{parcount}{0} in \newenvironment{parnumbers*}, lipsum 8's number is 2. So there is only one question: Could it be a command, not in a form of environment ?
    – WonderTree
    Jul 15, 2012 at 10:30
1

I improve your codes as follows:

\newenvironment{parnumbers*}{%to ignore some items 
\par
\everypar{\leavevmode\marginpar[\hfill]
{}}%
}{}

So as I wanted, lipsum 5's number is 1 lipsum 8's number is 2 lipsum 6-7 are ignored.

The last question is how to make it by a command, not such a environment?

enter image description here

The complete MWE:

\documentclass{book}
 \usepackage{mparhack}   % get marginpars to always show up on the correct side (need to compile twice)
\usepackage{lipsum}     % for dummy text

% change this to get the formatting you want
\newcommand{\parnum}{\bfseries\arabic{parcount}}
\newcounter{parcount}
\newenvironment{parnumbers}{%
\par%
   \everypar{\stepcounter{parcount}\leavevmode\marginpar[\hfill\parnum]
{\parnum}}%
\setcounter{parcount}{0}%to restart numbering in every environment
}{}

\newenvironment{parnumbers*}{%
\par%
   \everypar{\leavevmode\marginpar[\hfill]
{}}%

}{}

\begin{document}
\begin{parnumbers}
\lipsum[1-4]
\end{parnumbers}

\begin{parnumbers}
\lipsum[5]
\begin{parnumbers*}
\lipsum[6-7]
\end{parnumbers*}
\lipsum[8]
\end{parnumbers}

\begin{parnumbers}
\lipsum[9-10]
\end{parnumbers}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.