Page LayoutNested footnotes

Information and discussion about page layout specific issues (e.g. header and footer lines, page formats, page numbers).
Post Reply
user001
Posts: 2
Joined: Mon Dec 19, 2011 10:21 am

Nested footnotes

Post by user001 »

Hallo. I had an issue with correct numbering of nested footnotes in LaTeX, such as shown below:
footnote_misnumbering.png
footnote_misnumbering.png (13.79 KiB) Viewed 3509 times
This issue was resolved, but only in a manner which conflicted with the hyperref package. This conflict is shown in the below examples.

First is the desired pdflatex output:
MWE_Comment.png
MWE_Comment.png (12.12 KiB) Viewed 3509 times
And second is the actual output:
MWE_noComment.png
MWE_noComment.png (12.39 KiB) Viewed 3509 times
These outputs were generated from the following code without (top output) or with (bottom output) inclusion of the hyperref package.

Code: Select all

\documentclass[10pt]{article}

% comment the below line to resolve the footnote numbering problem
\usepackage[colorlinks=true,urlcolor=red,hyperfootnotes=false]{hyperref}

% solution proposed by Werner (begin)
\usepackage{letltxmacro}
\newcounter{fnmarkcntr}\newcounter{fntextcntr}
\makeatletter
\renewcommand{\footnotemark}{%
   \@ifnextchar[\@xfootnotemark
     {\stepcounter{fnmarkcntr}%
      \refstepcounter{footnote}\label{footnotemark\thefnmarkcntr}%
      \protected@xdef\@thefnmark{\thefootnote}%
      \@footnotemark}}
\makeatother
\LetLtxMacro{\oldfootnotetext}{\footnotetext}
\renewcommand{\footnotetext}[1]{%
  \stepcounter{fntextcntr}%
  \oldfootnotetext[\ref{footnotemark\thefntextcntr}]{#1}
}
% solution proposed by Werner (end)

\begin{document}
This text has a footnote\footnote%
{Which contains a sub-footnote\footnotemark}
\footnotetext{This footnote should be labeled `2'}
\end{document}
Could someone please help me to generate the desired output in a manner that is compatible with the hyperref package? Thank you very much.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Nested footnotes

Post by kaiserkarl13 »

The "solution" you posted seems unnecessary. I get your example to work just fine without the extra packages and redefinitions. Observe:

Code: Select all

\documentclass[10pt]{article}

% comment the below line to resolve the footnote numbering problem
\usepackage[colorlinks=true,urlcolor=red,hyperfootnotes=false]{hyperref}

\begin{document}
This text has a footnote\footnote%
{Which contains a sub-footnote\protect\footnotemark}
\footnotetext{This footnote should be labeled `2'}
\end{document}
On my machine, it works fine. You might be having issues with minipages: the minipage environment redefines \thefootnote inside so it uses a, b, c, and uses mpfootnote instead of footnote for numbering. This means \footnotemark (which is not similarly redefined) won't have the correct default numbering. You can specify the number like this: \footnotemark[2] ... \footnotetext[2]{Text.}.

Incidentally, your original code doesn't process either unless you ignore the errors. Once the .aux file has been generated, it seems fine, but until then it looks for a non-existent number. So perhaps the moral of this post should be, "don't ignore errors!"
user001
Posts: 2
Joined: Mon Dec 19, 2011 10:21 am

Nested footnotes

Post by user001 »

Sorry, in the interest of posting a succinct MWE, I realize now that I made it too simple.

If you add a second footnote mark as below, the numbering won't work without the posted solution:

Code: Select all

\begin{document}
This text has a footnote\footnote%
{Which contains two sub-footnote\footnotemark\footnotemark}
\footnotetext{This footnote should be labeled `2'}
\footnotetext{This footnote should be labeled `3'}
\end{document}
kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

Nested footnotes

Post by kaiserkarl13 »

You have to give LaTeX some help---you give it two \footnotetext commands in a row, so it uses the current value of the footnote counter when generating numbers. This will work for your example:

Code: Select all

\documentclass[12pt]{article}

% comment the below line to resolve the footnote numbering problem
\usepackage[colorlinks=true,urlcolor=red,hyperfootnotes=true]{hyperref}

\begin{document}
This text has a footnote\footnote%
{Here is a footnote within the footnote\footnotemark.  And here is another
one.\footnotemark}
\footnotetext[2]{This footnote should be labeled `2'}
\footnotetext{This footnote should be labeled `3'}
\end{document}
A slightly more robust way is like this:

Code: Select all

\documentclass[12pt]{article}

% comment the below line to resolve the footnote numbering problem
\usepackage[colorlinks=true,urlcolor=red,hyperfootnotes=true]{hyperref}
\newcounter{prevfn}

\begin{document}
This text has a footnote\footnote%
{Here is a footnote within the footnote\footnotemark.  And here is another
one.\footnotemark}
\setcounter{prevfn}{\value{footnote}}
\addtocounter{prevfn}{-1}
\footnotetext[\value{prevfn}]{This footnote should be labeled `2'}
\footnotetext{This footnote should be labeled `3'}
\end{document}
I say "slightly" because it still requires you to know how many nested footnotes you have. It does not, however, require you to know the value off-hand.
Post Reply