0

How can I get "see" indexing commands, created using \indexsee, such as...

\indexsee{zilch!nadaX}{nothing} % double-level "zilch"

...to work in the following source file see.tex?

%% see.tex
\begin{filecontents}{see.ist}
% MakeIndex style file
% output main entry <entry> as: \item \idxmark{<entry>}, 
item_0  "\n\\item \\idxmark{"
delim_0 "}, "
% not forgetting the subitem case
item_x1 "} \n \\subitem "
headings_flag 1
heading_prefix "{\\medskip\\hfill\\large\\textsf{\\textbf{"
heading_suffix "}}\\hfill}\\medskip\\nopagebreak\n"
\end{filecontents}

%\documentclass{memoir}
\documentclass{book}
\usepackage{makeidx}

%% Babel (to be used with multiple languages):
\RequirePackage[T1]{fontenc}%
\RequirePackage[main=english]{babel}%

%% Indexing:
\newcommand\gobbleone[1]{}
\newcommand{\seeonly}[2]{\, (\emph{\seename} #1)}
\newcommand{\also}[2]{\unskip(\emph{\alsoname} #1)}
\newcommand{\Also}[2]{\unskip\emph{See also} #1}
\let\oldindex\index
\renewcommand{\index}[1]{\def\exptoindex{#1}\expandafter\oldindex\expandafter{\exptoindex}}
%\newcommand{\indexsee}[2]{\index{#1\protect\gobbleone|seeonly{#2}}}
% From https://tex.stackexchange.com/questions/332093/error-with-entries-in-index-page-header-memoir-class:
\makeatletter
\def\indexsee#1{\indexseeI#1@\end}
\def\indexseeI#1@#2\end{%
  \def\temp{#2}%
  \ifx\temp\empty
    \def\next{\indexseeIII{#1}{#1}}%
  \else
    \def\next{\indexseeII#1@#2\end}%
  \fi
  \next
}
\def\indexseeII#1@#2@\end{\indexseeIII{#1}{#2}}
\def\indexseeIII#1#2#3{\index{#1@#2\protect\gobbleone|seeonly{#3}}}
\newcommand{\indexalso}[2]{\index{#1!zzzz@\protect\gobbleone|also{#2}}}
\newcommand{\indexAlso}[2]{\index{#1!zzzz@\protect\gobbleone|Also{#2}}}
\makeatother

% fix to put hyperlink on mainref, too:
\newcommand{\mainref}[1]{\textbf{\emph{\hyperpage{#1}}}}

\newcommand{\idxmark}[1]{{\let\gobbleone\relax\markboth{\sffamily\bfseries#1}{\sffamily\bfseries#1}}#1}

%% Cross-referencing
\RequirePackage[pdftex]{hyperref}
\hypersetup{colorlinks,linkcolor=red}

\makeindex

\begin{document}

\mainmatter
%\chapter{Nothing}

This book is about zero, that is, nothing, null, nill, nada, or zilch.
%
\index{nothing|mainref}
\index{nothing}
\index{nothing!nil}
\index{nothing!nil!and zero}
\index{nothing!null}
\index{null elements}
%
\index{zero}
\indexsee{zero element}{zero}
\indexAlso{zero}{zero element}
\indexalso{nothing!nil}{null element}

Testing subitem ``see''.
\index{nothing!nada}
\index{nadaY}
\index{zilch!nadaY}
\indexsee{zilch!nadaX}{nothing} % double-level "zilch"
% Fixed -- wrong 2nd argument used:
% \indexsee{zilch!nadaY}{nothing!nadaW} % disappears
%\indexalso{zilch}{nadaZ!nil} % disappears
\indexsee{zilch!nadaY}{nothing, nadaW} % OK
\indexAlso{zilch}{nadaZ, nil} % OK

\backmatter
%\pagestyle{index}
\printindex

\end{document}

The printed index obtained is:

Printed index fails to get \indexsee entry.

What I want to obtain in the printed index for that \indexsee{zilch!nadaX}{nothing} item to appear as follows (where I've used ~~~ to indicate indenting for a subenty):

zilch
~~~ nadaX (see nothing)

The initial run of pdflatex generates this see.idx:

\indexentry{nothing|hyperindexformat{\mainref}}{1}
\indexentry{nothing|hyperpage}{1}
\indexentry{nothing!nil|hyperpage}{1}
\indexentry{nothing!nil!and zero|hyperpage}{1}
\indexentry{nothing!null|hyperpage}{1}
\indexentry{null elements|hyperpage}{1}
\indexentry{zero|hyperpage}{1}
\indexentry{zero element@zero element\gobbleone |hyperindexformat{\seeonly{zero}}}{1}
\indexentry{zero!zzzz@\gobbleone |hyperindexformat{\Also{zero element}}}{1}
\indexentry{nothing!nil!zzzz@\gobbleone |hyperindexformat{\also{null element}}}{1}
\indexentry{nothing!nada|hyperpage}{1}
\indexentry{nadaY|hyperpage}{1}
\indexentry{zilch!nadaY|hyperpage}{1}
\indexentry{zilch!nadaX@zilch!nadaX\gobbleone |hyperindexformat{\seeonly{nothing}}}{1}
\indexentry{zilch!nadaY@zilch!nadaY\gobbleone |hyperindexformat{\seeonly{nothing, nadaW}}}{1}
\indexentry{zilch!zzzz@\gobbleone |hyperindexformat{\Also{nadaZ, nil}}}{1}

The subsequent run of makeindex -s see.ist see, generates this see.ind:

\begin{theindex}

  \item nadaY, \hyperpage{1}
  \item nothing, \hyperindexformat{\mainref}{1}, \hyperpage{1}
    \subitem nada, \hyperpage{1}
    \subitem nil, \hyperpage{1}
      \subsubitem and zero, \hyperpage{1}
      \subsubitem \gobbleone , 
        \hyperindexformat{\also{null element}}{1}
    \subitem null, \hyperpage{1}
  \item null elements, \hyperpage{1}

  \indexspace

  \item zero, \hyperpage{1}
    \subitem \gobbleone , \hyperindexformat{\Also{zero element}}{1}
  \item zero element\gobbleone , \hyperindexformat{\seeonly{zero}}{1}
  \item zilch
    \subitem zilch
      \subsubitem nadaX\gobbleone , 
        \hyperindexformat{\seeonly{nothing}}{1}
    \subitem nadaY, \hyperpage{1}
    \subitem zilch
      \subsubitem nadaY\gobbleone , 
        \hyperindexformat{\seeonly{nothing, nadaW}}{1}
    \subitem \gobbleone , \hyperindexformat{\Also{nadaZ, nil}}{1}

\end{theindex}

Notes:

  1. I'm using a custom \indexsee (and custom \indexalso, \indexAlso) just so as to change their format from what would result from standard commands such as \index{something|see other}
  2. In case it would make a difference, I will actually be using this with the memoir document class (and of course then no separate loading of makeidx).

Related posts: The current definition of \indexsee comes from https://tex.stackexchange.com/a/501483/13492. That is a modification needed with babel. My original indexing commands came from https://tex.stackexchange.com/a/332098/13492 and https://tex.stackexchange.com/a/318504/13492.

Your Answer

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

Browse other questions tagged or ask your own question.