0

Using the MakeIndex (via memoir class), I would like to index a page note by referencing the page number (in the Notes section where the note appears) as well as the note number. Attempts to include \thepagenote somewhere references the number of the last page note in the document.

For example, given the MWE below that has 4 page notes, attempts to index the first page note ends up with an entry in the index referencing the last (fourth) page note.

I noticed that the .ind file still has \thepagenote while page numbers are hardcoded after all processing is done, e.g.

\item First pagenote, \ipn{\thepagenote}{5}.

so I guess I have to figure out some way of expanding \thepagenote sooner. This answer seems closely related, but porting that solution directly did not seem to produce expected results -- a number for \thepagenote is hardcoded into the .ind file, but it is still the last page note.

enter image description here

MWE

\documentclass{memoir}
\usepackage{lipsum}

\newcommand{\ipn}[2]{PAGE #2 NOTE #1}

\makeindex
\makepagenote

\begin{document}
\mainmatter
\part{Part}
\chapter{Chapter}
\index{1st index term}%
\lipsum[1]\pagenote{First pagenote\index{2nd index term|ipn{\thepagenote}}}
\lipsum[2]\pagenote{Second pagenote}
\lipsum[3]\pagenote{Third pagenote}
\lipsum[4]\pagenote{Fourth pagenote}
\backmatter
\printpagenotes
\printindex
\end{document}

MWE like referenced answer

https://tex.stackexchange.com/a/282610/47128

\documentclass{memoir}

\usepackage{lipsum}
\usepackage{hyperref}

\newcommand\pn[2]{\hyperpage{#2}n#1}

\makeatletter
\let\if@nopgnote\iffalse % just for the example
\newcommand{\is}[1]{%
  \if@nopgnote
    \index{#1}%
  \else
    \edef\tempnumber{\thepagenote}%
    \expandafter\pagenoteindex\expandafter{\tempnumber}{#1}%
  \fi
}
\makeatother
\newcommand{\pagenoteindex}[2]{\index{#2|pn{#1}}}

\makeindex
\makepagenote

\begin{document}
\mainmatter
\part{part}
\chapter{chapter}
\lipsum[1]\pagenote{First pagenote}
\lipsum[2]\pagenote{Second pagenote.\is{inside second pagenote}}
\lipsum[3]\pagenote{Third pagenote.}
\backmatter
\printpagenotes
\printindex
\end{document}
1

1 Answer 1

0

I somewhat blindly combined the answers I referenced previously:

And the result is below. The changes to the memoir command \m@m@wrpnote could maybe be condensed with \xpatchcmd but I'm not familiar with that. Additions to the original command are marked with BEGIN ADDITIONS.

\documentclass{memoir}

\usepackage{lipsum}
\usepackage{hyperref}

\newcommand\pn[2]{\hyperpage{#2}n#1}

\makeatletter
\let\if@noftnote\iffalse % just for the example
\newcommand{\is}[1]{%
  \edef\tempnumber{\thepnotemirror}%
  \expandafter\pagenoteindex\expandafter{\tempnumber}{#1}%
}
\makeatother
\newcommand{\pagenoteindex}[2]{\index{#2|pn{#1}}}


\newcounter{pnotemirror}
\makeatletter
\renewcommand{\m@m@wrpnote}[2][]{%
  \mem@pn@lastkern=\lastkern%
  \refstepcounter{pagenoteshadow}%
  \ifm@mpnpageopt%
    \phantomsection%
    \label{pagenote\thepagenoteshadow-\thesheetsequence}%
  \fi%
  \if\mem@pn@step%
    \@ifmtarg{#1}{% BEGIN ADDITION
      \ifnumequal{\value{pagenote}}{0}%
      {\m@m@pnwrite\@notefile{}{\string\setcounter{pnotemirror}{0}}}%
      {}% END ADDITION
      \refstepcounter{pagenote}%
      % this enables the ^{1,2} feature
      \ifdim\mem@pn@lastkern=\multiplefootnotemarker%
        \m@mmf@prepare% rerun
      \fi%
      \mem@pn@multiple@marker{\notenumintext{\thepagenote}}%
    }{\m@mmf@prepare}%
  \fi%
  \ifm@mpn@new@chap%
    \global\m@mpn@new@chapfalse%
    \addtonotes{\string\pagenotesubhead{\@chapapp}{\thechapter}{\pnchap}}%
  \fi%
  \ifm@mpn@new@schap%
    \global\m@mpn@new@schapfalse%
    \addtonotes{\string\pagenotesubheadstarred{\@chapapp}{}{\pnschap}}%
  \fi%
  \m@m@pnwrite\@notefile{}%
    {% BEGIN ADDITION
      \string\refstepcounter{pnotemirror}% END ADDITION
      \string\startnoteentry{\thepagenote}}%
  \m@m@pnwrited\@notefile{}{{#1}}%
  \m@m@pnwrite\@notefile{}%
    {{pagenote\thepagenoteshadow-\thesheetsequence}}%
  \m@m@pnwrite@fourtharg{#1}%
  \begingroup%
    \newlinechar='40%
    \m@m@pnwrited\@notefile{}{#2}%
  \endgroup%
  \m@m@pnwrite\@notefile{}%
  {\string\endnoteentry}%
  \endgroup%
  \@esphack}
\makeatother

\makeindex
\makepagenote

\begin{document}
\mainmatter
\part{Part}
\chapter{Chapter}
\index{Some index term}%
\lipsum[1]\pagenote{Ch. 1, First pagenote}
\lipsum[2]\pagenote{Ch. 1, Second pagenote\is{Ch. 1, Second pagenote}}
\lipsum[3]\pagenote{Ch. 1, Third pagenote}
\lipsum[4]\pagenote{Ch. 1, Fourth pagenote}
\chapter{Chapter}
\lipsum[5]\pagenote{Ch. 2, First pagenote}
\lipsum[6]\pagenote{Ch. 2, Second pagenote}
\lipsum[7]\pagenote{Ch. 2, Third pagenote\is{Ch. 2, Third pagenote}}
\backmatter
\printpagenotes
\printindex
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .