[latex3-commits] [git/LaTeX3-latex3-latex2e] lthooks2: added docu and tests for \AtBeginEnvironment etc (4541decc)

Frank Mittelbach frank.mittelbach at latex-project.org
Tue Aug 18 23:00:14 CEST 2020


Repository : https://github.com/latex3/latex2e
On branch  : lthooks2
Link       : https://github.com/latex3/latex2e/commit/4541decc949f8569d6d5dc63afabb2a30ebdee1d

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

commit 4541decc949f8569d6d5dc63afabb2a30ebdee1d
Author: Frank Mittelbach <frank.mittelbach at latex-project.org>
Date:   Tue Aug 18 23:00:14 2020 +0200

    added docu and tests for \AtBeginEnvironment etc


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

4541decc949f8569d6d5dc63afabb2a30ebdee1d
 base/ltclass.dtx                                   |  4 +-
 base/ltfilehook.dtx                                |  2 -
 base/ltfssini.dtx                                  |  6 +-
 base/lthooks.dtx                                   | 96 ++++++++--------------
 base/ltmiscen.dtx                                  | 14 +++-
 base/testfiles-lthooks/lthooks-026.lvt             | 32 ++++++++
 .../{filehook-003.tlg => lthooks-026.tlg}          | 76 +++++++----------
 base/testfiles-lthooks/lthooks-legacy.lvt          |  4 -
 base/testfiles-lthooks/lthooks-legacy.tlg          |  1 -
 base/testfiles-lthooks2/lthooks2-002.lvt           |  2 +-
 10 files changed, 114 insertions(+), 123 deletions(-)

diff --git a/base/ltclass.dtx b/base/ltclass.dtx
index c6ac6958..7047aac1 100644
--- a/base/ltclass.dtx
+++ b/base/ltclass.dtx
@@ -459,7 +459,9 @@
 % \end{macro}
 %
 % \begin{macro}{\@documentclasshook}
-%    The hook called after the first |\documentclass| command.  By
+%    This legacy hook is called after the first |\documentclass| command.
+%    It is \emph{not} integrated with the new 2020 hook management system!
+%    By
 %    default this checks to see if |\@normalsize| is undefined, and if
 %    so, sets it to |\normalsize|.
 % \changes{v0.2q}{1993/12/17}
diff --git a/base/ltfilehook.dtx b/base/ltfilehook.dtx
index 1cfaf8d3..bde036f7 100644
--- a/base/ltfilehook.dtx
+++ b/base/ltfilehook.dtx
@@ -37,8 +37,6 @@
 %
 %<*driver>
 
-\RequirePackage{lthooks}        % needed for structedlog if running old format
-
 \documentclass{l3doc}
 
 % bug fix fo l3doc.cls
diff --git a/base/ltfssini.dtx b/base/ltfssini.dtx
index 715e8e68..d5e56fe8 100644
--- a/base/ltfssini.dtx
+++ b/base/ltfssini.dtx
@@ -1751,7 +1751,11 @@
 %    
 %    \begin{macrocode}
    \UseHook{normalfont}%
-   \@defaultfamilyhook       % hookname from 2020/02 will vanish
+%    \end{macrocode}
+%    This is the old name for the hook introduced in 2020/02/02.
+%    It will be removed in one of the future releases!
+%    \begin{macrocode}
+   \@defaultfamilyhook        % hookname from 2020/02 will vanish
    \selectfont}
 %    \end{macrocode}
 %    
diff --git a/base/lthooks.dtx b/base/lthooks.dtx
index 330d38fb..afd51806 100644
--- a/base/lthooks.dtx
+++ b/base/lthooks.dtx
@@ -36,8 +36,6 @@
 %    \end{macrocode}
 %
 %<*driver>
-\RequirePackage[debug]{lthooks}
-
 \documentclass{l3doc}
 
 % bug fix fo l3doc.cls
@@ -1193,6 +1191,38 @@
 %    to add the outer hooks, etc.
 %
 %
