3

I have a document with cleveref and hyperref, both of which I don't want to miss. I need to reuse footnotes using cleveref which works fine thanks to https://tex.stackexchange.com/a/10116. I also want to automatically insert superscript commas between footnotemarks which works fine thanks to https://tex.stackexchange.com/a/71347. Taken separately, both of them work fine. Combined using code from https://tex.stackexchange.com/a/285630/154602, the footnote is duplicated and formatted incorrectly and the superscript comma is missing.

\documentclass{article}
\usepackage{biblatex}
\usepackage[colorlinks]{hyperref}
\usepackage{cleveref} % must be loaded after hyperref

% Source: https://tex.stackexchange.com/a/10116
\crefformat{footnote}{#2\footnotemark[#1]#3}

%\iffalse % without these lines, footnote marks look fine but miss a comma inbetween
% Inspiration: https://tex.stackexchange.com/a/285630/154602 and https://tex.stackexchange.com/a/71347
\let\oldFootnote\footnote
\let\oldFootnotemark\footnotemark
\newcommand\nextToken\relax

\renewcommand\footnote[1]{%
    \oldFootnote{#1}\futurelet\nextToken\isFootnoteOrSimilar}
\renewcommand\footnotemark[1]{%
    \oldFootnotemark{#1}\futurelet\nextToken\isFootnoteOrSimilar}

\newcommand\isFootnoteOrSimilar{%
    \ifx\footnote%
        \nextToken\textsuperscript{,}%
    \else%
        \ifx\footnotemark%
            \nextToken\textsuperscript{,}%
        \fi%
    \fi%
}
%\fi

\textheight=7cm
\begin{document}

Text\footnote{First footnote}\footnote{Second footnote}\footnote{Third footnote} Text\footnote{Fourth footnote} Text

Referencing future footnote\cref{second}. Creating a footnote which will be referenced later\footnote{\label{first}First footnote!}

Creating the previously referenced footnote\footnote{\label{second}Second footnote}, and referencing a previously created footnote\cref{first}.

Footnote followed by referenced footnote\cref{first}\footnote{footnote B}

Referenced footnote followed by new footnote\footnote{footnote C}\cref{second}
\end{document}

The result: enter image description here

How can I make the combination of \footnote and \cref on a footnote look nice, just as when two \footnotes follow each other in the first line of the output?

I think the issue is caused by the fact that when checking \isFootnoteOrSimilar, the \cref is not expanded. The macro expansion of \isFootnoteOrSimilar must be run last, after \cref is fully expanded, but I don't know how to do that.

genodeftest
  • 190
  • 7
  • The problem arises mainly because of the \footnotemark instruction in the argument of \crefformat. Please describe in words how call-outs to cross-referenced footnotes should look like. – Mico Jun 05 '18 at 09:11
  • call-outs to cross-references should look exactly like "ordinary" footnotes generated using \footnote{}, see the first line of the resulting text. I.e. they should be a superscripted hyperlinked number with commas inbetween consecutive call-outs of any footnote type. – genodeftest Jun 05 '18 at 09:19
  • Then what's the purpose of the square brackets in the argument of \crefformat? Are cross-referenced footnote markers supposed to be surrounded by square brackets? Please advise. – Mico Jun 05 '18 at 09:36
  • 1
    I do not want to have these square brackets. I put them there by accident. Thanks for the hint! – genodeftest Jun 05 '18 at 10:52

1 Answers1

2

call-outs to cross-references should look exactly like "ordinary" footnotes generated using \footnote

The following setup may be what you're looking for. Note that you should employ \cref{<footnote-label>} if you want to create a cross-reference that consists of both the item's text string (here: footnote) and the associated (superscripted) number, and you should use \labelcref{<footnote-label>} if you want to create just a superscripted number. In the following example, note the 2 instances of \cref and the 3 instances of \labelcref.

enter image description here

\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage{cleveref} 
\creflabelformat{footnote}{\unskip\textsuperscript{#2#1#3}}

\newcommand\nextToken\relax    
\newcommand\isFootnoteOrSimilar{%
    \ifx\footnote%
        \nextToken\textsuperscript{,}%
    \else%
        \ifx\footnotemark%
            \nextToken\textsuperscript{,}%
    \else%
        \ifx\labelcref%
            \nextToken\textsuperscript{,}%
    \fi\fi\fi%
}

\let\oldFootnote\footnote
\renewcommand\footnote[1]{%
    \oldFootnote{#1}\futurelet\nextToken\isFootnoteOrSimilar}
\let\oldFootnotemark\footnotemark
\renewcommand\footnotemark[1]{%
    \oldFootnotemark{#1}\futurelet\nextToken\isFootnoteOrSimilar}
\let\oldlabelcref\labelcref
\renewcommand\labelcref[1]{%
    \oldlabelcref{#1}\futurelet\nextToken\isFootnoteOrSimilar}

\textheight=5cm
\parindent=0pt
\begin{document}

Create a cross-reference to a future \cref{second}. 

Create a footnote which will be referenced later\footnote{\label{first}First footnote}.

Create an already-referenced footnote\footnote{\label{second}Second footnote}.

Create a cross-reference to an already-created \cref{first}.

\medskip
A new footnote mark, followed by a cross-reference to another footnote:
\footnote{Footnote C\label{third}}\labelcref{first}

\medskip
A cross-reference to a footnote, followed by a new footnote mark, followed by a cross-reference to another footnote:
\labelcref{first}\footnote{Footnote D}\labelcref{third}
\end{document}
Mico
  • 506,678