[latex3-commits] [git/LaTeX3-latex3-latex2e] develop: Gh626 one-time hooks (#629) (c96508e6)
GitHub
noreply at github.com
Tue Jul 27 09:00:27 CEST 2021
Repository : https://github.com/latex3/latex2e
On branch : develop
Link : https://github.com/latex3/latex2e/commit/c96508e69695f2354e4e2529f49a618dc3bf68d4
>---------------------------------------------------------------
commit c96508e69695f2354e4e2529f49a618dc3bf68d4
Author: Frank Mittelbach <frank.mittelbach at latex-project.org>
Date: Tue Jul 27 09:00:27 2021 +0200
Gh626 one-time hooks (#629)
* test file for #626
* fix for #626
* changed test because "doc" has a dependency on "multicol" and shows different output depending on whether or not it is avaialble
>---------------------------------------------------------------
c96508e69695f2354e4e2529f49a618dc3bf68d4
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 | 51 ++++++++++++++++++++++++++++++++++++++++++
base/testfiles/github-0626.tlg | 25 +++++++++++++++++++++
7 files changed, 155 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
new file mode 100644
index 00000000..0e999f4c
--- /dev/null
+++ b/base/testfiles/github-0626.lvt
@@ -0,0 +1,51 @@
+\begin{filecontents}[force]{\jobname-1}
+ \typeout{==> in \jobname-1}
+\end{filecontents}
+
+\begin{filecontents}[force]{\jobname-2}
+ \typeout{==> in \jobname-2}
+\end{filecontents}
+
+\input{test2e}
+
+\AddToHook{class/before/article}{\START \typeout{--> before article 1}\OMIT}
+\AddToHook{class/after/article}{\TIMO \typeout{--> after article 1}}
+
+\documentclass{article}
+
+\AddToHook{class/before/article}{\typeout{--> before article 2}}
+\AddToHook{class/after/article}{\typeout{--> after article 2}}
+
+\AddToHook{package/before/structuredlog}{\typeout{--> before structuredlog 1}}
+\AddToHook{package/after/structuredlog}{\typeout{--> after structuredlog 1}}
+\usepackage{structuredlog}
+\AddToHook{package/before/structuredlog}{\typeout{--> before structuredlog 2}}
+\AddToHook{package/after/structuredlog}{\typeout{--> after structuredlog 2}}
+
+\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}}
+
+
+
+\includeonly{\jobname-2}
+
+\OMIT
+\begin{document}
+\TIMO
+
+\include{\jobname-1}
+\include{\jobname-2}
+
+\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}}
+
+\END
+
diff --git a/base/testfiles/github-0626.tlg b/base/testfiles/github-0626.tlg
new file mode 100644
index 00000000..fc46fb53
--- /dev/null
+++ b/base/testfiles/github-0626.tlg
@@ -0,0 +1,25 @@
+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 structuredlog 1
+(structuredlog.sty
+Package: structuredlog ....-..-.. vv... Structuring the TeX transcript file
+\g__filehook_nesting_level_int=\count...
+)
+--> after structuredlog 1
+--> before structuredlog 2
+--> after structuredlog 2
+--> before github-0626-2 1
+= (LEVEL 1 START) github-0626-2.tex
+(github-0626-2.tex
+==> in github-0626-2
+)
+= (LEVEL 1 STOP) github-0626-2.tex
+--> 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.