我希望在我的文档中使用脚注和章节尾注(章节尾注仅用于“大”注释)。
在尾注中,我很高兴能够引用/链接到当前章节(/节/小节/...),其中尾注被调用,并且就在它之前的文本,因为我发现在章节末尾只列出尾注列表很不方便,而且我不记得注释到底在处理什么(上下文)。所以我希望能够在尾注中引用文本的一部分和章节编号,以便将尾注放在上下文中,然后帮助读者...
有没有办法让“ \myendnote
”命令带有两个参数并能够:
- 打印命令主体中调用该命令的第一个参数以及尾注中的第一个参数(在下面的例子中,在引号“”之间并以斜体表示);
- 在尾注文本中打印调用命令的当前章节、节、小节等的链接,甚至脚注编号(如果尾注被调用到脚注中,请参阅 MWE)。这是最后一个功能(处理脚注可以用另一个命令(如“ ”
\myfootendnote
)或另一个参数来处理,我对一切都持开放态度……);
\newcommand{\myendnote}[2]{%
% Here maybe something to auto generate the "autolabel" ???
{#1}\endnote{\emph{\S{}~\ref{autolabel} \nameref{autolabel}, p. \pageref{autolabel}, " {#1} "~}: {#2}}}
% #1 : Text displayed in body document (which have the endnote superscript mark) AND in the endnote between quotes "" and in italic.
% #2 : Text of the endnote
请参阅下面的最终工作解决方案(编辑 3)
这里是 MWE:
\documentclass{report}
\usepackage{hyperref}
\usepackage{nameref}
\usepackage{enotez}
\setenotez{counter-format=alph}
\usepackage{verbatim}
\usepackage{fancyvrb}% Only used for verbatim footnotes
\VerbatimFootnotes
\newcommand{\myendnote}[2]{%
% Here maybe something to auto generate the "autolabel" ???
{#1}\endnote{\emph{\S{}~\ref{autolabel} \nameref{autolabel}, p. \pageref{autolabel}, " {#1} "~}: {#2}}}
% #1 : Text displayed in body document (which have the endnote superscript mark) AND in the endnote between quotes "" and in italic.
% #2 : Text of the endnote
\begin{document}
\chapter{First Chapter}
\chapter{Second Chapter}
\section{A section}
\subsection{A subsection}
\verb!\myendnote{Some text with an end note}{text in the end note no 1}!
Some text with a foot note\footnote{\verb!\myendnote{footnote text}{text in the end note no 2}!%
}
\printendnotes
\end{document}
预期结果如下:
编辑 3:最终的工作解决方案感谢John Kormylo 回答
最终的解决方案适用于带有尾注的几个章节,但尾注列表中与脚注相关的超链接不会重定向到正确的页面,但会打印正确的号码。
命令\myendnote
调用被简化了,因为用户不再需要将计数器作为参数传递,命令会自动处理标记。
梅威瑟:
\documentclass{report}
\usepackage{nameref}
\usepackage{hyperref}
\usepackage{enotez}
\setenotez{counter-format=alph}
\usepackage{verbatim}
\usepackage{fancyvrb}% Only used for verbatim footnotes
\VerbatimFootnotes
\newcounter{endnoteLabelCnt}
\setcounter{endnoteLabelCnt}{0}
\newcounter{endnoteLabelUsed}
\setcounter{endnoteLabelUsed}{0}
\newcounter{endnoteLabelInFootnote}
\setcounter{endnoteLabelInFootnote}{0}
\newcounter{endnoteLabelInFootnoteUsed}
\setcounter{endnoteLabelInFootnoteUsed}{0}
\newcommand{\autoLabelling}{%
\stepcounter{endnoteLabelCnt}%
\label{\thechapter\theendnoteLabelCnt}%
}%
\newcommand{\autoLabellingFootnote}{%
\stepcounter{endnoteLabelInFootnote}%
\label{\thechapter\theendnoteLabelInFootnote\thechapter}%
}%
% Modification of the command in order to deal with call inside a footnote
% <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\usepackage{xparse}
\NewDocumentCommand{\myendnote}{m m o}{%
% <code>
\IfNoValueTF{#3}{% code when no optional argument #3 is passed
{#1}\autoLabelling\endnote{\stepcounter{endnoteLabelUsed}\emph{\S{}~\ref{\thechapter\theendnoteLabelUsed} \nameref{\thechapter\theendnoteLabelUsed}, p. \pageref{\thechapter\theendnoteLabelUsed}, " {#1} "~}: {#2}}}
{% code when the optional argument #3 is present
% Note that, on the next line, the \stepcounter is moved after the \ref and \nameref in order to link to the current section and after to the footnote numer
{#1}\autoLabelling\autoLabellingFootnote\endnote{\emph{\S{}~\ref{\thechapter\theendnoteLabelUsed} \nameref{\thechapter\theendnoteLabelUsed}, \stepcounter{endnoteLabelUsed}\stepcounter{endnoteLabelInFootnoteUsed}footnote \ref{\thechapter\theendnoteLabelInFootnoteUsed\thechapter}, p. \pageref{\thechapter\theendnoteLabelInFootnoteUsed\thechapter}, " {#1} "~}: {#2}}}
}
% #1 : Text displayed in body document (which have the endnote superscript mark) AND in the endnote between quotes "" and in italic.
% #2 : Text of the endnote
% #3 : Optionnal argument if command passed inside a footnote
\begin{document}
\chapter{First Chapter}
\section{A First section}
\subsection{A First subsection}
\verb!\myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}:! \myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}
Some text with a foot note\footnote{\verb!\myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}[footnote]:! \myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}[footnote]}
\printendnotes
\setcounter{endnote}{0} %<<<<<< added
\chapter{Second Chapter}
\section{A second section}
\subsection{A second subsection}
\verb!\myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}:! \myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}
Some text with a foot note\footnote{\verb!\myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}[footnote]:! \myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}[footnote]}
\printendnotes
\setcounter{endnote}{0} %<<<<<< added
\chapter{Third Chapter}
\section{A third section}
\subsection{A third subsection}
\verb!\myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}:! \myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}
Some text with a foot note\footnote{\verb!\myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}[footnote]:! \myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}[footnote]}
\printendnotes
\setcounter{endnote}{0} %<<<<<< added
\end{document}
编辑 1:第一次尝试
我的非可行的解决方案是使用两个新命令:
\autoLabelling
根据计数器创建标签的命令endnoteLabelCnt
:
\newcommand{\autoLabelling}{
\stepcounter{endnoteLabelCnt}
\label{\arabic{endnoteLabelCnt}}
}
\myendnote
如上所述,但有 3 个参数,最后一个是通过 counterendnoteLabelCnt
with\autoLabelling
命令创建的标签。
这里有一个最小非工作示例:
\documentclass{report}
%\usepackage{hyperref}
\usepackage{nameref}
\usepackage{enotez}
\setenotez{counter-format=alph}
\usepackage{verbatim}
\usepackage{fancyvrb}% Only used for verbatim footnotes
\VerbatimFootnotes
\newcounter{endnoteLabelCnt}
\setcounter{endnoteLabelCnt}{0}
\newcommand{\autoLabelling}{
\stepcounter{endnoteLabelCnt}
\label{\arabic{endnoteLabelCnt}}
}
\newcommand{\myendnote}[3]{%
% Here maybe something to auto generate the "autolabel" ???
{#1}\endnote{\emph{\S{}~\ref{#3} \nameref{#3}, p. \pageref{#3}, " {#1} "~}: {#2}}}
% #1 : Text displayed in body document (which have the endnote superscript mark) AND in the endnote between quotes "" and in italic.
% #2 : Text of the endnote
% #3 : Label
\begin{document}
\chapter{First Chapter}
\chapter{Second Chapter}
\section{A section}
\subsection{A subsection}
\autoLabelling
\verb!\myendnote{Some text with an end note}{text in the end note no 1}!
\verb!{\arabic{AbsoluteSectionNumber}} :! \myendnote{Some text with an end note}{text in the end note no 1}{\arabic{endnoteLabelCnt}}
% Warning: \autoLabelling command is called into the footnote here:
Some text with a foot note\footnote{\autoLabelling\verb!\myendnote{footnote text}{text in the end note no 2} :! \myendnote{Some text with an end note}{text in the end note no 2}{\arabic{endnoteLabelCnt}}}
\printendnotes
\end{document}
结果:
问题以红色矩形突出显示:所有链接都指向脚注编号“1”(对应于\autoLabelling
脚注中最后一次使用命令)。第一个尾注“a”应指向小节 2.1.1,如上面的预期结果所示。似乎计数器endnoteLabelCnt
在最后一次调用命令之前就“到处增加”了\autoLabelling
...
编辑 2:跟进评论后的第二次尝试
John Kormylo 提出的解决方案在章节内有效,但如果我的文档中有多个章节,我就无法使其发挥作用。
我尝试修改\myendnote
命令,以便通过可选参数来处理脚注内的调用:
\usepackage{xparse}
\NewDocumentCommand{\myendnote}{m m m o}{%
% <code>
\IfNoValueTF{#4}{% code when no optional argument #4 is passed
{#1}\autoLabelling\endnote{\stepcounter{endnoteLabelCnt}\emph{\S{}~\ref{#3} \nameref{#3}, p. \pageref{#3}, " {#1} "~}: {#2}}}
{% code when the optional argument #4 is present
% Note that, on the next line, the \stepcounter is moved after the \ref and \nameref in order to link to the current section and after to the footnote numer
{#1}\autoLabelling\endnote{\emph{\S{}~\ref{#3} \nameref{#3}, \stepcounter{endnoteLabelCnt}footnote \ref{#3}, p. \pageref{#3}, " {#1} "~}: {#2}}}
}
% #1 : Text displayed in body document (which have the endnote superscript mark) AND in the endnote between quotes "" and in italic.
% #2 : Text of the endnote
% #3 : Label
% #4 : Optionnal argument if command passed inside a footnote
我尝试过这个:
\documentclass{report}
\usepackage{nameref}
\usepackage{enotez}
\usepackage{hyperref}
\setenotez{counter-format=alph}
\usepackage{verbatim}
\usepackage{fancyvrb}% Only used for verbatim footnotes
\VerbatimFootnotes
\newcounter{endnoteLabelCnt}
\setcounter{endnoteLabelCnt}{0}
\newcommand{\autoLabelling}{%
\stepcounter{endnoteLabelCnt}
% Modification here by adding "\thechapter"
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\label{\thechapter\theendnoteLabelCnt}
}
% Modification of the command in order to deal with call inside a footnote
% <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\usepackage{xparse}
\NewDocumentCommand{\myendnote}{m m m o}{%
% <code>
\IfNoValueTF{#4}{% code when no optional argument #4 is passed
{#1}\autoLabelling\endnote{\stepcounter{endnoteLabelCnt}\emph{\S{}~\ref{#3} \nameref{#3}, p. \pageref{#3}, " {#1} "~}: {#2}}}
{% code when the optional argument #4 is present
% Note that, on the next line, the \stepcounter is moved after the \ref and \nameref in order to link to the current section and after to the footnote numer
{#1}\autoLabelling\endnote{\emph{\S{}~\ref{#3} \nameref{#3}, \stepcounter{endnoteLabelCnt}footnote \ref{#3}, p. \pageref{#3}, " {#1} "~}: {#2}}}
}
% #1 : Text displayed in body document (which have the endnote superscript mark) AND in the endnote between quotes "" and in italic.
% #2 : Text of the endnote
% #3 : Label
% #4 : Optionnal argument if command passed inside a footnote
% <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\begin{document}
\chapter{First Chapter}
\section{A First section}
\subsection{A First subsection}
\verb!\myendnote{Some text with an end note}{text in the end note no 1}!
\verb!{\arabic{AbsoluteSectionNumber}} :! \myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}{\thechapter\theendnoteLabelCnt}
Some text with a foot note\footnote{\verb!\myendnote{footnote text}{text in the end note no \theendnoteLabelCnt} :! \myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}{\thechapter\theendnoteLabelCnt}[footnote]}
\setcounter{endnoteLabelCnt}{0}
\printendnotes
\chapter{Second Chapter}
\section{A second section}
\subsection{A second subsection}
\verb!\myendnote{Some text with an end note}{text in the end note no 1}!
\verb!{\arabic{AbsoluteSectionNumber}} :!\myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}{\thechapter\theendnoteLabelCnt}
Some text with a foot note\footnote{\verb!\myendnote{footnote text}{text in the end note no \theendnoteLabelCnt} :!\myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}{\thechapter\theendnoteLabelCnt}[footnote]}
\setcounter{endnoteLabelCnt}{0}
\printendnotes
\end{document}
但它在第二章尾注列表中不起作用,我只得到??字符......
答案1
这种方法可行。它打印脚注计数器,但\nameref
仍打印“A 节”。
\documentclass{report}
\usepackage{nameref}
\usepackage{enotez}
\usepackage{hyperref}
%\setenotez{counter-format=alph}
\usepackage{verbatim}
\usepackage{fancyvrb}% Only used for verbatim footnotes
\VerbatimFootnotes
\newcounter{endnoteLabelCnt}
\setcounter{endnoteLabelCnt}{0}
\newcommand{\autoLabelling}{%
\stepcounter{endnoteLabelCnt}
\label{test\theendnoteLabelCnt}
}
\newcommand{\myendnote}[3]{% #1=
% Here maybe something to auto generate the "autolabel" ???
{#1}\endnote{\stepcounter{endnoteLabelCnt}\emph{\S{}~\ref{#3} \nameref{#3}, p. \pageref{#3}, " {#1} "~}: {#2}}}
% #1 : Text displayed in body document (which have the endnote superscript mark) AND in the endnote between quotes "" and in italic.
% #2 : Text of the endnote
% #3 : Label
\begin{document}
\chapter{First Chapter}
\chapter{Second Chapter}
\section{A section}
\subsection{A subsection}
\autoLabelling
\verb!\myendnote{Some text with an end note}{text in the end note no 1}!
\verb!{\arabic{AbsoluteSectionNumber}} :! \myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}{test\theendnoteLabelCnt}
% Warning: \autoLabelling command is called into the footnote here:
Some text with a foot note\footnote{\verb!\myendnote{footnote text}{text in the end note no \theendnoteLabelCnt} :! \myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}{test\theendnoteLabelCnt}}\autoLabelling
\setcounter{endnoteLabelCnt}{0}
\printendnotes
\end{document}
如果您打算\printendnotes
多次拨打电话,则需要两个计数器。所有标签必须具有唯一的名称,因此您不能重复使用旧号码。
\documentclass{report}
\usepackage{nameref}
\usepackage{enotez}
\usepackage{hyperref}
\setenotez{counter-format=alph}
\usepackage{verbatim}
\usepackage{fancyvrb}% Only used for verbatim footnotes
\VerbatimFootnotes
\newcounter{endnoteLabelCnt}
\setcounter{endnoteLabelCnt}{0}
\newcounter{endnoteLabelUsed}
\setcounter{endnoteLabelUsed}{0}
\newcommand{\autoLabelling}{%
\stepcounter{endnoteLabelCnt}
% Modification here by adding "\thechapter"
%<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\label{\thechapter\theendnoteLabelCnt}
}
% Modification of the command in order to deal with call inside a footnote
% <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\usepackage{xparse}
\NewDocumentCommand{\myendnote}{m m m o}{%
% <code>
\IfNoValueTF{#4}{% code when no optional argument #4 is passed
{#1}\autoLabelling\endnote{\stepcounter{endnoteLabelUsed}\emph{\S{}~\ref{#3} \nameref{#3}, p. \pageref{#3}, " {#1} "~}: {#2}}}
{% code when the optional argument #4 is present
% Note that, on the next line, the \stepcounter is moved after the \ref and \nameref in order to link to the current section and after to the footnote numer
{#1}\autoLabelling\endnote{\emph{\S{}~\ref{#3} \nameref{#3}, \stepcounter{endnoteLabelUsed}footnote \ref{#3}, p. \pageref{#3}, " {#1} "~}: {#2}}}
}
% #1 : Text displayed in body document (which have the endnote superscript mark) AND in the endnote between quotes "" and in italic.
% #2 : Text of the endnote
% #3 : Label
% #4 : Optionnal argument if command passed inside a footnote
% <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
\begin{document}
\chapter{First Chapter}
\section{A First section}
\subsection{A First subsection}
\verb!\myendnote{Some text with an end note}{text in the end note no 1}!
\verb!{\arabic{AbsoluteSectionNumber}} :! \myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}{\thechapter\theendnoteLabelCnt}
Some text with a foot note\footnote{\verb!\myendnote{footnote text}{text in the end note no \theendnoteLabelCnt} :! \myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}{\thechapter\theendnoteLabelCnt}[footnote]}
\printendnotes
\chapter{Second Chapter}
\section{A second section}
\subsection{A second subsection}
\verb!\myendnote{Some text with an end note}{text in the end note no 1}!
\verb!{\arabic{AbsoluteSectionNumber}} :!\myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}{\thechapter\theendnoteLabelCnt}
Some text with a foot note\footnote{\verb!\myendnote{footnote text}{text in the end note no \theendnoteLabelCnt} :!\myendnote{Some text with an end note \theendnoteLabelCnt}{text in the end note no \theendnoteLabelCnt}{\thechapter\theendnoteLabelCnt}[footnote]}
\printendnotes
\end{document}