[Tex/LaTex] make index entries refer to number selected paragraphs

indexingmemoir

For a given work, I have to number some selected paragraphs, with a continuous numerotation throughout all the book.
I can do it using this tip.

I need the index entries refer to the paragraph numbers and not to the pages.
I've seen this post, but I'm not able to customize it for my need, as I am quite a newbie to LaTeX and I don't understand which part of the implemantation I should change to refer to the numbered paragraphes…

Till now, I've not choosen the document class — as the tip for numbering some selected paragraphs is for memoir, I think I will use it.

Thanks for your help.

Best Answer

Following the example you give, using the memoir class, here is a simple way to implement what you want. Memoir may be a good option if you have precise, complex needs, because it is very comprehensive, especially for long documents.

Because memoir's \frontmatter, \mainmatter and friends alter the way section numbering is done, I suggest you create a whole new counter, since you are not really using it as a sectioning command anyway. If you need to add the paragraphs to the table of contents, it is possible too, so no worries there (just ask).

Here is the example document:

\documentclass{memoir}

% Load dummy text
\usepackage{lipsum}

% We create a counter
\newcounter{paracount}

% We create the paragraph command
\def\para{%
    \refstepcounter{paracount}%
    \noindent\textbf{\theparacount.\quad}}

% We create an index
\makeindex

% We tell memoir to index paragraphs and not pages
\renewcommand{\index}[1]{\specialindex{\jobname}{paracount}{#1}}


\begin{document}

\frontmatter

\para \index{Front matter entry} \lipsum[4]

\mainmatter

\para \index{First entry} \lipsum[1]

\para \index{Second entry} \lipsum[2]

\para \index{Third entry} \lipsum[3]

\printindex

\end{document}

Note that you can tell memoir to index things based on any counter, you just need to specify it in the \specialindex{\jobname}{<counter>}{#1} line.

Now, all you need to do is run LaTeX, then MakeIndex, then LaTeX again.

Related Question