2

I am using revtex4-1 in a document with many short subsections (2-3 per page). Rather than the page number, I would like my index to refer to the section and subsection (i.e. "example, 2.1" for the item 'example' in section 2, subsection 1). The code below does everything I want, except there is no "." between the section and subsection numbers:

\documentclass[rmp]{revtex4-1}
\usepackage{makeidx}

\makeatletter
  \def\@wrindex#1{%
    \protected@write\@indexfile{}%
      {\string\indexentry{#1}{\thesubsection}}
    \endgroup
  \@esphack}
\makeindex

\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\arabic{section}\arabic{subsection}}

\begin{document}

\section{Section} This is Section 1
\subsection{Subsection} This is Subsection 1.1 \index{My Subsection}

\printindex
\end{document}

If I instead do \renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}, then the index will not print. I have seen workarounds such as this one, but this method only works for up to 9 subsections. How can I have the index print section.subsection?

4
  • makeindex does not understand the . in the index entry
    – user31729
    Feb 8 '17 at 18:11
  • See also tex.stackexchange.com/questions/298519/…
    – user31729
    Feb 8 '17 at 18:14
  • That makes sense. Is there a way to either change \thesubsection into a form that makeindex does understand? Or a way to change what makeindex can understand?
    – mtutor
    Feb 8 '17 at 18:15
  • See my answer below
    – user31729
    Feb 8 '17 at 18:27
2

The page_compositor key is responsible how makeindex interpretes the 'numbers' it reads and sorts accordingly.

By defining a new index style file, say subsection.ist this can be used to change the key to ., for example.

\documentclass[rmp]{revtex4-1}
\usepackage{makeidx}

\makeatletter
  \def\@wrindex#1{%
    \protected@write\@indexfile{}%
      {\string\indexentry{#1}{\thesubsection}}
    \endgroup
  \@esphack}
\makeindex

\renewcommand{\thesection}{\arabic{section}}
\renewcommand{\thesubsection}{\arabic{section}.\arabic{subsection}}


\begin{filecontents}{subsection.ist}
page_precedence "nrRAa"
page_compositor "."
\end{filecontents}


\usepackage{pgffor}



\begin{document}

\section{Section} This is Section 1
\foreach \x in {1,...,20} {%
\clearpage
\subsection{Subsection \x} \index{My Subsection}
}

\section{Section} This is Section 1
\foreach \x in {1,...,20} {%
\clearpage
\subsection{Subsection \x} \index{My Subsection}
}


\printindex
\end{document}

Call makeindex -s subsection.ist foo, if foo.tex is the name of the .tex document.

enter image description here

1
  • 1
    Please note that makeindex is limited in it's parsing and sorting features. xindy is by far more elaborate
    – user31729
    Feb 8 '17 at 18:31

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.