1

Consider the subsequent Index which is generated by the following code:

\documentclass[12pt]{book}
\usepackage{imakeidx}
\makeindex
\usepackage{idxlayout}

    \begin{document}
    \large
    \par Here are some words.\index{Person, Key@{\scshape{Person, Key}}! In the beginning {\bf EVENT 1}}
    \newpage abc \newpage abc \newpage abc
    \par More words.\index{Person, Key@{\scshape{Person, Key}}! This is followed by {\bf EVENT 2}}
    \newpage abc \newpage abc \newpage abc \newpage abc \newpage abc
    \par More words.\index{Person, Key@{\scshape{Person, Key}}! Later, we have {\bf EVENT 3}}
    \newpage abc \newpage abc \newpage abc \newpage abc \newpage abc \newpage abc \newpage abc
    \par More words.\index{Person, Key@{\scshape{Person, Key}}! Continuing with {\bf EVENT 4}}
    \newpage abc
    \par More words.\index{Person, Key@{\scshape{Person, Key}}! So follows {\bf EVENT 5}}
    \newpage abc
    \par More words.\index{Person, Key@{\scshape{Person, Key}}! Later comes {\bf EVENT 6}}
    \newpage abc \newpage abc \newpage abc
    \par More words.\index{Person, Key@{\scshape{Person, Key}}! Followed by {\bf EVENT 7}}
    \newpage abc \newpage abc \newpage abc \newpage abc
    \par More words.\index{Person, Key@{\scshape{Person, Key}}! Then comes {\bf EVENT 8}}
    \newpage abc \newpage abc \newpage abc \newpage abc \newpage abc \newpage abc \newpage abc
    \par More words.\index{Person, Key@{\scshape{Person, Key}}! Shortly thereafter Event 8 comes {\bf EVENT 9}}
    \newpage abc 
    \par More words.\index{Person, Key@{\scshape{Person, Key}}! The end: {\bf EVENT 10}}
      
    
    \idxlayout{columns=1}
        \renewcommand\indexname{\color{RoyalRed}Index}
    %\renewcommand\indexname{Index.}
        \printindex
    \end{document}

enter image description here

What I would like to do, is to simply arrange the sub-entries in chronological order so that the sub-entry containing EVENT 1 comes first, followed by the sub-entry containing EVENT 2, and so forth, all the way up to the one that contains EVENT 10. This way, also, the associated pages will appear in ascending order.

How may I accomplish this? Thank you.

2

You can use something like

\index{Person, Key@\textsc{Person, Key}!\NOOP{<number>}<description>}

where <number> is autogenerated and \NOOP is a macro that does nothing, but is recorded in the .idx file. The number is padded to five digits with zeros, so it will be used for sorting.

Any “Person, Key” pair defines a counter that's incremented at each usage. Of course, we'll use a macro for automating the process.

\documentclass[12pt]{book}
%\usepackage{xparse} % not needed with LaTeX 2020-10-01 or later
\usepackage{imakeidx}
\makeindex[columns=1]

\ExplSyntaxOn
\NewDocumentCommand{\NOOP}{m}{}

\NewDocumentCommand{\personevent}{mm}
 {
  \mlchristians_personevent:nn { #1 } { #2 }
 }

\cs_new_protected:Nn \mlchristians_personevent:nn
 {
  \int_if_exist:cF { g_mlchristians_personevent_#1_int }
   {
    \int_new:c { g_mlchristians_personevent_#1_int }
   }
  \int_gincr:c { g_mlchristians_personevent_#1_int }
  % emit the index entry
  \index{ #1 @ \textsc{#1}! \NOOP { \__mlchristians_pad:n { #1 } } #2 }
 }

\cs_new:Nn \__mlchristians_pad:n
 {
  \prg_replicate:nn { 5 - \tl_count:v { g_mlchristians_personevent_#1_int } } { 0 }
  \int_use:c { g_mlchristians_personevent_#1_int }
 }
\cs_generate_variant:Nn \tl_count:n { v }

\ExplSyntaxOff

\begin{document}

Here are some words.\personevent{Person, Key}{In the beginning \textbf{EVENT 1}}

\newpage abc \newpage abc \newpage abc

More words.\personevent{Person, Key}{This is followed by \textbf{EVENT 2}}
\newpage abc \newpage abc \newpage abc \newpage abc \newpage abc

More words.\personevent{Person, Key}{Later, we have \textbf{EVENT 3}}

\newpage abc \newpage abc \newpage abc \newpage abc \newpage abc \newpage abc \newpage abc

More words.\personevent{Person, Key}{Continuing with \textbf{EVENT 4}}

\newpage abc

More words.\personevent{Person, Key}{So follows \textbf{EVENT 5}}

\newpage abc

More words.\personevent{Person, Key}{Later comes \textbf{EVENT 6}}

\newpage abc \newpage abc \newpage abc

More words.\personevent{Person, Key}{Followed by \textbf{EVENT 7}}

\newpage abc \newpage abc \newpage abc \newpage abc

More words.\personevent{Person, Key}{Then comes \textbf{EVENT 8}}

\newpage abc \newpage abc \newpage abc \newpage abc \newpage abc \newpage abc \newpage abc

More words.\personevent{Person, Key}{Shortly thereafter Event 8 comes \textbf{EVENT 9}}

\newpage abc 

More words.\personevent{Person, Key}{The end: \textbf{EVENT 10}}

\printindex

\end{document}

Please, note that \textsc{text} is the correct syntax instead of {\scshape{text}} and that \bf has been deprecated for 25 years.

enter image description here

The .idx file is

\indexentry{Person, Key@\textsc  {Person, Key}!\NOOP {00001}In the beginning \textbf  {EVENT 1}}{1}
\indexentry{Person, Key@\textsc  {Person, Key}!\NOOP {00002}This is followed by \textbf  {EVENT 2}}{4}
\indexentry{Person, Key@\textsc  {Person, Key}!\NOOP {00003}Later, we have \textbf  {EVENT 3}}{9}
\indexentry{Person, Key@\textsc  {Person, Key}!\NOOP {00004}Continuing with \textbf  {EVENT 4}}{16}
\indexentry{Person, Key@\textsc  {Person, Key}!\NOOP {00005}So follows \textbf  {EVENT 5}}{17}
\indexentry{Person, Key@\textsc  {Person, Key}!\NOOP {00006}Later comes \textbf  {EVENT 6}}{18}
\indexentry{Person, Key@\textsc  {Person, Key}!\NOOP {00007}Followed by \textbf  {EVENT 7}}{21}
\indexentry{Person, Key@\textsc  {Person, Key}!\NOOP {00008}Then comes \textbf  {EVENT 8}}{25}
\indexentry{Person, Key@\textsc  {Person, Key}!\NOOP {00009}Shortly thereafter Event 8 comes \textbf  {EVENT 9}}{32}
\indexentry{Person, Key@\textsc  {Person, Key}!\NOOP {00010}The end: \textbf  {EVENT 10}}{33}

The .ind file is

\begin{theindex}

  \item \textsc  {Person, Key}
    \subitem \NOOP {00001}In the beginning \textbf  {EVENT 1}, 1
    \subitem \NOOP {00002}This is followed by \textbf  {EVENT 2}, 4
    \subitem \NOOP {00003}Later, we have \textbf  {EVENT 3}, 9
    \subitem \NOOP {00004}Continuing with \textbf  {EVENT 4}, 16
    \subitem \NOOP {00005}So follows \textbf  {EVENT 5}, 17
    \subitem \NOOP {00006}Later comes \textbf  {EVENT 6}, 18
    \subitem \NOOP {00007}Followed by \textbf  {EVENT 7}, 21
    \subitem \NOOP {00008}Then comes \textbf  {EVENT 8}, 25
    \subitem \NOOP {00009}Shortly thereafter Event 8 comes \textbf  {EVENT 9}, 
        32
    \subitem \NOOP {00010}The end: \textbf  {EVENT 10}, 33

\end{theindex}
1
  • This works perfectly when the index sub-entry occurs on one page in the document. However, if I want the citation spans a set of pages, say 6-9, then using, for example, \personevent{Person, Key}{citation}|(} followed later in the document by \personevent{Person, Key}{citation}|)} would print out two separate sub-entries: Person, Key, 6 followed underneath by Person, Key, 9. Is there a way to print one sub-entry indicating a span of pages, such as the way noted which works for \index? Many thanks again for all your help. – mlchristians Nov 14 '20 at 19:13

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.