Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
add comment

2 Answers

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

share|improve this answer
    
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 '12 at 9:45
    
But with your resolution lipsum 8's number is 3. –  WonderTree Jul 15 '12 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 '12 at 10:30
add comment
up vote 1 down vote accepted

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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