4

I am using the memoir class.

In some parts of the page, there are multiple spots that need to be annotated with the same footnote.

Lorem ipsum dolor[1] sit amet, consectetur adipiscing elit[2], sed do eiusmod tempor incididunt ut labore et dolore[1] magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor[1] in reprehenderit in voluptate velit esse cillum dolore[1] eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.


1: See Appendix on dolors.

2: See Appendix on elites.

Currently, I am manually specifying the footnotes, such as ipsum dolor\footnote[1]{See \emph{Appendix on dolors}.} sit amet. Then I have to manually add the other footnote marks: labore et dolore\textsuperscript{1} magna aliqua

But I don't want to manually keep track of what number is what footnote. They get moved around a lot and I keep forgetting. Besides, I shouldn't have to manually keep track of the numbering, Latex should do it for me.

What command can I use to reference the same footnote multiple times, so that the footnotes are automatically numbered?

2

4 Answers 4

5

Using Andrews MWE and adding some Heiko magic:

\documentclass{memoir}
\usepackage[height=30mm]{geometry}%
\usepackage{refcount}
\begin{document}
  One footnote\footnote{A wonderful footnote!\label{foot}}
  and a second one\footnote{A less wonderful footnote!\label{toe}}.

  The last footnote, \ref{foot}, is really nice. I like
  footnote~\ref{foot} more than footnote \ref{toe}. Here is another
  footnote with the first footnote marker\footnotemark[\getrefnumber{foot}]
  and a second footnote with the second foot note
  marker\footnotemark[\getrefnumber{toe}].

\end{document}

The point is that \ref{...} gives number + \hbox{}, thus \footnotemark does not like it as it expects a number.

The solution probably fails if something other than numbers are used to mark footnotes.

Note how the \label have been added inside the footnotes.

5
  • 1
    What is "Heiko magic"?
    – Superbest
    May 27, 2015 at 18:56
  • Also, what happens to this if I get confused and accidentally use \ref{foot} before \footnote{A wonderful footnote!\label{foot}}?
    – Superbest
    May 27, 2015 at 19:01
  • Also, in spite of what you say, looks like \footnotemark[\ref{foot}] worked for me. (I do only intend to use numbers as footnotes, currently)
    – Superbest
    May 27, 2015 at 19:08
  • In fact I've managed to get away with \footref{foot} - but I'm not sure where this command came from, since I have a pretty big preamble.
    – Superbest
    May 27, 2015 at 19:16
  • Heiko wrote the package refcount, he has written many useful packages. Remember for new labels, compile twice then it does not matter where ref is placed it will get the info it needs
    – daleif
    May 27, 2015 at 20:38
3

It really ought to be possible to do what you want using the standard \label and \ref commands, however, this does not work because \footnote does not set \@currentlabel which is what LaTeX uses to "remember" the last label.

The obvious fix is to make \footnote remember the last label used, which it calls \@thefnmark. You can do this using the \apptocmd from the etoolbox package:

\makeatletter
\apptocmd{\@footnotetext}{\def\@currentlabel{\@thefnmark}}{}{}
\makeatother

(It turns out that \@footnotetext is the thing to change.) Here's a full MWE:

enter image description here

together with the accompanying code:

\documentclass{memoir}
\usepackage[height=30mm]{geometry}%
\usepackage{etoolbox}
\makeatletter
\apptocmd{\@footnotetext}{\def\@currentlabel{\@thefnmark}}{}{}
\newcommand\footnoteref[1]{\ifcsmacro{r@#1}{\footnotemark[\ref{#1}]}{$^{??}$}}
\makeatother
\begin{document}
  One footnote\footnote{A wonderful footnote!}\label{foot}
  and a second one\footnote{A less wonderful footnote!}\label{toe}.

  The last footnote, \ref{foot}, is really nice. I like
  footnote~\ref{foot} more than footnote \ref{toe}. Here is another
  footnote with the first footnote marker\footnoteref{foot}
  and a second footnote with the second foot note
  marker\footnoteref{toe}.
\end{document}

Edit The macro \footnoteref is convenient for placing the repeated footnote labels but it is also necessary because without it the code will not compile when you first define a new label, although it will be fine on all subsequent passes. On the first pass, when the labels are not defined, the MWE produces the following:

enter image description here

As @dalief points out, it is better to put the footnote inside \footnote{...} rather than redefining \@footnotemark as I have done above.

5
  • Erh, this does not compile. Isn't the main problem that \footnotemark expects a number, and \ref is not (there are some extra stuff in there). Might be possible to use some of Heikos packages to actually get a number out.
    – daleif
    May 27, 2015 at 7:42
  • Plus the label goes inside the footnote for it to catch the number (like it have always worked).
    – daleif
    May 27, 2015 at 7:55
  • @daleif The problem is that on the first pass the references do not exist and this is what caused the error. I have added the fix. Thanks for pointing out the problem.
    – user30471
    May 27, 2015 at 9:34
  • What is \usepackage[height=30mm]{geometry} for? I'm guessing to make the page shorter so your screenshot is not so big?
    – Superbest
    May 27, 2015 at 19:09
  • @Superbest Yes, that's right, the geometry package is there only for the screenshot.
    – user30471
    May 27, 2015 at 21:08
2

One solution could be the package fixfoot:

MWE

\documentclass[12pt]{memoir}
\usepackage[bmargin=20cm,lmargin=6cm,rmargin=6cm]{geometry}
\usepackage{fixfoot,xspace}
\usepackage[colorlinks]{hyperref}

\DeclareFixedFootnote{\foobar}{Run \texttt{pdflatex} two times.}
\DeclareFixedFootnote*{\foo}{A wonderful footnote!}
\DeclareFixedFootnote*{\baz}{A more wonderful footnote!}

\begin{document}

Compile this twice \foobar. One footnote,\foo and another.\baz 
The last footnote\baz is really nice. I like this footnote\baz 
more than footnote\foo, but check that the PDF is correctly 
generated.\foobar 

\end{document}
1

Since the repeated footnote references are needed after the footnote is created, the \label/\ref system with two LaTeX runs is not really needed. Instead the current value of the footnote counter can be saved in a macro and the macro with the number will become the argument for \footnotemark:

\documentclass{memoir}
\usepackage[height=30mm]{geometry}%

\begin{document}
  Lorem ipsum dolor%
  \footnote{See \emph{Appendix on dolors}}%
  \edef\thefndolors{\the\value{footnote}}
  sit amet, consectetur adipiscing elit%
  \footnote{See \emph{Appendix on elites}},%
  sed do eiusmod tempor incididunt ut labore et
  dolore\footnotemark[\thefndolors] magna aliqua. Ut enim ad minim
  veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex
  ea commodo consequat. Duis aute irure dolor\footnotemark[\thefndolors]
  in reprehenderit in voluptate velit esse cillum
  dolore\footnotemark[\thefndolors] eu fugiat nulla pariatur.
  Excepteur sint occaecat cupidatat non proident, sunt in culpa
  qui officia deserunt mollit anim id est laborum.
\end{document}

Result

You must log in to answer this question.

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