0

This is another (I hope final) follow-up to the questions Can one truncate page ranges in index using splitidx? and Page range truncation with imakeidx. I think I now know all the requirements about the index I'm writing. House style from OUP requires page range truncation in entries, sub-entries, and sub-sub-entries. This was achieved by egreg's answers to the second of the questions referenced. However, I also make cross-references in the index. Now, when I add a see and a seealso index entries to the mwe from egreg:

 \begin{filecontents*}{subjind.ist}
    delim_0 ", \\checkrange{"
    delim_1 ", \\checkrange{"
    delim_2 ", \\checkrange{"
    delim_t "}"
    \end{filecontents*}

    \documentclass{book}
    \usepackage{xparse}
    \usepackage{imakeidx}

    \makeindex[title=Subject Index,options=-s subjind]

    \ExplSyntaxOn
    \NewDocumentCommand{\checkrange}{m}
     {
      \seq_set_from_clist:Nn \l__ssind_in_seq { #1 }
      \seq_set_map:NNn \l__ssind_out_seq \l__ssind_in_seq { \checkrangeaux{##1} }
      \seq_use:Nn \l__ssind_out_seq {,~}
     }
    \seq_new:N \l__ssind_in_seq
    \seq_new:N \l__ssind_out_seq

    \NewDocumentCommand{\checkrangeaux}{>{\SplitArgument{1}{--}}m}
     {
      \formatrange#1
     }
    \NewDocumentCommand{\formatrange}{mm}
     {
      \IfNoValueTF { #2 }
       { % no --, it's not a range
        #1
       }
       { % it's a range
        \egreg_range:nn { #1 } { #2 }
       }
     }

    \bool_new:N \l__egreg_range_compare_bool

    \cs_new_protected:Nn \egreg_range:nn
     {
      % print the start number
      #1--
      \int_compare:nNnTF { \str_count:n { #1 } } = { \str_count:n { #2 } }
       {% same number of digits, remove equal ones at the start
        \__egreg_range_compare:nn { #1 } { #2 }
       }
       {% different number of digits, print both
        #2
       }
     }
    \cs_new_protected:Nn \__egreg_range_compare:nn
     {
      \bool_set_true:N \l__egreg_range_compare_bool
      % do a loop on the digits in the first number
      \int_step_inline:nn { \str_count:n { #1 } }
       {
        \bool_if:NTF \l__egreg_range_compare_bool
         {
          % if the digits coincide, print nothing
          \str_if_eq:eeF { \str_item:nn { #1 } { ##1 } } { \str_item:nn { #2 } { ##1 } }
           {
            \str_item:nn { #2 } { ##1 }
            % at the first differing digit, don't compare any longer
            \bool_set_false:N \l__egreg_range_compare_bool
           }
         }
         { \str_item:nn { #2 } { ##1 } }
       }
     }
    \ExplSyntaxOff

    \begin{document}
    \setcounter{page}{95}\index{Topic0|(}Text\newpage
    \setcounter{page}{101}\index{Topic0|)}Text\newpage
    \setcounter{page}{124}\index{Topic1|(}\index{Topic2|(}Text\newpage
    \setcounter{page}{126}\index{Topic1|)}Text\newpage
    \setcounter{page}{134}\index{Topic2|)}Text\newpage
    \setcounter{page}{135}\index{Topic0!sub0|(}Text\newpage
    \setcounter{page}{136}\index{Topic0!sub0!subsub0|(}Text\newpage
    \setcounter{page}{139}\index{Topic0!sub0!subsub0|)}Text\newpage
    \setcounter{page}{140}\index{Topic0!sub0|)}Text\newpage
    \setcounter{page}{141}\index{Topic0}Text\newpage
    \index{Topic0}Text\newpage
    \index{Topic0}Text    
    \index{Topic3|see{Topic0}}
    \index{Topic4|seealso{ATopic1}}
    \printindex
    \end{document}

pdflatex hangs altogether. I'm running pdflatex from TeXworks, using MikTeX on Windows 10.

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.