# How to use \hyperlink (from hyperref) in \makenote (from scrlayer-notecolumn)?

I am trying to put a \hyperlink into a \makenote, but I get the following error:

! 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
in makenote.


This is the source code:

% lualatex
\documentclass{scrbook}

\usepackage{luatex85}

\usepackage{fontspec}

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

\usepackage{hyperref}

\begin{document}

Testing makenote \makenote{makenote}.

Testing \hypertarget{anchorname}{hypertarget}.

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

Testing \label{labelname}label.

\end{document}


I use lualatex for compilation, but I get the same error if I use pdflatex (commenting out fontspec beforehand).

The \hyperlink command works great in the text, it only fails in the \makenote.

The \hyperref command works in \makenote, but unfortunately the anchors of the \labels are not exactly where the \labels are defined in general. Therefore this is a solution.

• Untested: \protect\hyperlink{...} in \makenote? – user31729 Apr 24 '17 at 14:39
• Thanks! Indeed, \protect solves this problem. Is there a way to define a version of \hyperlink that does not need \protect? In fact, in my actual use case the \hyperlinks are buried in some user defined commands and I have to put \protect in front of them if they are used in \makenote. – Toni Dietze Apr 24 '17 at 15:18
• You can try to \robustify\hyperlink, in the preamble, this requires \usepackage{etoolbox} – user31729 Apr 24 '17 at 16:35
• Thanks for mentioning etoolbox. I got it working using \protecting. \newcommand{\makenoteORmarginpar}[1]{\ifdefined\makenote\makenote{\protecting{#1}}\else\marginpar{#1}\fi} – Toni Dietze Apr 24 '17 at 16:39

Since KOMA-Script 3.23 package scrlayer-notecolumn has a star variant of \makenote, that does not need to protect commands, that may break and should not be expanded:

\documentclass{scrbook}

\usepackage{fontspec}

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

\usepackage{hyperref}

\begin{document}

Testing makenote \makenote{makenote}.

Testing \hypertarget{anchorname}{hypertarget}.

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

Testing \label{labelname}label.

\end{document}


results in

without error.

You can get the same result (even with KOMA-Script before 3.23) using:

\documentclass{scrbook}

\usepackage{fontspec}

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

\usepackage{hyperref}

\begin{document}

Testing makenote \makenote{makenote}.

Testing \hypertarget{anchorname}{hypertarget}.

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

Testing \label{labelname}label.

\end{document}


or

\documentclass{scrbook}

\usepackage{fontspec}

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

\usepackage{hyperref}

\begin{document}

Testing makenote \makenote{makenote}.

Testing \hypertarget{anchorname}{hypertarget}.

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

Testing \label{labelname}label.

\end{document}


or

\documentclass{scrbook}

\usepackage{fontspec}

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

\usepackage{hyperref}

\begin{document}

Testing makenote \makenote{makenote}.