+% \begin{function}{\BeforeBeginEnvironment}
+%   \begin{syntax}
+%     \cs{BeforeBeginEnvironment} \oarg{label} \Arg{code}
+%   \end{syntax}
+%   This declaration adds to the \hook{env/\meta{env}/before} hook
+%    using by default the current package or class name as a label or
+%    \texttt{top-level} if used in the document directly.
+% \end{function}
+%
+% \begin{function}{\AtBeginEnvironment}
+%   \begin{syntax}
+%     \cs{AtBeginEnvironment} \oarg{label} \Arg{code}
+%   \end{syntax}
+%   Like \cs{BeforeBeginEnvironment} but adds to the \hook{env/\meta{env}/begin} hook.
+% \end{function}
+%
+% \begin{function}{\AtEndEnvironment}
+%   \begin{syntax}
+%     \cs{AtEndEnvironment} \oarg{label} \Arg{code}
+%   \end{syntax}
+%   Like \cs{BeforeBeginEnvironment} but adds to the \hook{env/\meta{env}/end} hook.
+% \end{function}
+%
+% \begin{function}{\AfterEndEnvironment}
+%   \begin{syntax}
+%     \cs{AfterEndEnvironment} \oarg{label} \Arg{code}
+%   \end{syntax}
+%   Like \cs{BeforeBeginEnvironment} but adds to the \hook{env/\meta{env}/after} hook.
+% \end{function}
+%
+%
+%    
 %
 % \subsubsection{Hooks provided by \cs{begin}\texttt{\{document\}}}
 %
@@ -3626,64 +3656,12 @@
 %<@@=hook>
 %    \end{macrocode}
 %  \end{macro}
