I wanted my "see" cross-references within the index to be formatted in the form:
this (see that)
So thanks to Change index "see also" and "see" format, I use the definitions of \seeonly
shown in the following source file.
But I also want the page headings of the index to show the first and last index entry on each page there. So I also defined \idxmark
, use the index
page style, and employ the index .ist
style file described in the memoir
documentation and now also included in my source.
% File indexdoc.tex
\documentclass{memoir}
\newcommand{\idxmark}[1]{#1\markboth{#1}{#1}}
\makepagestyle{index}
\makeheadrule{index}{\textwidth}{\normalrulethickness}
\makeevenhead{index}{\rightmark}{}{\leftmark}
\makeoddhead{index}{\rightmark}{}{\leftmark}
\makeevenfoot{index}{}{\thepage}{}
\makeoddfoot{index}{}{\thepage}{}
\newcommand\gobbleone[1]{}
\newcommand{\seeonly}[2]{\, (\emph{\seename} #1)}
\let\oldindex\index
\renewcommand{\index}[1]{\def\exptoindex{#1}\expandafter\oldindex\expandafter{\exptoindex}}
\newcommand{\indexsee}[2]{\index{#1@#1\protect\gobbleone|seeonly{#2}}}
\begin{filecontents}{indexdoc.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 "
\end{filecontents}
\makeindex
\begin{document}
This is some text\indexsee{text}{verbiage}. Which is a synonym for verbiage\index{verbiage}.
\backmatter
\pagestyle{index}
\printindex
\end{document}
Those two things, alas, clash; I get error message:
Writing index file indexdoc.idx
(./indexdoc.aux) [1{/Users/user/Library/texlive/2016/texmf-var/fonts/map/
pdftex/updmap/pdftex.map}] [2] (./indexdoc.ind
./indexdoc.ind:3: Argument of \gobbleone has an exra }.Runaway argument?
./indexdoc.ind:3: Paragraph ended before \gobbleone was complete.
<to be read again>
\par
l.3 \item \idxmark{text\gobbleone }
, \seeonly{verbiage}{1}
?
<inserted text>
\par
l.3 \item \idxmark{text\gobbleone }
, \seeonly{verbiage}{1}
?
Without the \idxmark
definition, the index page style, and the index .ist style file from memman.pdf
, the definition of \seeonly
(in terms of \gobble
) causes no problem.
How can the clash be resolved?
Originally accepted answer not robust with math
I had originally accepted "siracusa"'s answer, which redefined \idxmark
. However, I now find that it fails the \indexsee
command — but is OK for the \indexAlso
command — when the first argument has the form
alfatxt@$alfamath$
(for alphabetizing math expression properly in the index).
% File indexdoc2.tex
\documentclass{memoir}
\newcommand{\idxmark}[1]{{\let\gobbleone\relax\markboth{#1}{#1}}#1}
\makepagestyle{index}
\makeheadrule{index}{\textwidth}{\normalrulethickness}
\makeevenhead{index}{\rightmark}{}{\leftmark}
\makeoddhead{index}{\rightmark}{}{\leftmark}
\makeevenfoot{index}{}{\thepage}{}
\makeoddfoot{index}{}{\thepage}{}
\let\oldindex\index
\renewcommand{\index}[1]{\def\exptoindex{#1}\expandafter\oldindex\expandafter{\exptoindex}}
\newcommand\gobbleone[1]{}
\newcommand{\seeonly}[2]{\, (\emph{\seename} #1)}
\newcommand{\indexsee}[2]{\index{#1@#1\protect\gobbleone|seeonly{#2}}}
\newcommand{\Also}[2]{\unskip\emph{See also} #1}
\newcommand{\indexAlso}[2]{\index{#1!zzzz@\protect\gobbleone|Also{#2}}}
\begin{filecontents}{indexdoc2.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 "
\end{filecontents}
\makeindex
\begin{document}
This is some text\indexsee{text}{verbiage}. Which is a synonym for verbiage\index{verbiage}.
$\pi$\index{pi@$\pi$ (math constant)} % OK
$\rho$ \indexsee{$\rho$}{density} % OK
$\sigma$ \indexsee{sigma@$\sigma$}{conductivity} % NO entry in index!
$\mu$ \indexAlso{$\mu$}{magnetic moment} % OK
$\alpha$ \indexAlso{alpha@$\alpha$}{angular acceleration} % OK !
\backmatter
\pagestyle{index}
\printindex
\end{document}