如何在 \makenote(来自 scrlayer-notecolumn)中使用 \hyperlink(来自 hyperref)?

如何在 \makenote(来自 scrlayer-notecolumn)中使用 \hyperlink(来自 hyperref)?

我尝试将 a 放入\hyperlinka 中\makenote,但出现以下错误:

! Use of \\makenote doesn't match its definition.
\@ifnextchar #1#2#3->\let \reserved@d =#1\def \reserved@a {
                                                           #2}\def \reserved@b {#3}\futurelet \@let@token \@ifnch 
l.20 Testing hyperlink \makenote{a \hyperlink{anchorname}{hyperlink}.}
                                                                     in makenote.

这是源代码:

% lualatex
\documentclass{scrbook}

\usepackage{luatex85}

\usepackage{fontspec}

\usepackage{scrlayer-scrpage}
\usepackage{scrlayer-notecolumn}

\usepackage{hyperref}

\begin{document}

Testing makenote \makenote{makenote}.

Testing \hyperlink{anchorname}{hyperlink}.

Testing hyperlink \makenote{a \hyperlink{anchorname}{hyperlink}.} in makenote.

Testing \hypertarget{anchorname}{hypertarget}.

Testing hyperref in makenote \makenote{a \hyperref[labelname]{hyperref}.}.

Testing \label{labelname}label.

\end{document}

我使用它进行编译,但如果我使用(事先注释掉) lualatex,我会出现同样的错误。pdflatexfontspec

\hyperlink命令在文本中运行良好,仅在 中失败\makenote

\hyperref命令在 中有效\makenote,但不幸的是 s 的锚点\label并不完全位于\labels 的一般定义位置。因此这是一个解决方案。

答案1

自 KOMA-Script 3.23 起软件包scrlayer-notecolumn中有一个 的星号变体\makenote,它不需要保护命令,但可能会中断并且不应扩展:

\documentclass{scrbook}

\usepackage{fontspec}

\usepackage{scrlayer-scrpage}
\usepackage{scrlayer-notecolumn}[2017/02/08]

\usepackage{hyperref}

\begin{document}

Testing makenote \makenote{makenote}.

Testing \hyperlink{anchorname}{hyperlink}.

Testing hyperlink \makenote*{a \hyperlink{anchorname}{hyperlink}.} in makenote.

Testing \hypertarget{anchorname}{hypertarget}.

Testing hyperref in makenote \makenote{a \hyperref[labelname]{hyperref}.}.

Testing \label{labelname}label.

\end{document}

结果是

在此处输入图片描述

没有错误。

使用以下命令可以获得相同的结果(即使使用 3.23 之前的 KOMA-Script):

\documentclass{scrbook}

\usepackage{fontspec}

\usepackage{scrlayer-scrpage}
\usepackage{scrlayer-notecolumn}

\usepackage{hyperref}

\begin{document}

Testing makenote \makenote{makenote}.

Testing \hyperlink{anchorname}{hyperlink}.

Testing hyperlink \makenote{a \protect\hyperlink{anchorname}{hyperlink}.} in makenote.

Testing \hypertarget{anchorname}{hypertarget}.

Testing hyperref in makenote \makenote{a \hyperref[labelname]{hyperref}.}.

Testing \label{labelname}label.

\end{document}

或者

\documentclass{scrbook}

\usepackage{fontspec}

\usepackage{scrlayer-scrpage}
\usepackage{scrlayer-notecolumn}
\DeclareRobustCommand*{\rhyperlink}{\hyperlink}

\usepackage{hyperref}

\begin{document}

Testing makenote \makenote{makenote}.

Testing \hyperlink{anchorname}{hyperlink}.

Testing hyperlink \makenote{a \rhyperlink{anchorname}{hyperlink}.} in makenote.

Testing \hypertarget{anchorname}{hypertarget}.

Testing hyperref in makenote \makenote{a \hyperref[labelname]{hyperref}.}.

Testing \label{labelname}label.

\end{document}

或者

\documentclass{scrbook}

\usepackage{fontspec}

\usepackage{scrlayer-scrpage}
\usepackage{scrlayer-notecolumn}
\DeclareRobustCommand*{\rmakenote}[1]{%
  \makenote{\detokenize{#1}}%
}

\usepackage{hyperref}

\begin{document}

Testing makenote \makenote{makenote}.

Testing \hyperlink{anchorname}{hyperlink}.

Testing hyperlink \rmakenote{a \hyperlink{anchorname}{hyperlink}.} in makenote.

Testing \hypertarget{anchorname}{hypertarget}.

Testing hyperref in makenote \makenote{a \hyperref[labelname]{hyperref}.}.

Testing \label{labelname}label.

\end{document}

相关内容