1

I have created a name index with the imakeidx package. My question is:

Is it possible to add a label as the key for the index and print e.g. \nameref{label} in the index?

The pseudo-code could look like this:

\index[nameindex]{some_label}

If the label was a label to a persons name, I would like the name to be printed, and not the label itself. Is that possible and how?

1
  • You mean a text label then. One problem may arise: \nameref isn't expandable, but as far as I know, \index does not try to expand this at all.
    – user31729
    Dec 15, 2015 at 18:00

1 Answer 1

2

This is a variation of an older answer by me, writing text labels to the .aux file.

The \labelText command actually be inside the \createPerson command from the other question of the O.P.

I've added an index here to, but only, if the unstarred version is used.

\documentclass{article}
\usepackage{blindtext}
\usepackage{imakeidx}
\usepackage{hyperref}


\makeindex[name={nameindex},title={Index of persons}]

\newcounter{mylabelcounter}


\makeatletter
\NewDocumentCommand{\labelText}{smm}{%
 \IfBooleanF{#1}{%
 \index[nameindex]{#2}% Do not make an index here
 }%
\refstepcounter{mylabelcounter}%
  \immediate\write\@auxout{%
    \string\newlabel{#3}{{1}{\thepage}{{#2}}{mylabelcounter.\number\value{mylabelcounter}}{}}%
  }%
}
\makeatother

\begin{document}
\blindtext[5]

\index[nameindex]{\nameref{label:einstein}}
\labelText{Albert Einstein}{label:einstein}

\printindex[nameindex]

\end{document}
2

You must log in to answer this question.

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