1

I have extracted the following code from an answer in Remove page number from index entries

which removes the page number from each index entry:

\documentclass{article}
\usepackage{xcolor}
\usepackage{imakeidx}

\makeindex[program=makeindex,options=-s mystyle.ist]

\usepackage{letltxmacro} \usepackage{filecontents} \makeatletter \let\mygobble@gobble \LetLtxMacro\OldIndex\index \renewcommand{\index}[1]{\OldIndex{#1|mygobble}} \makeatother \begin{filecontents}{mystyle.ist} quote '+' delim_0 " " delim_1 " " delim_2 " " delim_n " " \end{filecontents}

\begin{document} \LARGE

Test\index{foo} \index{bar} \printindex \end{document}

which produces the index output:

enter image description here

I thought, perhaps, there might be a way to modify the above code so that the page number might be "gobbled" on a selective basis instead of globally; more specifically, I attempted to define an index command, say, \index1 that would remove the page number if used---and, if using \index, the page number would be retained.

However, I was unsuccessful in my various attempts.

QUESTION: If possible, how might one modify the above code so that the entry page number may be removed on a selective (and not global) basis?

Thank you.

DDS
  • 8,816
  • 4
  • 9
  • 36

1 Answers1

1

Use \newcommand{\indexi}[1]{\OldIndex{#1|mygobble}} (numbers are not allowed in commands names)

a

\documentclass{article}
\usepackage{xcolor}
\usepackage{imakeidx}

\makeindex[program=makeindex,options=-s mystyle.ist]

\usepackage{letltxmacro} \usepackage{filecontents} \makeatletter \let\mygobble@gobble \LetLtxMacro\OldIndex\index \newcommand{\indexi}[1]{\OldIndex{#1|mygobble}} % changed <<<<<<<< \makeatother \begin{filecontents}{mystyle.ist} quote '+' delim_0 " " delim_1 " " delim_2 " " delim_n " " \end{filecontents}

\begin{document} \LARGE

Test\indexi{foo}  % no page number
\index{bar}
\printindex

\end{document}

Simon Dispa
  • 39,141