[latex3-commits] [latex3/hyperref] amsmath, develop: check label definition (4a08f36)

github at latex-project.org github at latex-project.org
Sun Jun 18 11:27:31 CEST 2023


Repository : https://github.com/latex3/hyperref
On branches: amsmath,develop
Link       : https://github.com/latex3/hyperref/commit/4a08f36b30d171c83ecbcd375e69776acfd0b3d1

>---------------------------------------------------------------

commit 4a08f36b30d171c83ecbcd375e69776acfd0b3d1
Author: Ulrike Fischer <fischer at troubleshooting-tex.de>
Date:   Sun Jun 18 11:27:31 2023 +0200

    check label definition


>---------------------------------------------------------------

4a08f36b30d171c83ecbcd375e69776acfd0b3d1
 ChangeLog.txt                    |  4 +++-
 nameref.dtx                      | 21 ++++++++++++++++--
 testfiles-pdftex/label-guard.lvt | 11 +++++++++
 testfiles-pdftex/label-guard.tlg | 48 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 81 insertions(+), 3 deletions(-)

diff --git a/ChangeLog.txt b/ChangeLog.txt
index 0931b1c..1bfc338 100644
--- a/ChangeLog.txt
+++ b/ChangeLog.txt
@@ -1,5 +1,7 @@
-2023-06-14 Ulrike Fischer
+2023-06-18 Ulrike Fischer
     * changed various patches for amsmath to make them independent of loading order.
+    * nameref: check the definition of label and reinstate the kernel definition if it has been changed.
+      This avoid problems with classes (revtex) and packages (ntheorem) which changes \label in an incompatible way.
     
 2023-05-16 Ulrike Fischer
     * remove puenc-greekbasic.def and load definitions from greek-fontenc instead.
diff --git a/nameref.dtx b/nameref.dtx
index e370a40..1af2452 100644
--- a/nameref.dtx
+++ b/nameref.dtx
@@ -274,8 +274,10 @@
 %    \begin{macro}{\label at hook}
 % Starting with LaTeX 2023-06-01 it is not longer needed to 
 % redefine \cs{label} as the kernel provides a hook and  
-% stores \cs{@currentlabelname}. We still support
-% \cs{label at hook} for now as it is used below in \cs{slabel}
+% stores \cs{@currentlabelname}. But as there are packages like ntheorem
+% and revtex which overwrites the kernel definition and then break nameref 
+% and hyperref we add a guard. 
+% We still support \cs{label at hook} for now as it is used below in \cs{slabel}
 % and also in hyperref.    
 %    \begin{macrocode}
 \providecommand*{\label at hook}{}
@@ -284,6 +286,21 @@
     }
 \@ifl at t@r\fmtversion{2023-06-01}
   {
+   \def\NR at label@copy#1{\@bsphack
+     \begingroup
+     \UseHookWithArguments{label}{1}{#1}%
+     \protected at write\@auxout{}%
+         {\string\newlabel{#1}{{\@currentlabel}{\thepage}%
+         {\@currentlabelname}{\@currentHref}{\@kernel at reserved@label at data}}}%
+  \endgroup
+  \@esphack}
+    \ifx\label\NR at label@copy
+    \else 
+      \PackageWarning{nameref}{The definition of \string\label\space has changed! 
+                               \MessageBreak Check your packages!
+                               \MessageBreak Replacing it with the kernel definition}
+      \let\label\NR at label@copy
+    \fi    
     \AddToHookWithArguments{label}{\def\label at name{#1}\label at hook}
   }
   {
diff --git a/testfiles-pdftex/label-guard.lvt b/testfiles-pdftex/label-guard.lvt
new file mode 100644
index 0000000..66852a0
--- /dev/null
+++ b/testfiles-pdftex/label-guard.lvt
@@ -0,0 +1,11 @@
+\documentclass{article}
+\input{regression-test}
+
+\usepackage[thref]{ntheorem}
+\START 
+\usepackage{nameref}
+\begin{document}
+
+\show\label
+\end{document}
+
diff --git a/testfiles-pdftex/label-guard.tlg b/testfiles-pdftex/label-guard.tlg
new file mode 100644
index 0000000..a64ee46
--- /dev/null
+++ b/testfiles-pdftex/label-guard.tlg
@@ -0,0 +1,48 @@
+This is a generated file for the l3build validation system.
+Don't change this file in any respect.
+(nameref.sty
+Package: nameref ....-..-.. v... Cross-referencing by name of section
+(../refcount.sty
+Package: refcount ....-..-.. v... Data extraction from label references (HO)
+(../ltxcmds.sty
+Package: ltxcmds ....-..-.. v... LaTeX kernel commands for general use (HO)
+) (../infwarerr.sty
+Package: infwarerr ....-..-.. v... Providing info/warning/error messages (HO)
+)) (../gettitlestring.sty
+Package: gettitlestring ....-..-.. v... Cleanup title references (HO)
+(../kvoptions.sty
+Package: kvoptions ....-..-.. v... Key value format for package options (HO)
+(../keyval.sty
+Package: keyval ....-..-.. v... key=value parser (DPC)
+\KV at toks@=\toks...
+) (../kvsetkeys.sty
+Package: kvsetkeys ....-..-.. v... Key value parser (HO)
+)))
+Package nameref Warning: The definition of \label has changed! 
+(nameref)                Check your packages! 
+(nameref)                Replacing it with the kernel definition on input line ....
+\c at section@level=\count...
+) (../l3backend-pdftex.def
+File: l3backend-pdftex.def ....-..-.. L3 backend support: PDF output (pdfTeX)
+\l__color_backend_stack_int=\count...
+\l__pdf_internal_box=\box...
+) (label-guard.aux)
+LaTeX Font Info:    Checking defaults for OML/cmm/m/it on input line ....
+LaTeX Font Info:    ... okay on input line ....
+LaTeX Font Info:    Checking defaults for OMS/cmsy/m/n on input line ....
+LaTeX Font Info:    ... okay on input line ....
+LaTeX Font Info:    Checking defaults for OT1/cmr/m/n on input line ....
+LaTeX Font Info:    ... okay on input line ....
+LaTeX Font Info:    Checking defaults for T1/cmr/m/n on input line ....
+LaTeX Font Info:    ... okay on input line ....
+LaTeX Font Info:    Checking defaults for TS1/cmr/m/n on input line ....
+LaTeX Font Info:    ... okay on input line ....
+LaTeX Font Info:    Checking defaults for OMX/cmex/m/n on input line ....
+LaTeX Font Info:    ... okay on input line ....
+LaTeX Font Info:    Checking defaults for U/cmr/m/n on input line ....
+LaTeX Font Info:    ... okay on input line ....
+> \label=macro:
+#1->\@bsphack \begingroup \UseHookWithArguments {label}{1}{#1}\protected at write \@auxout {}{\string \newlabel {#1}{{\@currentlabel }{\thepage }{\@currentlabelname }{\@currentHref }{\@kernel at reserved@label at data }}}\endgroup \@esphack .
+l. ...\show\label
+\tf at thm=\write...
+(label-guard.aux)





More information about the latex3-commits mailing list.