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.

0

1 Answer 1

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}
3
  • Thank you for this very helpful answer.
    – DDS
    Commented Nov 27, 2021 at 16:36
  • @mlchristians You did all the work :-) Commented Nov 27, 2021 at 16:50
  • Thank you again for the assistance you have given me on this, and other problems as well.
    – DDS
    Commented Nov 27, 2021 at 16:53

You must log in to answer this question.

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