hyperref icon indicating copy to clipboard operation
hyperref copied to clipboard

add hook to \NR@setref

Open linasstonys opened this issue 3 years ago • 3 comments

Could you define a new command \def\ref@name{#1} and add a new hook to ref the same like it is done in \label:

\def\NR@setref#1{%
    \def\ref@name{#1}%
    \setref@hook    
    \begingroup
      \@safe@activestrue
      \expandafter
    \endgroup
    \expandafter\NR@@setref\csname r@#1\endcsname
    }%

\def\label#1{%
  \@bsphack
  \begingroup
    \def\label@name{#1}%
    \label@hook

Thanks

linasstonys avatar Jul 05 '22 09:07 linasstonys

Please show an example document with a use case.

u-fischer avatar Jul 05 '22 09:07 u-fischer

This is just a hook and use cases can be any. For example write undefined refs positions

\appto\setref@@hook{\write@refposs@info}  
\def\write@refposs@info{%
  \@ifundefined{r@\ref@name}{%
    \pdfsavepos
    \protected@write\@auxout{}%
      {\string\refposs{\ref@name}{{\the\inputlineno}{\number\c@page}{\number\pdflastxpos sp}{\number\pdflastypos sp}}}%
    }{}%  
  }  

that information can be formatted and printed at the end of the file as a helper for user

linasstonys avatar Jul 05 '22 10:07 linasstonys

while I agree that such a hook could be useful (the showkeys package actually do something like that) I don't think that it should be added by nameref, but in the kernel (as should be the similar hook for \label).

u-fischer avatar Jul 06 '22 09:07 u-fischer