[latex3-commits] [git/LaTeX3-latex3-latex3] earlier-expl3: Define 2e interfaces for filename stack and backend loading (c1cbabb22)

PhelypeOleinik tex.phelype at gmail.com
Sat Jun 6 01:48:32 CEST 2020


Repository : https://github.com/latex3/latex3
On branch  : earlier-expl3
Link       : https://github.com/latex3/latex3/commit/c1cbabb2247c139c10500f6f027930862b7490f6

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

commit c1cbabb2247c139c10500f6f027930862b7490f6
Author: PhelypeOleinik <tex.phelype at gmail.com>
Date:   Fri Jun 5 20:48:32 2020 -0300

    Define 2e interfaces for filename stack and backend loading
    
    This commit complements the commit (not committed yet, so no hash):
      "Incorporate l3 interfaces for filename stack and backend loading"
    in the latex2e repository that incorporates these interfaces in
    \@pushfilename, \@popfilename (both in ltclass.dtx), and \document (in
    ltfiles.dtx).
    
    This commit doesn't depend on its pair in the latex2e repository: expl3
    should work the same way it did before this commit.  The latex2e commit,
    however, requires this version to work properly.


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

c1cbabb2247c139c10500f6f027930862b7490f6
 l3kernel/expl3.dtx | 100 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 88 insertions(+), 12 deletions(-)

diff --git a/l3kernel/expl3.dtx b/l3kernel/expl3.dtx
index 396c2f40e..d47350825 100644
--- a/l3kernel/expl3.dtx
+++ b/l3kernel/expl3.dtx
@@ -1323,19 +1323,74 @@
   }
 %    \end{macrocode}
 %
-%  A backend has to be in place by the start of the document: this has to be
-%  before global options are checked for use. The odd group stuff avoids
-%  needing to actually patch \tn{document}.
+% \begin{macro}{\@expl at sys@load at backend@@@@}
+%   A backend has to be in place by the start of the document: this has
+%   to be before global options are checked for use.
+%
+%   The \cs[no-index]{@expl at ...@@@@} macros defined in this package are
+%   interfaces for \LaTeXe{}.  There are currently (this will change
+%   with the next release of \LaTeXe{}) two possible cases, at this
+%   point of the code:  either \cs{@expl at sys@load at backend@@@@} (and the
+%   others) already exist because they were defined in
+%   \texttt{ltexpl.ltx} (in \texttt{2ekernel} mode) or in
+%   \texttt{expl3.ltx} (in \texttt{package} mode).
+%
+%   In \texttt{2ekernel} mode, if they exist we are using a future
+%   (2020-10-01) release of \LaTeXe{} and we don't need (and can't)
+%   patch \LaTeXe's internals because these commands are already there.
+%   Though if they don't exist in \texttt{2ekernel} mode, we're using
+%   an older version of the kernel, so we \emph{must} patch.
+%
+%   In \texttt{package} mode, if these commands exist, then we are using
+%   a version of \LaTeXe{} with \textsf{expl3} preloaded (any version)
+%   and in any case patching is already done or the macros are in the
+%   format itself, so nothing to do.
+%   But if in \texttt{package} mode these macros don't exist, we have an
+%   even older version of \LaTeXe{} which doesn't even have
+%   \textsf{expl3} preloaded, so patching is necessary.
+%
+%   All this means that in both \texttt{2ekernel} and \texttt{package}
+%   mode we have to check whether \cs{@expl at sys@load at backend@@@@}
+%   exists, and patch some \LaTeXe{} internals if it doesn't.
+%
+%   In newer \LaTeXe{}, these macros have an empty definition in
+%   \texttt{ltexpl.dtx} in case something wrong happens while loading
+%   this file (\texttt{expl3.ltx}), so they can safely be used in the
+%   \LaTeXe{} kernel.
+%
+%   \cs{@expl at sys@load at backend@@@@} is inserted right at the beginning
+%   of \cs{document}, but after closing the group started by \cs{begin}.
+%   When using \cs{tl_put_left:Nn} to patch the backend loading in
+%   \cs{document}, we need to make sure that it happens at group level
+%   zero, thus the strange |\endgroup...\begingroup| thing.
+%
+%   This chunk of code should only be executed when loading
+%   \texttt{expl3.sty} in a \LaTeXe{} without \pkg{expl3} preloaded, so
+%   we check if \cs{@expl at sys@load at backend@@@@} exists.
 %    \begin{macrocode}
