When using \property_ref:nn
from the new ltproperties
, how should one properly add hyperlink to it?
In the following example, I defined two commands \MyLabel
and \MyRef
. \MyLabel
would record the current label and type, and \MyRef
would print it accordingly. I would like to add hyperlink in \MyRef
pointing to the corresponding MyLabel
. However, directly using \hyperref[label]{...}
leads to errors:
Use of \??? doesn't match its definition.
<argument> \???
This error message doesn't really say much, so I have no idea where is actually going wrong.
There is a property called target
that might be useful in this case (for example, maybe one should replace the label
with \property_ref:nn { #1 } { target }
?). However I didn't success in making it to work: when I write \property_record:nn { #1 } { label, type, target }
instead of \property_record:nn { #1 } { label, type }
, the errors gone, but the generated hyperlink does not work.
\documentclass{article}
\usepackage{hyperref}
\ExplSyntaxOn
\tl_new:N \l__mymodule_current_type_tl
\property_new:nnnn { type } { now } { unknown } { \l__mymodule_current_type_tl }
\NewDocumentCommand \MyLabel { m }
{
\group_begin:
\exp_args:No \addtocounter { mymodule_ \l__mymodule_current_type_tl } { -1 }
\exp_args:No \refstepcounter { mymodule_ \l__mymodule_current_type_tl }
% \label{#1}
\property_record:nn { #1 } { label, type }
\group_end:
}
\NewDocumentCommand \MyRef { m }
{
\group_begin:
% \hyperref[#1]
{
\tl_use:c { l_mymodule_ \property_ref:nn { #1 } { type } _label_text_tl }
\nobreakspace
% \ref{#1}
\property_ref:nn { #1 } { label }
}
\group_end:
}
\newcounter{mymodule_T}
\tl_const:Nn \l_mymodule_T_label_text_tl { TEST }
\NewDocumentEnvironment { test } { }
{
\tl_set:Nn \l__mymodule_current_type_tl { T }
\fbox{ \l_mymodule_T_label_text_tl \nobreakspace \tl_use:c {themymodule_T} }
}
{
% Does nothing
}
\ExplSyntaxOff
\begin{document}
\begin{test}\MyLabel{test}
\end{test}
\bigskip
\MyRef{test}
\end{document}