5

The manual of Makeindex states:

In some indexes, certain page numbers are specially formatted—for example, an italic page number may indicate the primary reference, and an n after a page number may denote that the item appears in a footnote on that page. MakeIndex makes it easy to format an individual page number any way you want.

If I apply this to my file were persons appear in the text and in the notes on the same page, this MWE:

\documentclass{scrartcl} 
\usepackage[T1]{fontenc} 
\usepackage[ngerman]{babel} 
\usepackage{makeidx} 
\makeindex 

\newcommand{\nn}[1]{#1n}

\begin{document} 

bla\index{Lahm} blablab\index{Lahm|nn} 

\newpage

bla\index{Lahm|nn} blablab

\printindex 

\end{document}

has an undesired index-output:

 Lahm, 1, 1, 2n

In fact it should be

 Lahm, 1, 1n, 2n

The reason as can be seen in the .ind-file:

\begin{theindex}

  \item Lahm, 1, \nn{1, 2}

\end{theindex}

It groups the two \nn-references. Of course this is not visible in the output. How can I avoid this?

(B.t.w. the .ilg file states:

-- Conflicting entries: multiple encaps for the same page under same key.

)

Upon further research it appears to me that this is a problem of the page range. Makeindex groups two pages with "," and one has to use an .ist file to change suffix_2p .

  • When writing this I came up with a workaround, though it is not the desired one: \newcommand{\nn}[1]{(#1)} thus making the parenthesis visible – Martin Mueller Mar 30 '17 at 11:43
3

You could re-write the \nn command so that it can handle a comma-separated list:

\usepackage{etoolbox}
\newcounter{notereferencecount}
\newcommand{\nn}[1]{%
  \setcounter{notereferencecount}{0}%
  \renewcommand{\do}[1]{%
    \ifnumequal{\value{notereferencecount}}{0}
      {##1n}
      {, ##1n}%
    \stepcounter{notereferencecount}}%
  \docsvlist{#1}}

Gives (I added a few more pages to make sure it did what I thought it would do!)

Screenshot showing index

While the .ind file reads

  \item Lahm, 1, \nn{1, 2}, 3, \nn{4}
3

A different implementation of Paul Stanley’s idea.

\documentclass{scrartcl} 
\usepackage[T1]{fontenc} 
\usepackage[ngerman]{babel} 
\usepackage{makeidx}
\usepackage{xparse}

\makeindex 

\ExplSyntaxOn
\NewDocumentCommand{\nn}{m}
 {
  % split the argument at commas
  \seq_set_split:Nnn \l_martin_nn_in_seq { , } { #1 }
  % add a trailing n to each item
  \seq_set_map:NNn \l_martin_nn_out_seq \l_martin_nn_in_seq { ##1n }
  % output the items separated, if necessary, by "comma space"
  \seq_use:Nn \l_martin_nn_out_seq {,~}
 }
\seq_new:N \l_martin_nn_in_seq
\seq_new:N \l_martin_nn_out_seq
\ExplSyntaxOff

\begin{document} 

bla\index{Lahm} blablab\index{Lahm|nn}

bla\index{A} bla\index{A|nn}

bla\index{B} bla\index{B|nn}

\newpage

bla\index{Lahm|nn} blablab

bla\index{B|nn}

\newpage

bla\index{B|nn}

\printindex 

\end{document}

enter image description here

  • Both solution seem to work fine. Is there a reason why one should prefer one to the other? – Martin Mueller Mar 30 '17 at 13:30
  • 1
    Not really ... except anything made by egreg is likely to be better than anything made by me! (But @egreg I don't agree with the use of an unbreakable space after a comma ...) – Paul Stanley Mar 30 '17 at 14:51
  • @PaulStanley It's not an unbreakable space, but a normal one; we're in an expl3 context. – egreg Mar 30 '17 at 15:18
  • 1
    Ah. This just proves why your answer is likely to be better! (I had forgotten about the sensible approach to whitespace in expl3). More shame. – Paul Stanley Mar 30 '17 at 15:20

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.