[latex3-commits] [latex3/latex2e] gh1185: check grpup level in shared code so applies to classes (0256b600)

github at latex-project.org github at latex-project.org
Tue Jan 30 17:21:36 CET 2024


Repository : https://github.com/latex3/latex2e
On branch  : gh1185
Link       : https://github.com/latex3/latex2e/commit/0256b600aad0e10ae14d465a493f16eaf1398edf

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

commit 0256b600aad0e10ae14d465a493f16eaf1398edf
Author: David Carlisle <d.p.carlisle at gmail.com>
Date:   Tue Jan 30 16:21:36 2024 +0000

    check grpup level in shared code so applies to classes


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

0256b600aad0e10ae14d465a493f16eaf1398edf
 base/doc/ltnews39.tex          |  4 ++--
 base/ltclass.dtx               | 42 ++++++++++++++++++++++--------------------
 base/testfiles/github-1185.tlg |  4 ++--
 3 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/base/doc/ltnews39.tex b/base/doc/ltnews39.tex
index ca21958c..26b9f40e 100644
--- a/base/doc/ltnews39.tex
+++ b/base/doc/ltnews39.tex
@@ -234,8 +234,8 @@ well.
 \section{Code improvements}
 
 \subsection{Loading packages at the top level}
-Packages should only be loaded with \cs{usepackage}, \cs{RequirePackage}
- or \cs{RequirePackageWithOptions}
+Classes and packages should only be loaded with \cs{documentclass}, \cs{usepackage},
+or class interface commands such as `\cs{LoadClass} or `\cs{RequirePackageWithOptions}
 at the top level, not inside a group. Previously \LaTeX\ did not check this,
 which would often lead to low level errors later on if package declarations
 were reverted as a group ended.
diff --git a/base/ltclass.dtx b/base/ltclass.dtx
index 3581e0f3..1a93d8d8 100644
--- a/base/ltclass.dtx
+++ b/base/ltclass.dtx
@@ -1752,30 +1752,10 @@
 % \end{macro}
 %
 % \begin{macro}{\RequirePackage}
-% \changes{v1.5i}{2023/11/26}{Test group level}
 % Load package if not already loaded.
 %    \begin{macrocode}
-%</2ekernel>
-%<latexrelease>\IncludeInRelease{2024/06/01}%
-%<latexrelease>                 {\RequirePackage}{Check Group}%
-%<*2ekernel|latexrelease>
 \def\RequirePackage{%
-  \ifnum\currentgrouplevel>\z@
-     \@latex at error
-      {\noexpand\RequirePackage or \noexpand\usepackage in a group}%
-      {\noexpand\RequirePackage or \noexpand\usepackage should be at the top level}%
-  \fi
   \@fileswithoptions\@pkgextension}
-%</2ekernel|latexrelease>
-%<latexrelease>\EndIncludeInRelease
-%<latexrelease>\IncludeInRelease{0000/00/00}%
-%<latexrelease>                 {\RequirePackage}{Check Group}%
-%<latexrelease>\def\RequirePackage{%
-%<latexrelease>  \@fileswithoptions\@pkgextension}
-%<latexrelease>\EndIncludeInRelease
-%<*2ekernel>
-%    \end{macrocode}
-%    \begin{macrocode}
 \@onlypreamble\RequirePackage
 %    \end{macrocode}
 % \end{macro}
@@ -1970,12 +1950,34 @@
 % \end{macro}
 %
 % \begin{macro}{\@fileswithoptions}
+% \changes{v1.5i}{2023/11/26}{Test group level}
 % The common part of |\documentclass| and |\usepackage|.
 %    \begin{macrocode}
+%</2ekernel>
+%<latexrelease>\IncludeInRelease{2024/06/01}%
+%<latexrelease>                 {\@fileswithoptions}{Check Group}%
+%<*2ekernel|latexrelease>
 \def\@fileswithoptions#1{%
+    \ifnum\currentgrouplevel>\z@
+     \@latex at error
+      {Loading a class or package in a group}%
+      {Classes and packages should only be loaded at the top level}%
+  \fi
   \@ifnextchar[%]
     {\@fileswith at ptions#1}%
     {\@fileswith at ptions#1[]}}
+%</2ekernel|latexrelease>
+%<latexrelease>\EndIncludeInRelease
+%<latexrelease>\IncludeInRelease{0000/00/00}%
+%<latexrelease>                 {\@fileswithoptions}{Check Group}%
+%<latexrelease>\def\@fileswithoptions#1{%
+%<latexrelease>  \@ifnextchar[%]
+%<latexrelease>    {\@fileswith at ptions#1}%
+%<latexrelease>    {\@fileswith at ptions#1[]}}
+%<latexrelease>\EndIncludeInRelease
+%<*2ekernel>
+%    \end{macrocode}
+%    \begin{macrocode}
 \@onlypreamble\@fileswithoptions
 %    \end{macrocode}
 %
diff --git a/base/testfiles/github-1185.tlg b/base/testfiles/github-1185.tlg
index ff0dc518..203a7c5f 100644
--- a/base/testfiles/github-1185.tlg
+++ b/base/testfiles/github-1185.tlg
@@ -1,12 +1,12 @@
 This is a generated file for the LaTeX2e validation system.
 Don't change this file in any respect.
-! LaTeX Error: \RequirePackage or \usepackage in a group.
+! LaTeX Error: Loading a class or package in a group.
 See the LaTeX manual or LaTeX Companion for explanation.
 Type  H <return>  for immediate help.
  ...                                              
 l. ...\usepackage
                {ifthen}
-\RequirePackage or \usepackage should be at the top level
+Classes and packages should only be loaded at the top level
 (ifthen.sty
 Package: ifthen ....-..-.. v... Standard LaTeX ifthen package (DPC)
 )





More information about the latex3-commits mailing list.