[latex3-commits] [git/LaTeX3-latex3-hyperref] cleanup-patches: simplify and extends showkeys support (32a9c4d)
Ulrike Fischer
fischer at troubleshooting-tex.de
Mon Apr 11 16:11:00 CEST 2022
Repository : https://github.com/latex3/hyperref
On branch : cleanup-patches
Link : https://github.com/latex3/hyperref/commit/32a9c4d41a3274ed698c6ef76680734f88adcbfc
>---------------------------------------------------------------
commit 32a9c4d41a3274ed698c6ef76680734f88adcbfc
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date: Mon Apr 11 16:11:00 2022 +0200
simplify and extends showkeys support
>---------------------------------------------------------------
32a9c4d41a3274ed698c6ef76680734f88adcbfc
nameref.dtx | 121 +++++++++++++++++++++++++++++++++---------------------------
1 file changed, 66 insertions(+), 55 deletions(-)
diff --git a/nameref.dtx b/nameref.dtx
index bd8460f..ae22962 100644
--- a/nameref.dtx
+++ b/nameref.dtx
@@ -557,8 +557,10 @@
\long\def\@fifthoffive#1#2#3#4#5{#5}
% \end{macrocode}
% \end{macro}
-% We have to redefine |\ref| and |\pageref| to know about extra
+% We have to redefine |\ref|, |\Ref| and |\pageref| to know about extra
% reference elements. Make them robust, and compatible with Babel.
+% We also define starred versions so that it doesn't depend on hyperref
+% if they are defined or not. We use the same internal names as hyperref.
% The Babel switch is mimicked if not already defined.
% Some support for package \xpackage{showkeys} is implemented. If
% option |notref| of that package is set, |\SK at ref| has the
@@ -573,6 +575,11 @@
\providecommand*\@safe at activesfalse{}%
% \end{macrocode}
% \end{macro}
+% \begin{macro}{\NR at ref@showkeys}
+% \begin{macrocode}
+\newcommand\NR at ref@showkeys[1]{}%
+% \end{macrocode}
+% \end{macro}
% \begin{macro}{\NR at setref}
% \begin{macrocode}
\def\NR at setref#1{%
@@ -597,6 +604,15 @@
% \begin{macro}{\T at ref}
% \begin{macrocode}
\def\T at ref#1{%
+ \NR at ref@showkeys{#1}%
+ \NR at setref{#1}\@firstoffive{#1}%
+}%
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\@refstar}
+% \begin{macrocode}
+\def\@refstar#1{%
+ \NR at ref@showkeys{#1}%
\NR at setref{#1}\@firstoffive{#1}%
}%
% \end{macrocode}
@@ -604,13 +620,23 @@
% \begin{macro}{\T at pageref}
% \begin{macrocode}
\def\T at pageref#1{%
+ \NR at ref@showkeys{#1}%
\NR at setref{#1}\@secondoffive{#1}%
}%
% \end{macrocode}
% \end{macro}
+% \begin{macro}{\@pagerefstar}
+% \begin{macrocode}
+\def\@pagerefstar#1{%
+ \NR at ref@showkeys{#1}%
+ \NR at setref{#1}\@secondoffive{#1}%
+}%
+% \end{macrocode}
+% \end{macro}%
% \begin{macro}{\T at Ref}
% \begin{macrocode}
\def\T at Ref#1{%
+ \NR at ref@showkeys{#1}%
\NR at setref{#1}\NR at MakeUppercaseFirstOfFive{#1}%
}%
\def\NR at MakeUppercaseFirstOfFive#1#2#3#4#5{%
@@ -618,97 +644,82 @@
}%
% \end{macrocode}
% \end{macro}
+% \begin{macro}{\@Refstar}
+% \begin{macrocode}
+\def\@Refstar#1{%
+ \NR at ref@showkeys{#1}%
+ \NR at setref{#1}\NR at MakeUppercaseFirstOfFive{#1}%
+ }%
+% \end{macrocode}
+% \end{macro}%
% \begin{macrocode}
\ifNR at showkeys
\ifx\SK at ref\@empty
\else
-% \end{macrocode}
-% \begin{macro}{\T at ref}
-% \begin{macrocode}
- \def\T at ref#1{%
- \@safe at activestrue
- \SK@\SK@@ref{#1}%
- \@safe at activesfalse
- \NR at setref{#1}\@firstoffive{#1}%
- }%
-% \end{macrocode}
-% \end{macro}
-% \begin{macro}{\T at pageref}
-% \begin{macrocode}
- \def\T at pageref#1{%
- \@safe at activestrue
- \SK@\SK@@ref{#1}%
- \@safe at activesfalse
- \NR at setref{#1}\@secondoffive{#1}%
- }%
-% \end{macrocode}
-% \end{macro}
-% \begin{macro}{\T at Ref}%
-% \begin{macrocode}
- \def\T at Ref#1{%
- \@safe at activestrue
- \SK@\SK@@ref{#1}%
- \@safe at activesfalse
- \NR at setref{#1}\NR at MakeUppercaseFirstOfFive{#1}%
- }%
-% \end{macrocode}
-% \end{macro}
-% \begin{macrocode}
+ \renewcommand\NR at ref@showkeys[1]{%
+ \@safe at activestrue
+ \SK@\SK@@ref{#1}%
+ \@safe at activesfalse}
\fi
\fi
% \end{macrocode}
-% Package \xpackage{hyperref} uses its own definitions of |\ref| and
-% |\pageref| because it extends the syntax by the star form.
+% Package \xpackage{hyperref} uses the same
+% definitions of |\ref|, |\Ref| and
+% |\pageref| but has to redefine the non-starred command to
+% add the hyperlink support.
% |\DeclareRobustCommand| is used by \xpackage{hyperref}.
% Package |nameref| can be loaded before, after
% \xpackage{hyperref} or after
% \xpackage{hyperref}'s definitions in |\AtBeginDocument|.
+% We have to postpone the definition to |\AtBeginDocument| to
+% avoid that showkeys overwrites them again.
% \begin{macrocode}
-\@ifpackageloaded{hyperref}{%
-}{%
+\AddToHook{begindocument}{%
% \end{macrocode}
% \begin{macro}{\ref}
% \begin{macrocode}
- \DeclareRobustCommand{\ref}{\@ifstar\T at ref\T at ref}%
+ \DeclareRobustCommand{\ref}{\@ifstar\@refstar\T at ref}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\pageref}
% \begin{macrocode}
- \DeclareRobustCommand{\pageref}{\@ifstar\T at pageref\T at pageref}%
+ \DeclareRobustCommand{\pageref}{\@ifstar\@pagerefstar\T at pageref}%
% \end{macrocode}
% \end{macro}
% \begin{macro}{\Ref}
% \begin{macrocode}
\DeclareRobustCommand*{\Ref}{%
- \@ifstar\T at Ref\T at Ref}%
+ \@ifstar\@Refstar\T at Ref}%
}
% \end{macrocode}
% \end{macro}
+% \begin{macrocode}
+\DeclareHookRule{begindocument}{showkeys}{before}{nameref}
+% \end{macrocode}
+%
%
% \subsection{Usage and frontend}
% Access the (third) name part with |\nameref|;
% \begin{macro}{\T at nameref}
% \begin{macrocode}
\def\T at nameref#1{%
+ \NR at ref@showkeys{#1}%
+ \begingroup
+ \let\label\@gobble
+ \NR at setref{#1}\@thirdoffive{#1}%
+ \endgroup
+}%
+% \end{macrocode}
+% \end{macro}
+% \begin{macro}{\@namerefstar}
+% \begin{macrocode}
+\def\@namerefstar#1{%
+ \NR at ref@showkeys{#1}%
\begingroup
\let\label\@gobble
\NR at setref{#1}\@thirdoffive{#1}%
\endgroup
}%
-\ifNR at showkeys
- \ifx\SK at ref\@empty
- \else
- \def\T at nameref#1{%
- \@safe at activestrue
- \SK@\SK@@ref{#1}%
- \@safe at activesfalse
- \begingroup
- \let\label\@gobble
- \NR at setref{#1}\@thirdoffive{#1}%
- \endgroup
- }%
- \fi
-\fi
% \end{macrocode}
% \end{macro}
% \begin{macrocode}
@@ -716,7 +727,7 @@
% \begin{macro}{\nameref}
% \begin{macrocode}
\DeclareRobustCommand*{\nameref}{%
- \@ifstar\T at nameref\T at nameref
+ \@ifstar\@namerefstar\T at nameref
}%
% \end{macrocode}
% \end{macro}
More information about the latex3-commits
mailing list.