-%<*2ekernel>
-\tl_put_left:Nn \document
+\cs_if_exist:NF \@expl at sys@load at backend@@@@
+  {
+    \tl_put_left:Nn \document
+      {
+        \endgroup
+        \@expl at sys@load at backend@@@@
+        \begingroup
+      }
+  }
+%    \end{macrocode}
+%
+%   Now we define it anyhow.
+%    \begin{macrocode}
+\cs_gset_protected:Npn \@expl at sys@load at backend@@@@
   {
-    \endgroup
     \str_if_exist:NF \c_sys_backend_str
       { \sys_load_backend:n { } }
-    \begingroup
   }
-%</2ekernel>
+%    \end{macrocode}
+% \end{macro}
+%
+%  Process package options.
+%    \begin{macrocode}
 %<*!2ekernel>
 \keys_set:nV { sys } \l_@@_options_clist
 \str_if_exist:NF \c_sys_backend_str
@@ -1380,13 +1435,24 @@
 %
 % \begin{macro}{\@pushfilename, \@popfilename}
 % \begin{macro}{\@@_status_pop:w}
+% \begin{macro}{\@expl at push@filename@@@@}
+% \begin{macro}{\@expl at push@filename at aux@@@@}
+% \begin{macro}{\@expl at pop@filename@@@@}
 %   The idea here is to use \LaTeXe{}'s \tn{@pushfilename} and
 %   \tn{@popfilename} to track the current syntax status. This can be
 %   achieved by saving the current status flag at each push to a stack,
 %   then recovering it at the pop stage and checking if the code
 %   environment should still be active.
+%
+%   Here the code follows the same patching logic than above for
+%   \cs{@expl at sys@load at backend@@@@}.
 %    \begin{macrocode}
-\tl_put_left:Nn \@pushfilename
+\cs_if_exist:NF \@expl at push@filename@@@@
+  {
+    \tl_put_left:Nn  \@pushfilename { \@expl at push@filename@@@@ }
+    \tl_put_right:Nn \@pushfilename { \@expl at push@filename at aux@@@@ }
+  }
+\cs_gset_protected:Npn \@expl at push@filename@@@@
   {
     \exp_args:Nx \__kernel_file_input_push:n
       {
@@ -1401,17 +1467,24 @@
       }
     \ExplSyntaxOff
   }
-\tl_put_right:Nn \@pushfilename { \@pushfilenameaux }
 %    \end{macrocode}
 %   This bit of trickery is needed to grab the name of the file being loaded
 %   so we can record it.
 %    \begin{macrocode}
-\cs_set_protected:Npn \@pushfilenameaux #1#2#3
+\cs_gset_protected:Npn \@expl at push@filename at aux@@@@ #1#2#3
   {
     \str_gset:Nn \g_file_curr_name_str {#3}
     #1 #2 {#3}
   }
-\tl_put_right:Nn \@popfilename
+%    \end{macrocode}
+%
+%    \begin{macrocode}
+\cs_if_exist:NF \@expl at pop@filename@@@@
+  {
+    \tl_put_right:Nn \@popfilename
+      { \@expl at pop@filename@@@@ }
+  }
+\cs_gset_protected:Npn \@expl at pop@filename@@@@
   {
     \__kernel_file_input_pop:
     \tl_if_empty:NTF \l_@@_status_stack_tl
@@ -1433,6 +1506,9 @@
 %    \end{macrocode}
 % \end{macro}
 % \end{macro}
+% \end{macro}
+% \end{macro}
+% \end{macro}
 %
 % \begin{variable}{\l_@@_status_stack_tl}
 %   As \pkg{expl3} itself cannot be loaded with the code environment





More information about the latex3-commits mailing list.