Nested Footnotes + Hyperref

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

% 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.

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

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.

-
As you chose to accept Werner's answer to the original question and to ask a follow-up question with regard to the hyperref incompatibility, it seems appropriate that you move the respective MWE ("Edit 2") to this new question. – lockstep Dec 19 '11 at 0:06
Perhaps also remove the "new" MWE from the original question. – lockstep Dec 19 '11 at 0:20
BTW, your MWE results in an error even if I comment out hyperref. – lockstep Dec 19 '11 at 0:22
Yes, that error is because I included a hyperlink (www.google.com), which is no longer recognized if the hyperref package is omitted. For simplicity, I will remove that -- it does not add anything substantive to the example. – user001 Dec 19 '11 at 0:24
@user001: I removed the automated CW from the question again. – Martin Scharrer Dec 20 '11 at 14:21

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.)

-
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