LaTeX forum ⇒ Page LayoutNested footnotes

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

Nested footnotes

Postby user001 » Mon Dec 19, 2011 10:37 am

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 1683 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 1683 times


And second is the actual output:
MWE_noComment.png
MWE_noComment.png (12.39 KiB) Viewed 1683 times


These outputs were generated from the following code without (top output) or with (bottom output) inclusion of the hyperref package.

  1. \documentclass[10pt]{article}
  2.  
  3. % comment the below line to resolve the footnote numbering problem
  4. \usepackage[colorlinks=true,urlcolor=red,hyperfootnotes=false]{hyperref}
  5.  
  6. % solution proposed by Werner (begin)
  7. \usepackage{letltxmacro}
  8. \newcounter{fnmarkcntr}\newcounter{fntextcntr}
  9. \makeatletter
  10. \renewcommand{\footnotemark}{%
  11. \@ifnextchar[\@xfootnotemark
  12. {\stepcounter{fnmarkcntr}%
  13. \refstepcounter{footnote}\label{footnotemark\thefnmarkcntr}%
  14. \protected@xdef\@thefnmark{\thefootnote}%
  15. \@footnotemark}}
  16. \makeatother
  17. \LetLtxMacro{\oldfootnotetext}{\footnotetext}
  18. \renewcommand{\footnotetext}[1]{%
  19. \stepcounter{fntextcntr}%
  20. \oldfootnotetext[\ref{footnotemark\thefntextcntr}]{#1}
  21. }
  22. % solution proposed by Werner (end)
  23.  
  24. \begin{document}
  25. This text has a footnote\footnote%
  26. {Which contains a sub-footnote\footnotemark}
  27. \footnotetext{This footnote should be labeled `2'}
  28. \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.

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

Postby kaiserkarl13 » Tue Dec 20, 2011 9:01 pm

The "solution" you posted seems unnecessary. I get your example to work just fine without the extra packages and redefinitions. Observe:
  1. \documentclass[10pt]{article}
  2.  
  3. % comment the below line to resolve the footnote numbering problem
  4. \usepackage[colorlinks=true,urlcolor=red,hyperfootnotes=false]{hyperref}
  5.  
  6. \begin{document}
  7. This text has a footnote\footnote%
  8. {Which contains a sub-footnote\protect\footnotemark}
  9. \footnotetext{This footnote should be labeled `2'}
  10. \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

Postby user001 » Wed Dec 21, 2011 5:10 am

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:

  1. \begin{document}
  2. This text has a footnote\footnote%
  3. {Which contains two sub-footnote\footnotemark\footnotemark}
  4. \footnotetext{This footnote should be labeled `2'}
  5. \footnotetext{This footnote should be labeled `3'}
  6. \end{document}

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

Postby kaiserkarl13 » Fri Jan 06, 2012 1:22 am

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:
  1. \documentclass[12pt]{article}
  2.  
  3. % comment the below line to resolve the footnote numbering problem
  4. \usepackage[colorlinks=true,urlcolor=red,hyperfootnotes=true]{hyperref}
  5.  
  6. \begin{document}
  7. This text has a footnote\footnote%
  8. {Here is a footnote within the footnote\footnotemark. And here is another
  9. one.\footnotemark}
  10. \footnotetext[2]{This footnote should be labeled `2'}
  11. \footnotetext{This footnote should be labeled `3'}
  12. \end{document}


A slightly more robust way is like this:
  1. \documentclass[12pt]{article}
  2.  
  3. % comment the below line to resolve the footnote numbering problem
  4. \usepackage[colorlinks=true,urlcolor=red,hyperfootnotes=true]{hyperref}
  5. \newcounter{prevfn}
  6.  
  7. \begin{document}
  8. This text has a footnote\footnote%
  9. {Here is a footnote within the footnote\footnotemark. And here is another
  10. one.\footnotemark}
  11. \setcounter{prevfn}{\value{footnote}}
  12. \addtocounter{prevfn}{-1}
  13. \footnotetext[\value{prevfn}]{This footnote should be labeled `2'}
  14. \footnotetext{This footnote should be labeled `3'}
  15. \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.


Return to “Page Layout”

Who is online

Users browsing this forum: No registered users and 3 guests