-
-%  \subsection{Set up existing \LaTeXe{} hooks}
-%
-%    As we are in a package calling \cs{NewHook} would label any
-%    already set up hook code under the package name, but we want it
-%    under the name \hook{top-level} so we pretend that \cs{@currname}
-%    is empty.
-%    \begin{macrocode}
-\begingroup
-  \def\@currname{}
-%    \end{macrocode}
-%    
-%    \begin{macrocode}
-%    \end{macrocode}
-%    We need to initialize the mechanism at \verb=\begin{document}=
-%    but obviously before everything else, so we sneak\footnote{This
-%    needs to move to \cs{document} directly.}
-%    \cs{@@_initialize_all:} into the \LaTeXe{} hook name.
-%
-%    We can't use \cs{tl_gput_left:Nn} because that complains about
-%    \cs{@begindocumenthook} not starting with \cs{g_} so we do this
-%    through the backdoor.
-%    \begin{macrocode}
-%  \tex_global:D\tl_put_left:Nn \@begindocumenthook
-%      {\@@_initialize_all:}
-%    \end{macrocode}
-%    There aren't many other hooks at the moment:
-%    \begin{macrocode}
-%    \end{macrocode}
-%    Not checked what this one does and whether it should be there (or
-%    is a real ``hook''.
-%    \begin{macrocode}
-
-
-  %   \NewHook{documentclass}   guess we drop that one
-  
-%    \end{macrocode}
-%    
-%    \begin{macrocode}
-\endgroup
-%    \end{macrocode}
-%
 %
 %
 % \section{Generic hooks for environments}
 %
 %
 %    
-%  \begin{macro}{\AtBeginEnvironment,\AtEndEnvironment,
-%                \BeforeBeginEnvironment,\AfterEndEnvironment}
-%
-%  Needs documenting above
-%  \end{macro}
-%    
-%    
-%    
-%    
-%    
 %    
 %    
 %    
@@ -3733,16 +3711,6 @@
 %  \end{macro}
 %
 %
-% \section{Hooks in \cs{enddocument}}
-%
-%
-%    
-%    The \hook{enddocument} hook was already set up earlier, here are now
-%    the additional ones:
-%    \begin{macrocode}
-%    \end{macrocode}
-
-
 %
 %
 % \subsection{Adjusting at \pkg{atveryend} interfaces}
diff --git a/base/ltmiscen.dtx b/base/ltmiscen.dtx
index a5e22870..2b1e3c18 100644
--- a/base/ltmiscen.dtx
+++ b/base/ltmiscen.dtx
@@ -888,10 +888,16 @@
 %<*2ekernel|latexrelease>
 %<latexrelease>\IncludeInRelease{2020/10/01}%
 %<latexrelease>                 {\AtBeginEnvironment}{Hooks for environments}%
-\newcommand\AtBeginEnvironment[1]    {\AddToHook{env/#1/begin}}
-\newcommand\AtEndEnvironment[1]      {\AddToHook{env/#1/end}}
-\newcommand\BeforeBeginEnvironment[1]{\AddToHook{env/#1/before}}
-\newcommand\AfterEndEnvironment[1]   {\AddToHook{env/#1/after}}
+%    \end{macrocode}
+%
+%    \begin{macrocode}
+\newcommand\AtBeginEnvironment[2][.]    {\AddToHook{env/#2/begin}[#1]}
+\newcommand\AtEndEnvironment[2][.]      {\AddToHook{env/#2/end}[#1]}
+\newcommand\BeforeBeginEnvironment[2][.]{\AddToHook{env/#2/before}[#1]}
+\newcommand\AfterEndEnvironment[2][.]   {\AddToHook{env/#2/after}[#1]}
+%    \end{macrocode}
+%
+%    \begin{macrocode}
 %</2ekernel|latexrelease>
 %<latexrelease>\EndIncludeInRelease
 %    \end{macrocode}
diff --git a/base/testfiles-lthooks/lthooks-026.lvt b/base/testfiles-lthooks/lthooks-026.lvt
new file mode 100644
index 00000000..8fe8a98c
--- /dev/null
+++ b/base/testfiles-lthooks/lthooks-026.lvt
@@ -0,0 +1,32 @@
+
+\documentclass{article}
+
+\input{regression-test}
+
+\START
+
+
+\BeforeBeginEnvironment{quote}{\typeout{quote begin}}
+\AtBeginEnvironment{quote}{\typeout{quote begin}}
+\AtEndEnvironment{quote}{\typeout{quote end}}
+\AfterEndEnvironment{quote}{\typeout{quote after}}
+
+\BeforeBeginEnvironment[foo]{quote}{\typeout{quote before 2}}
+\AtBeginEnvironment[bar]{quote}{\typeout{quote begin 2}}
+
+
+\ShowHook{env/quote/begin}
+
+
+\begin{document}
+
+\begin{quote} test 1 \end{quote}
+
+\AtEndEnvironment[baz]{quote}{\typeout{quote end 2}}
+\AfterEndEnvironment[foobar]{quote}{\typeout{quote after 2}}
+
+\ShowHook{env/quote/after}
+
+\begin{quote} test 2 \end{quote}
+
+\end{document}
diff --git a/base/testfiles-lthooks/filehook-003.tlg b/base/testfiles-lthooks/lthooks-026.tlg
similarity index 63%
copy from base/testfiles-lthooks/filehook-003.tlg
copy to base/testfiles-lthooks/lthooks-026.tlg
index e2a813fd..9da783a5 100644
--- a/base/testfiles-lthooks/filehook-003.tlg
+++ b/base/testfiles-lthooks/lthooks-026.tlg
@@ -1,22 +1,15 @@
 This is a generated file for the l3build validation system.
 Don't change this file in any respect.
-(article.cls
-Document Class: article ....-..-.. v... Standard LaTeX document class
-(size10.clo
-File: size10.clo ....-..-.. v... Standard LaTeX file (size option)
-)
-\c at part=\count...
-\c at section=\count...
-\c at subsection=\count...
-\c at subsubsection=\count...
-\c at paragraph=\count...
-\c at subparagraph=\count...
-\c at figure=\count...
-\c at table=\count...
-\abovecaptionskip=\skip...
-\belowcaptionskip=\skip...
-\bibindent=\dimen...
-)
+The hook 'env/quote/begin':
+ Code chunks:
+    . -> \typeout {quote begin}
+    bar -> \typeout {quote begin 2}
+ Extra code next invocation:
+    ---
+ Rules:
+    ---
+ Execution order:
+    ., bar
 (../l3backend-dvips.def
 File: l3backend-dvips.def ....-..-.. L3 backend support: dvips
 \l__pdf_internal_box=\box...
@@ -27,7 +20,7 @@ File: l3backend-dvips.def ....-..-.. L3 backend support: dvips
 \g__pdf_backend_link_int=\count...
 \g__pdf_backend_link_sf_int=\count...
 )
-No file filehook-003.aux.
+No file lthooks-026.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 ....
@@ -42,36 +35,29 @@ 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 ....
-The hook 'include/before':
- Code chunks:
-    A -> \typeout {A}
-    B -> \typeout {B}
-    C -> \typeout {C}
- Extra code next invocation:
-    ---
- Rules:
-    ---
- Execution order:
-    A, B, C
-The hook 'include/after':
- Code chunks:
-    A -> \typeout {A}
-    B -> \typeout {B}
-    C -> \typeout {C}
- Extra code next invocation:
-    ---
- Rules:
-    ---
- Execution order (after reversal):
-    C, B, A
-The hook 'include/end':
+quote begin
+quote before 2
+quote begin
+quote begin 2
+quote end
+quote after
+The hook 'env/quote/after':
  Code chunks:
-    A -> \typeout {A}
-    B -> \typeout {B}
-    C -> \typeout {C}
+    . -> \typeout {quote after}
+    foobar -> \typeout {quote after 2}
  Extra code next invocation:
     ---
  Rules:
     ---
  Execution order (after reversal):
-    C, B, A
+    foobar, .
+quote begin
+quote before 2
+quote begin
+quote begin 2
+quote end
+quote end 2
+quote after 2
+quote after
+[1
+] (lthooks-026.aux)
diff --git a/base/testfiles-lthooks/lthooks-legacy.lvt b/base/testfiles-lthooks/lthooks-legacy.lvt
index 5168d25b..1569fd1d 100644
--- a/base/testfiles-lthooks/lthooks-legacy.lvt
+++ b/base/testfiles-lthooks/lthooks-legacy.lvt
@@ -9,7 +9,6 @@
 
 \AtBeginDocument{\typeout{FOO}}
 
-
 \makeatletter
 \g at addto@macro\@begindocumenthook{\typeout{legacy begindocument\on at line}}
 \g at addto@macro\@sffamilyhook{\typeout{legacy sffamily\on at line}}
@@ -18,9 +17,6 @@
 \g at addto@macro\@ttfamilyhook{\typeout{legacy ttfamily\on at line}}
 \makeatother
 
-\typeout{============================ 3}
-%\ShowHook{begindocument}
-
 \begin{document}
 
 \textsf{A}
diff --git a/base/testfiles-lthooks/lthooks-legacy.tlg b/base/testfiles-lthooks/lthooks-legacy.tlg
index 78579e93..c3a7002b 100644
--- a/base/testfiles-lthooks/lthooks-legacy.tlg
+++ b/base/testfiles-lthooks/lthooks-legacy.tlg
@@ -1,7 +1,6 @@
 This is a generated file for the l3build validation system.
 Don't change this file in any respect.
 **** Add to hook begindocument (top-level) on input line ... <- \typeout {FOO}
-============================ 3
 Update code for hook 'begindocument' on input line ...:
 **** Add to hook begindocument (legacy) on input line ... <- \typeout {legacy begindocument\on at line }
 Code labels for sorting:
diff --git a/base/testfiles-lthooks2/lthooks2-002.lvt b/base/testfiles-lthooks2/lthooks2-002.lvt
index 9d68f5e2..cc3b99ab 100644
--- a/base/testfiles-lthooks2/lthooks2-002.lvt
+++ b/base/testfiles-lthooks2/lthooks2-002.lvt
@@ -9,7 +9,7 @@
 
 \input{regression-test}
 
-\usepackage[debug]{lthooks}
+\DebugHooksOn
 
 \START
 





More information about the latex3-commits mailing list.