1

I am creating document containing a list of quotations from a very long book, each quotation associated with a page number (from the book). I would like to create an index to the document containing the page numbers of the book itself, not the page numbers of the document I am creating. The following code generates a document with an index, all the entries pointing, naturally, to page number 1. I would like them, rather, to point to pages 5, 14, and 17.

\documentclass[10pt]{article}%

\usepackage{marginnote}
\usepackage[margin=1.5in]{geometry}
\usepackage{changepage}

\usepackage{imakeidx}
\makeindex[columns=2]

\setlength{\marginparsep}{-0.4em}
\setlength{\marginparwidth}{3em}

\setlength{\parindent}{0em}
\setlength{\parskip}{0.5\baselineskip}

\newcommand{\nt}[1]{\reversemarginpar\marginpar{\begin{footnotesize}#1 \end{footnotesize}}}

\begin{document}

\begin{footnotesize}
Truly man is a marvelously vain, diverse, and undulating object.\nt{5}\index{Diversity}

I am almost ready to vow irreconcilable hatred against all democratic
rule.\nt{14}\index{Democracy}

What causes do we not invent for the misfortunes that befall us?\nt{17}\index{Causes}

\end{footnotesize}

\cleardoublepage
\printindex

\end{document}

1 Answer 1

1

You can define a personal MakeIndex style; if the name is the same as the main document's with extension .mst it will be automatically used.

In the style file we change the delim_0 (for first level index items) and delim_t that's added at the end of each entry.

Finally, I define a wrapper for \index to use the book page given as argument. I reuse \nt, but you can use a different command in case you want to have notes without a corresponding index entry.

\begin{filecontents*}{\jobname.mst}
delim_0 "\\ignore"
delim_t "\\ignore"
\end{filecontents*}

\documentclass[10pt]{article}%

\usepackage{marginnote}
\usepackage[margin=1.5in]{geometry}
\usepackage{changepage}

\usepackage{imakeidx}
\makeindex[columns=2]

\setlength{\marginparsep}{-0.4em}
\setlength{\marginparwidth}{3em}

\setlength{\parindent}{0em}
\setlength{\parskip}{0.5\baselineskip}

\newcommand{\nt}[2]{%
  \reversemarginpar\marginpar{\footnotesize #1}%
  \index{#2@#2\bookpage{#1}}
}
\protected\def\bookpage#1{,~#1}
\protected\def\ignore#1\ignore{}

\begin{document}

Truly man is a marvelously vain, diverse, and undulating object.\nt{5}{Diversity}

I am almost ready to vow irreconcilable hatred against all democratic
rule.\nt{14}{Democracy}

What causes do we not invent for the misfortunes that befall us?\nt{17}{Causes}

\printindex

\end{document}

enter image description here

The .ind file will be

\begin{theindex}

  \item Causes\bookpage {17}\ignore1\ignore

  \indexspace

  \item Democracy\bookpage {14}\ignore1\ignore
  \item Diversity\bookpage {5}\ignore1\ignore

\end{theindex}

so you see how the typesetting works: \bookpage expands to , <number> and the part between \ignore...\ignore gets ignored.

Avoid \begin{footnotesize}.

1
  • Many thanks, egreg! Works beautifully.
    – user257660
    Oct 20, 2022 at 18:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .