I want to copy the label command locally to preserve its use, for example when other packages might modify its behavior later on. For this reason, I would like to copy label using let (or similar) rather than def.
The following code works.
\documentclass{article}
\usepackage{amsmath}
\usepackage{showkeys}
\NewCommandCopy{\mylabel}{\label}
\begin{document}
I tried to label here. \mylabel{test}
\newpage
I tried to reference here. \pageref{test}
\end{document}
However, I would also like to use hyperref, but it breaks things. The following code does not work.
\documentclass{article}
\usepackage{amsmath}
\usepackage{showkeys}
\NewCommandCopy{\mylabel}{\label}
\usepackage{hyperref}
\begin{document}
I tried to label here. \mylabel{test}
\newpage
I tried to reference here. \pageref{test}
\end{document}
More explicitly, I am getting some runaway argument error from a hyperref internal function.
Is there a way to copy the label command with hyperref support?
This question seems related to this question, but simply using \let as suggested is not working for me.
hyperrefis loaded, and it gives the same error. See https://www.overleaf.com/read/jnhmqpqzynxt – Derive Foiler Mar 20 '22 at 17:08restatable) which kills the label function internally. I want to be able to label it anyways (I am being very careful about this). – Derive Foiler Mar 20 '22 at 17:11\NewCommandCopy{\mylabel}{\label}after begin document (ie after hyperref is set up) (you need to delete the aux file or ignore errors when you first switch) but better not to do this, – David Carlisle Mar 20 '22 at 17:14\addtocontentsor\@outputpagewhich do\let\label\@gobblebut which do not\let\mylabel\@gobble. Same with hyperef-thingies like\texorpdfstring. – Ulrich Diez Mar 20 '22 at 17:50\labelwill need to be modified to patch\mylabelas well. Not making the copy will certainly be preferable. – David Carlisle Mar 20 '22 at 18:29\mylabela mechanism is feasible where instead of the saved definition of\labelthe current\label-command is carried out (no matter what meaning exactly it currently has) in case\labeldoes not have its usual meaning and therefore currently seems to be patched. Could turn things into confusing patchwork. – Ulrich Diez Mar 20 '22 at 18:37\labeland the commands for cross-referencing so that more data than just page-number and value of the counter stepped as the last one before placing the label is associated to a cross-referencing-label. If you do\NewCommandCopy{\mylabel}{\label}before hyperref is loaded, then\mylabelcreates cross-referencing-labels where hyperref's enlargement of the set of data handled by the cross-referencing-mechanism is not taken into account and therefore cross-referencing-commands' extraction of data associated to a cross-referencing-label goes wrong. ... – Ulrich Diez Mar 21 '22 at 09:07\labeland\refand\pageref. – Ulrich Diez Mar 21 '22 at 09:10