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.
The following solution uses the same method as the table of contents is generated.
The entries for the list of important things are written to the .aux
file, then at the end of the document LaTeX writes it to the file \jobname.imp
. In the next run this file is read and a table is set.
\documentclass{report}
\usepackage{longtable}
\makeatletter
\newlength\ImpLineWidth
\newtoks\ImpToks
\newcommand*{\printimportant}{%
\clearpage
\section*{\centering Index of important things}%
\setlength{\ImpLineWidth}{\linewidth}%
\addtolength{\ImpLineWidth}{-2\tabcolsep}
\begin{longtable}{@{}p{.6\ImpLineWidth}p{.4\ImpLineWidth}@{}}%
\global\ImpToks{}%
\@starttoc{imp}%
\the\ImpToks
\end{longtable}%
}
\newcommand*{\importantentry}[2]{%
\global\ImpToks\expandafter{%
\the\ImpToks
\centering #1&
\centering #2\tabularnewline
}%
\ignorespaces
}
\newcommand*{\important}[1]{%
\addtocontents{imp}{%
\protect\importantentry{#1}{%
\ifnum\value{part}=0 %
\else
part~\thepart, %
\fi
\ifnum\value{chapter}=0 %
\else
chapter~\thechapter, %
\ifnum\value{section}=0 %
\else
section~\thesection, %
\fi
\fi
page~\thepage
}%
}%
}
\makeatother
\begin{document}
\part{First part}
\important{Some indexed \dots}
\chapter{First chapter}
\important{Again}
\section{First section}
\important{Idem 1}
\chapter{Second chapter}
\important{Idem 2}
\printimportant
\end{document}
Index based variant
The following uses the index machinery. For the case that there is already an index I have used package index
to get a second one. (There are other packages like multind
, …)
The sectioning titles are usually not available. Exception is the latest title that packages like titleref
, nameref
or zref-titleref
remember. For the best control of the numbering and title, the sectioning commands needs to be patched. Here I have used a shortcut via \addcontentsline
assuming that only sectioning titles are relevant that also goes into the table of contents. A glitch remains, the large space between the part number and the part title, the standardclass uses the hardcoded \hspace{1em}
here.
But anyway, you are using a different unknown setup as the word numbering shows.
For simplicity it is also assumed that the part title is always present.
The first LaTeX run of test.tex
generates test.imx
. The final index file test.imp
is generated via:
makeindex -o test.imp test.imx
Also a different style file than the standard settings can be used to control the output of the final index file.
\documentclass{report}
\usepackage{index}
\newindex{imp}{imx}{imp}{Index of important things}
\makeatletter
\newlength\ImpLineWidth
\newtoks\ImpToks
\newcommand*{\printimportant}{%
\begingroup
\def\numberline##1{##1:~}%
\renewcommand*{\theindex}{%
\clearpage
\section*{\centering Index of important things}%
\setlength{\parskip}{1ex plus .5ex minus .25ex}%
\setlength{\parindent}{0pt}%
\let\item\@idxitem
}{%
\clearpage
}%
\printindex[imp]%
\endgroup
}
% Remember sectioning titles
\newcommand*{\imp@toc}{toc}
\@ifdefinable{\imp@org@addcontentsline}{%
\let\imp@org@addcontentsline\addcontentsline
\renewcommand*{\addcontentsline}[3]{%
\edef\imp@temp{#1}%
\ifx\imp@temp\imp@toc
\begingroup
\expandafter\protected@xdef\csname imp@current@#2\endcsname{#3}%
\csname imp@cleanup@#2\endcsname
\endgroup
\fi
\imp@org@addcontentsline{#1}{#2}{#3}%
}%
}
% Clear subordinate sectioning titles
\def\imp@temp#1#2{%
\expandafter\newcommand\csname imp@cleanup@#1\endcsname{%
\global\expandafter\let\csname imp@current@#2\endcsname\@empty
\csname imp@cleanup@#2\endcsname
}%
}
\imp@temp{part}{chapter}
\imp@temp{chapter}{section}
\imp@temp{section}{subsection}
\newcommand*{\important}[2][]{%
\def\imp@temp{#1}%
\protected@edef\imp@temp{%
\noexpand\index[imp]{%
\ifx\imp@temp\@empty
\else
#1@%
\fi
#2; %
% assuming the part is always present.
part~\csname imp@current@part\endcsname
\ifx\imp@current@chapter\@empty
\else
, chapter~\csname imp@current@chapter\endcsname
% section, ...
\fi
|textbf%
}%
}%
\imp@temp
}
\makeatother
\begin{document}
\tableofcontents
\part{First part}
\important{Some indexed \dots}
\chapter{First chapter}
\important{Again}
\section{First section}
\important{Idem 1}
\chapter{Second chapter}
\important{Idem 2}
\printimportant
\end{document}
Best Answer
based on the discussion in the comments, the following suggestion will not solve all problems, but it should get rid of some of them.
if a term to be indexed falls near the end of a page, it is generally a good idea to place the
\index
entry before the text string, especially if the term contains more than one word, or might be hyphenated.in the case of a multi-word term, consider what a person looking in the index will be looking for on the referenced page. if the term is a name, e.g.
Albert Einstein
, a person looking in the index will look for "Einstein" -- then put\index
after the name. if they'd look for the first word of the phrase, e.g. "probability theory", put it before.i have compiled a document addressing various problems that arise in indexing; it has been posted on the ams web server. (this document is still a work in progress, but is far enough along to be useful. the incomplete portions are marked as such. comments are welcome; the address is included in the introduction.)
the "off by one" problem is encountered quite frequently, and is addressed in my "manual" in greater detail than described above.