4

Footnoting a footnote can be performed by placing a \footnotemark within a footnote, followed later by the accompanying \footnotetext. However, only a single footnote can be placed within a footnote because of footnote counter desynchronization. This problem was solved, but the solution turned out to be incompatible with the \hyperref package (despite disabling hyperfootnotes in the \usepackage{hyperref} declaration).

The below MWE demonstrates this incompatibility.

    \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}

Shown below is the output of the above code with the \usepackage{hyperref} command removed.

enter image description here

Shown below is the erroneous output of the above code with the \usepackage{hyperref} command included.

enter image description here

Note that inclusion of the hyperref package results in incorrect numbering of the nested footnote (0 instead of 2) and placement of an undesired (albeit correctly numbered) footnotemark in the body of the text (it should be placed in the footnote). This undesired footnotemark has been erroneously hyperlinked.

user001
  • 7,964

2 Answers2

2

You might want to (ab)use the tablefootnote package:

\documentclass{article}
\usepackage{tablefootnote}[2011/11/26]% v1.0e

\makeatletter
\newcommand{\spewnotes}{%
\tfn@tablefootnoteprintout%
\global\let\tfn@tablefootnoteprintout\relax%
\gdef\tfn@fnt{0}%
}
\makeatother

\usepackage{hyperref}

\begin{document}
This is a footnote\footnote{Here is a footnote within the footnote%
\tablefootnote{This footnote should be labeled `2'}. %
And here is another one\tablefootnote{This footnote should be labelled `3'}.}%
\spewnotes{}. Text\footnote{Another footnote%
\tablefootnote{This footnote should be labelled `5'}. %
And here is another one\tablefootnote{This footnote should be labelled `6'}}\spewnotes{}.

\newpage

Some text (which is necessary to get two pages,
thus one can choose continuous view of the pdf-file and then check
that the hyperreferences indeed aim to the correct point.

\end{document}

You just need to make sure that there is no page break between '\footnote{...}' and \spewnotes, otherwise the spewed footnotes end at the second page. (And I did not test what happens when you use a table with tablefootnote at the same page as your footnotes to footnotes, but one can deal with that problem in the unlikely case that it does really occur.)

Stephen
  • 14,890
  • 3
    Posting the exact answer twice is discouraged here and will cause the answer to be automatically flagged. Simply adding a comment to the original answer would be better. – Martin Scharrer Dec 20 '11 at 14:22
  • @MartinScharrer: Sorry, had done that at the time when this was CW and the questions both ask for a solution to the same problem, just this question additionally asks for hyperref, thus the one answer answers both questions. I'll include a comment at the other version of the question linking to this answer. (A bit of a complicated situation.) – Stephen Dec 20 '11 at 18:54
0

If you change the \ref in Werner's answer to \getrefnumber from the refcount package it works with hyperref (if hyperfootnote=false isn't passed there are warnings about footnotemark links that lead to nowhere).

\documentclass[10pt]{article}

\usepackage[colorlinks=true,urlcolor=red,hyperfootnotes=false]{hyperref}

% modified solution by Werner (begin) \usepackage{letltxmacro} \usepackage{refcount} \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[\getrefnumber{footnotemark\thefntextcntr}]{#1} } % modified solution 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}

ronno
  • 1,325