2

To make sure I've indexed what I should I want to footnote every indexed item in a draft of my document. The MNWE that follows is what I've tried. The renewed \index command properly creates an index entry, but doesn't generate the footnote. \marginpar instead of \footnote fails too. So does \marginnote.

\documentclass{article}

\usepackage{marginnote}
\usepackage{imakeidx}   % needed in the real document
\usepackage{refcount}   % needed in the real document

\let\oldindex\index
\renewcommand{\index}[1]{%
%\footnote{INDEXING #1}
\marginnote{#1}
\oldindex{#1}
}

\makeindex[intoc] % needs imakeidx

\begin{document}
Here is an entry\index{entry} to index\index{index}.
Check that margin notes work\marginnote{This is a margin note}
Check that footnotes work\footnote{This is a footnote}

\printindex
\end{document}
3
  • 1
    Index can be used in places where float constructions like footnote and marginpar cannot be used. You might want to use marginnote (package of the same name). Also try to search ctan, fairly certain there is a package for this
    – daleif
    Sep 13, 2015 at 15:37
  • You will be struck by the thunderbolts of egreg because you misused index an his package. Please consider, that \index has an optional argument here, which is forgotten with \let here
    – user31729
    Sep 13, 2015 at 15:45
  • @ChristianHupfer egreg's thunderbolts are to be avoided at all costs. Will update my MNWE, Sep 13, 2015 at 15:53

2 Answers 2

3

You have to delay \renewcommand{\index} at begin document:

\documentclass{article}

\usepackage{imakeidx}   % needed in the real document
\usepackage{refcount}   % needed in the real document

\AtBeginDocument{%
  \NewCommandCopy{\oldindex}{\index}%
  \renewcommand{\index}[1]{%
    \footnote{INDEXING #1}%
    \marginpar{#1}%
    \oldindex{#1}%
  }%
}

\makeindex[intoc] % needs imakeidx

\begin{document}
Here is an entry\index{entry} to index\index{index}.

\printindex
\end{document}

The original answer used \LetLtxMacro for reasons explained at When to use \LetLtxMacro? but nowadays \NewCommandCopy is to be preferred.

Not that it's really needed here, but it's better practice any time a command has (or appears to have) an optional argument.

If you also want to support the optional argument to \index, then you can use xparse that makes things easier.

\documentclass{article}

\usepackage{imakeidx}   % needed in the real document
\usepackage{refcount}   % needed in the real document

\AtBeginDocument{%
  \NewCommandCopy{\oldindex}{\index}%
  \RenewDocumentCommand{\index}{om}{%
    \footnote{INDEXING #2}%
    \marginpar{#2}%
    \IfNoValueTF{#1}{\oldindex{#2}}{\oldindex[#1]{#2}}%
  }%
}

\makeindex[intoc] % needs imakeidx

\begin{document}
Here is an entry\index{entry} to index\index{index}.

\printindex
\end{document}

(I used \marginpar throughout, because \marginnote results in overlapped entries if on the same line).

4
  • Thank you. I didn't even have time to update using \LetLtxMacro1. Sep 13, 2015 at 16:11
  • @EthanBolker Read my profile page: Pronto prontissimo son come il fulmine: sono il factotum della città.
    – egreg
    Sep 13, 2015 at 16:12
  • Google translate says "Ready than ready are like lightning : are the factotum of the city". Sep 13, 2015 at 20:05
  • @EthanBolker “Readier than ready, I'm like the lightning: I'm the town's Jack-of-all-trades.” From Rossini's “Il barbiere di Siviglia”.
    – egreg
    Sep 13, 2015 at 20:11
0

Here is what I use for exactly the same purpose. leaves \index untouched:

\newcommand{\indx}1{\colorbox{yellow}{\footnotesize #1}\index{#1}}%checking

%\newcommand{\indx}1{\index{#1}} %standard \index

\item to toggle perspective view \indx{perspective view},
\item store and select camera positions (snapshots). Only the camera and the view angle (zoom) are stored, not the result type.
\item Legend and status bar can be moved freely on the \indx{Legend!move} screen with the left mouse button pressed.

How it looks

2
  • first answer, sorry. it is \newcommand{\indx}[1]{\color...
    – Jetrock
    Jan 26 at 12:45
  • 1
    Welcome to TeX.SE!
    – Mensch
    Jan 26 at 13:18

You must log in to answer this question.

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