我有一份包含 cleveref 和 hyperref 的文档,我不想错过它们。我需要使用 cleveref 重复使用脚注,这要归功于https://tex.stackexchange.com/a/10116。我还想在脚注标记之间自动插入上标逗号,这得益于https://tex.stackexchange.com/a/71347。单独来看,它们都工作正常。结合使用以下代码https://tex.stackexchange.com/a/285630/154602,脚注重复且格式不正确,缺少上标逗号。
\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}
\footnote
我怎样才能使脚注中的和的组合\cref
看起来美观,就像\footnote
输出第一行中两个 s 相互衔接一样?
我认为问题是由于在检查时\isFootnoteOrSimilar
,\cref
没有展开。的宏扩展\isFootnoteOrSimilar
必须在完全展开后最后运行\cref
,但我不知道该怎么做。
答案1
交叉引用的标注应该看起来与使用生成的“普通”脚注完全一样
\footnote
以下设置可能正是您想要的。请注意,\cref{<footnote-label>}
如果您想创建由项目的文本字符串(此处:)footnote
和相关(上标)数字组成的交叉引用,则应使用;\labelcref{<footnote-label>}
如果您只想创建上标数字,则应使用。在下面的示例中,请注意 的 2 个实例\cref
和 的 3 个实例\labelcref
。
\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}