[latex3-commits] [git/LaTeX3-latex3-latex2e] gh626-one-time-hooks: fix for #626 (ed39a51f)
Frank Mittelbach
frank.mittelbach at latex-project.org
Fri Jul 23 11:41:01 CEST 2021
Repository : https://github.com/latex3/latex2e
On branch : gh626-one-time-hooks
Link : https://github.com/latex3/latex2e/commit/ed39a51f7291d3460d705036457b91f6508f1068
>---------------------------------------------------------------
commit ed39a51f7291d3460d705036457b91f6508f1068
Author: Frank Mittelbach <frank.mittelbach at latex-project.org>
Date: Fri Jul 23 11:41:01 2021 +0200
fix for #626
>---------------------------------------------------------------
ed39a51f7291d3460d705036457b91f6508f1068
base/changes.txt | 9 +++++++++
base/doc/ltnews34.tex | 33 +++++++++++++++++++++++++++++++--
base/ltclass.dtx | 14 +++++++++-----
base/ltfilehook.dtx | 24 +++++++++++++++++++++++-
base/ltfiles.dtx | 11 +++++++----
base/testfiles/github-0626.lvt | 4 ++++
base/testfiles/github-0626.tlg | 8 ++++++++
7 files changed, 91 insertions(+), 12 deletions(-)
diff --git a/base/changes.txt b/base/changes.txt
index f666bec5..25b4d541 100644
--- a/base/changes.txt
+++ b/base/changes.txt
@@ -6,6 +6,15 @@ completeness or accuracy and it contains some references to files that
are not part of the distribution.
================================================================================
+2021-07-23 Frank Mittelbach <Frank.Mittelbach at latex-project.org>
+
+ * ltclass.dtx (section{Implementation}):
+ Make class/.../name one-time hooks;
+ Make package/.../name one-time hooks (gh/626)
+
+ * ltfiles.dtx (section{File Handling}):
+ Make include/.../name one-time hooks (gh/626)
+
2021-07-20 Phelype Oleinik <phelype.oleinik at latex-project.org>
* ltcmdhooks.dtx:
diff --git a/base/doc/ltnews34.tex b/base/doc/ltnews34.tex
index 5041f583..2dd95a76 100644
--- a/base/doc/ltnews34.tex
+++ b/base/doc/ltnews34.tex
@@ -138,9 +138,38 @@
\emph{write}
-\section{???}
-\emph{write}
+
+
+\section{Hook business}
+
+\subsection{Class, package, and include hook improvements}
+
+Classes, packages and include files can only be loaded once in a
+\LaTeX{} document. For that reasons hooks that are specific to such
+files have been made one-time hooks. Beside being more efficient this
+supports the following important use case
+\begin{verbatim}
+\AddToHook{package/after/varioref}
+ { ... apply my customizations if the package
+ gets loaded (or was loaded already) ... }
+\end{verbatim}
+without the need to first test if the package was already loaded
+before.
+%
+\githubissue{623}
+
+
+
+
+\subsection{???}
+
+%
+\githubissue{000}
+
+
+
+
\section{New or improved commands}
diff --git a/base/ltclass.dtx b/base/ltclass.dtx
index d70604cd..f08b4a68 100644
--- a/base/ltclass.dtx
+++ b/base/ltclass.dtx
@@ -33,7 +33,7 @@
%<*driver>
% \fi
\ProvidesFile{ltclass.dtx}
- [2021/07/12 v1.4d LaTeX Kernel (Class & Package Interface)]
+ [2021/07/23 v1.4e LaTeX Kernel (Class & Package Interface)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltclass.dtx}
@@ -2310,15 +2310,17 @@
% package otherwise, if it is \cs{@clsextension}, a class, so
% depending on that we execute different hooks. If the extension is
% neither, then it is another type of file without special hooks.
+% \changes{v1.4e}{2021/07/23}{Make class/before/name a one-time hook}
+% \changes{v1.4e}{2021/07/23}{Make package/before/name a one-time hook}
% \begin{macrocode}
%-----------------------------------------
\ifx\@currext\@pkgextension
\UseHook{package/before}%
- \UseHook{package/before/\@currname}%
+ \UseOneTimeHook{package/before/\@currname}%
\else
\ifx\@currext\@clsextension
\UseHook{class/before}%
- \UseHook{class/before/\@currname}%
+ \UseOneTimeHook{class/before/\@currname}%
\fi
\fi
% \end{macrocode}
@@ -2377,14 +2379,16 @@
% \end{macrocode}
% And same procedure, James, when we are finished loading, except
% that the hook order is now reversed.
+% \changes{v1.4e}{2021/07/23}{Make class/after/name a one-time hook}
+% \changes{v1.4e}{2021/07/23}{Make package/after/name a one-time hook}
% \begin{macrocode}
%-----------------------------------------
\ifx\@currext\@pkgextension
- \UseHook{package/after/\@currname}%
+ \UseOneTimeHook{package/after/\@currname}%
\UseHook{package/after}%
\else
\ifx\@currext\@clsextension
- \UseHook{class/after/\@currname}%
+ \UseOneTimeHook{class/after/\@currname}%
\UseHook{class/after}%
\fi
\fi}%
diff --git a/base/ltfilehook.dtx b/base/ltfilehook.dtx
index 5d0acc8f..62afae8a 100644
--- a/base/ltfilehook.dtx
+++ b/base/ltfilehook.dtx
@@ -32,7 +32,7 @@
%
% \begin{macrocode}
\providecommand\ltfilehookversion{v1.0k}
-\providecommand\ltfilehookdate{2021/05/25}
+\providecommand\ltfilehookdate{2021/07/23}
% \end{macrocode}
%
%<*driver>
@@ -276,6 +276,21 @@
% If a package or class is not loaded (or it was loaded before the
% hooks were set) none of the hooks are executed!
%
+% All class or package hooks involving the name of the class or
+% package are implemented as
+% one-time hooks, the other as normal hooks. This allows for the
+% following use case
+%\begin{verbatim}
+% \AddToHook{package/after/varioref}
+% { ... apply my customizations if the package gets
+% loaded (or was loaded already) ... }
+%\end{verbatim}
+% without the need to first test if the package was already loaded
+% before.
+%
+%
+%
+%
% \subsection{Hooks for \cs{include} files}
%
% To manage \cs{include} files, \LaTeX{} issues a \cs{clearpage}
@@ -341,6 +356,13 @@
% normally does nothing, but starts a new page if further material
% got added this way.}
%
+%
+% All include hooks involving the include file name are implemented as
+% one-time hooks, the other as normal hooks.
+%
+%
+%
+%
% \subsection{High-level interfaces for \LaTeX{}}
%
% We do not provide any additional wrappers around the hooks (like
diff --git a/base/ltfiles.dtx b/base/ltfiles.dtx
index bcaac582..3e7a497f 100644
--- a/base/ltfiles.dtx
+++ b/base/ltfiles.dtx
@@ -32,7 +32,7 @@
%<*driver>
% \fi
\ProvidesFile{ltfiles.dtx}
- [2021/04/17 v1.2m LaTeX Kernel (File Handling)]
+ [2021/07/23 v1.2n LaTeX Kernel (File Handling)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltfiles.dtx}
@@ -850,16 +850,18 @@
% \end{macrocode}
% Execute the \texttt{before} hooks just after we switched the
% \texttt{.aux} file \ldots
+% \changes{v1.2n}{2021/07/23}{Make include/before/name a one-time hook}
% \begin{macrocode}
\UseHook{include/before}%
- \UseHook{include/before/#1}%
+ \UseOneTimeHook{include/before/#1}%
%-----------------------------------------
\@input@{#1.tex}%
%-----------------------------------------
% \end{macrocode}
% \ldots{} then \texttt{end} hooks \ldots
+% \changes{v1.2n}{2021/07/23}{Make include/end/name a one-time hook}
% \begin{macrocode}
- \UseHook{include/end/#1}%
+ \UseOneTimeHook{include/end/#1}%
\UseHook{include/end}%
%-----------------------------------------
\clearpage
@@ -869,8 +871,9 @@
% followed by another \cs{clearpage} just in case new material got
% added (after all we need to be in well defined state after the
% \cs{include}).
+% \changes{v1.2n}{2021/07/23}{Make include/after/name a one-time hook}
% \begin{macrocode}
- \UseHook{include/after/#1}%
+ \UseOneTimeHook{include/after/#1}%
\UseHook{include/after}%
\clearpage
%-----------------------------------------
diff --git a/base/testfiles/github-0626.lvt b/base/testfiles/github-0626.lvt
index eb146244..5a8ae836 100644
--- a/base/testfiles/github-0626.lvt
+++ b/base/testfiles/github-0626.lvt
@@ -24,6 +24,8 @@
\AddToHook{include/before/\jobname-1}{\typeout{--> before \jobname-1 1}}
\AddToHook{include/before/\jobname-2}{\typeout{--> before \jobname-2 1}}
+\AddToHook{include/end/\jobname-1}{\typeout{--> end \jobname-1 1}}
+\AddToHook{include/end/\jobname-2}{\typeout{--> end \jobname-2 1}}
\AddToHook{include/after/\jobname-1}{\typeout{--> after \jobname-1 1}}
\AddToHook{include/after/\jobname-2}{\typeout{--> after \jobname-2 1}}
@@ -40,6 +42,8 @@
\AddToHook{include/before/\jobname-1}{\typeout{--> before \jobname-1 2}}
\AddToHook{include/before/\jobname-2}{\typeout{--> before \jobname-2 2}}
+\AddToHook{include/end/\jobname-1}{\typeout{--> end \jobname-1 2}}
+\AddToHook{include/end/\jobname-2}{\typeout{--> end \jobname-2 2}}
\AddToHook{include/after/\jobname-1}{\typeout{--> after \jobname-1 2}}
\AddToHook{include/after/\jobname-2}{\typeout{--> after \jobname-2 2}}
diff --git a/base/testfiles/github-0626.tlg b/base/testfiles/github-0626.tlg
index 127fd886..6d3acc76 100644
--- a/base/testfiles/github-0626.tlg
+++ b/base/testfiles/github-0626.tlg
@@ -2,6 +2,8 @@ This is a generated file for the LaTeX2e validation system.
Don't change this file in any respect.
--> before article 1
--> after article 1
+--> before article 2
+--> after article 2
--> before doc 1
(doc.sty
Package: doc ....-..-.. v... Standard LaTeX documentation package (FMi)
@@ -92,8 +94,14 @@ Package: multicol ....-..-.. v... multicolumn formatting (FMi)
\c at CodelineNo=\count...
)
--> after doc 1
+--> before doc 2
+--> after doc 2
--> before github-0626-2 1
(github-0626-2.tex
==> in github-0626-2
)
+--> end github-0626-2 1
--> after github-0626-2 1
+--> before github-0626-2 2
+--> end github-0626-2 2
+--> after github-0626-2 2
More information about the latex3-commits
mailing list.