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}
  • 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 '15 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 '15 at 15:45
  • @ChristianHupfer egreg's thunderbolts are to be avoided at all costs. Will update my MNWE, – Ethan Bolker Sep 13 '15 at 15:53
2

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
\usepackage{letltxmacro}

\AtBeginDocument{%
  \LetLtxMacro\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}

Why \LetLtxMacro instead of \let is explained elsewhere on the site: When to use \LetLtxMacro?

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
\usepackage{letltxmacro,xparse}

\AtBeginDocument{%
  \LetLtxMacro\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).

  • Thank you. I didn't even have time to update using \LetLtxMacro1. – Ethan Bolker Sep 13 '15 at 16:11
  • @EthanBolker Read my profile page: Pronto prontissimo son come il fulmine: sono il factotum della città. – egreg Sep 13 '15 at 16:12
  • Google translate says "Ready than ready are like lightning : are the factotum of the city". – Ethan Bolker Sep 13 '15 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 '15 at 20:11

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.