3

Using the package makeidx I'm trying to generate an index entry with \index{TeX@\TeX} but it doesn't show up in the index. This is obviously due to the expansion of \TeX but I can't figure out how to make it work.

Update: OK, I now see where the problem was and I'll add code to reproduce it:

\documentclass{article}
\usepackage{makeidx}
\newcommand{\indexp}[1]{\index{#1}}
\makeindex

\begin{document}
\TeX\index{TeX@\TeX}

\pagebreak

\TeX\indexp{TeX@\TeX}

\printindex
\end{document}

I used my indexp command throughout my whole book because I otherwise had problems with index entries from footnotes. The \TeX index entry is generated with \index but not with \indexp, so it was my fault. Sorry for the noise.

Still, if someone could explain what exactly the difference is, I'd be thankful. I aped \indexp from somewhere because it solved problems I had but I don't really know how it differs from \index.

Another Update:

Sorry for the delay, but I was really busy. Here's a minimal example do demonstrate why I use \indexp and not \index:

\documentclass{scrbook}
\usepackage{makeidx}
\newcommand{\indexp}[1]{\index{#1}}
\makeindex
\begin{document}
The crux of the biscuit is the
apostrophe\index{apostrophe@\textsc{aprostropheA}}.\footnote{Really, it's the
  apostrophe\index{apostrophe@\textsc{aprostropheA}}.}

\pagebreak

The crux of the biscuit is the
apostrophe\indexp{apostropheB@\textsc{aprostropheB}}.\footnote{Really, it's the
  apostrophe\indexp{apostropheB@\textsc{aprostropheB}}.}
\printindex
\end{document}

With \index I get two different index entries which is obviously not what I want. With \indexp I get one which is fine.

  • 1
    Welcome to TeX.SX! Can you add a short but complete example of code? – egreg Sep 16 '15 at 16:57
  • This works without problems for me and shows the output of \TeX as expected, both with makeidx and imakeidx – user31729 Sep 16 '15 at 17:00
  • I see no real gain in using \indexp in place of \index, so probably there's more you aren't showing. What's the problem with footnotes? – egreg Sep 16 '15 at 23:35
2

There are category code changes involved when working with \index. As such, and since it seems like you're not doing anything other than passing an argument to \index via \indexp, use

\newcommand{\indexp}{\index}

instead of

\newcommand{\indexp}[1]{\index{#1}}

That way the argument is completely handled by \index, not \indexp.

enter image description here

\documentclass{article}
\usepackage{makeidx}
\newcommand{\indexp}{\index}
\makeindex

\begin{document}
\TeX\index{TeX@\TeX}

\pagebreak

\TeX\indexp{TeX@\TeX}

\printindex
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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