summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex-dev/base/ltexpl.dtx
blob: 021edc644c3fb691dfbd9cb8e552f2725539f3a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
% \iffalse meta-comment
%
% Copyright (C) 2019-2021
% The LaTeX Project and any individual authors listed elsewhere
% in this file.
%
% This file is part of the LaTeX base system.
% -------------------------------------------
%
% It may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
%    https://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions of LaTeX
% version 2008 or later.
%
% This file has the LPPL maintenance status "maintained".
%
% The list of all files belonging to the LaTeX base distribution is
% given in the file `manifest.txt'. See also `legal.txt' for additional
% information.
%
% The list of derived (unpacked) files belonging to the distribution
% and covered by LPPL is defined by the unpacking scripts (with
% extension .ins) which are part of the distribution.
%
% \fi
%
% \iffalse
%%% From File: ltexpl.dtx
%
%<*driver>
% \fi
\ProvidesFile{ltexpl.dtx}
             [2021/04/20 v1.3c LaTeX Kernel (expl3-dependent code)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltexpl.dtx}
\title{\filename}
\date{\filedate}
\author{%
  Joseph Wright}

\providecommand\pkg[1]{\texttt{#1}}

\begin{document}
 \MaintainedByLaTeXTeam{latex}
 \maketitle
 \DocInput{ltexpl.dtx}
\end{document}
%</driver>
% \fi
%
%
% \changes{v1.2d}{2020/08/21}{Dropped unused command}
%
% \section{\pkg{expl3}-dependent code}
%
% \StopEventually{}
%
% \changes{v0.0}{2019-10-02}{Initial version}
%
% \subsection{Loader}
%
% \changes{v1.0a}{2020/03/02}
%         {Don't load expl3 if already in the format (gh/295)}
% \changes{v1.1}{2020/03/05}
%         {Load xparse.ltx if \cs{NewDocumentCommand} is not defined
%         by expl3.ltx}
% \changes{v1.2c}{2020/06/04}
%         {Define a local version of some \LaTeXe{} basic macros to support
%          package loading}
%
% \begin{macro}{\@kernel@after@enddocument,
%                \@kernel@after@enddocument@afterlastpage}
%   These two kernel hooks are used by the shipout code.  They are
%   defined earlier here because the \pkg{lthooks} code adds material
%   to them.
% \changes{v1.2h}{2020/12/18}
%         {Define kernel \cs{enddocument} hooks early}
%    \begin{macrocode}
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2020/10/01}%
%<latexrelease>  {kernel@enddocument hooks}{Define several kernel hooks}
%    \end{macrocode}
%    We only initialize these kernel hooks if they are not already
%    existing. Otherwise they would be set to \cs{@empty} on rollback
%    which would be wrong because code that has been added to them
%    may still have to be executed in the rollback situation . Instead
%    code that writes to them needs to handle the rollback as needed.
%    It is likely that we have to change that approach in the future,
%    but for now it should do.
%    (It is enough to test only for the existence of one hook, as all
%    got added at the same time.)
% \changes{v1.3c}{2021/04/20}{Don't empty kernel hooks on rollback}
%    \begin{macrocode}
\ifx\@kernel@after@enddocument\@undefined
  \let \@kernel@after@enddocument               \@empty
  \let \@kernel@after@enddocument@afterlastpage \@empty
%    \end{macrocode}
%
%  \begin{macro}{\@kernel@before@begindocument,\@kernel@after@begindocument}
%    For the similar reasons we also define those that are used in
%    \cs{document} because they too get material added to in early modules.
%    \begin{macrocode}
  \let \@kernel@before@begindocument \@empty
  \let \@kernel@after@begindocument  \@empty
\fi
%<latexrelease>\EndIncludeInRelease
%    \end{macrocode}
%
%    \begin{macrocode}
%<latexrelease>\IncludeInRelease{0000/00/00}%
%<latexrelease>  {kernel@enddocument hooks}{Define several kernel hooks}
%<latexrelease>\let\@kernel@after@enddocument\@undefined
%<latexrelease>\let\@kernel@after@enddocument@afterlastpage\@undefined
%<latexrelease>\let\@kernel@before@begindocument\@undefined
%<latexrelease>\let\@kernel@after@begindocument\@undefined
%</2ekernel|latexrelease>
%<latexrelease>\EndIncludeInRelease
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% First define some blank commands, so that in case something goes wrong while
% loading \textsf{expl3}, we won't get strange \texttt{Undefined control
% sequence} errors.
% \changes{v1.3a}{2021/01/24}{Define \pkg{expl3} hooks conditionally}
%    \begin{macrocode}
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2020/10/01}%
%<latexrelease>            {\@expl@sys@load@backend@@}{Roll forward support}%
\def\reserved@a#1{\ifdefined#1\else\def#1{}\fi}
\reserved@a\@expl@sys@load@backend@@
\reserved@a\@expl@push@filename@@
\reserved@a\@expl@push@filename@aux@@
\reserved@a\@expl@pop@filename@@
%<latexrelease>\EndIncludeInRelease
%</2ekernel|latexrelease>
%    \end{macrocode}
%
% \changes{v1.2d}{2020/07/08}
%         {Add a last-minute hook for \textsf{expl3}}
% Create a hook for last-minute \pkg{expl3} material.
%    \begin{macrocode}
%<*2ekernel>
\def\@expl@finalise@setup@@{}
%</2ekernel>
%    \end{macrocode}
%
% Now define some basics to support loading \textsf{expl3}.  These macros can
% be defined here safely, because they are redefined later on by the kernel,
% so we define simpler versions just to suit our needs.
%    \begin{macrocode}
%<*2ekernel>
\long\def\@gobble#1{}
\long\def\@firstofone#1{#1}
\long\def\@firstoftwo#1#2{#1}
\long\def\@secondoftwo#1#2{#2}
\long\def\IfFileExists#1{%
  \openin\@inputcheck"#1" %
  \ifeof\@inputcheck
    \expandafter\@secondoftwo
  \else
    \closein\@inputcheck
    \expandafter\@firstoftwo
  \fi}
\long\def\@ifnextchar#1#2#3{%
  \let\reserved@d=#1%
  \def\reserved@a{#2}%
  \def\reserved@b{#3}%
  \futurelet\@let@token\@ifnch}
\def\@ifnch{%
  \ifx\@let@token\reserved@d
    \expandafter\reserved@a
  \else
    \expandafter\reserved@b
  \fi}
%</2ekernel>
%    \end{macrocode}
%
%    If we are doing a rollback with a format containing expl3 we
%    aren't reloading it as that creates havoc. This may need a
%    refined version!
%    \begin{macrocode}
%<*2ekernel|latexrelease>
%<latexrelease>\IncludeInRelease{2020/10/01}%
%<latexrelease>                 {expl3}{Pre-load expl3}%
\expandafter\ifx\csname tex\string _let:D\endcsname\relax
  \expandafter\@firstofone
\else
  \GenericInfo{}{Skipping: expl3 code already part of the format}%
%<2ekernel>  \expandafter\endinput
%<latexrelease>  \expandafter\@gobble
\fi
%    \end{macrocode}
%
%  Check for the required primitive/engine support and the existence of
%  a loader.
%    \begin{macrocode}
  {%
    \IfFileExists{expl3.ltx}
      {%
        \ifnum0%
          \ifdefined\pdffilesize 1\fi
          \ifdefined\filesize 1\fi
          \ifdefined\luatexversion\ifnum\luatexversion>94 1\fi\fi
          \ifdefined\kanjiskip 1\fi
            >0 %
          \expandafter\@firstofone
        \else
%    \end{macrocode}
%
% In \texttt{2ekernel} mode, an error is fatal and building the format
% is aborted. Use \verb=\batchmode \read -1 to \tokenlist=, which errors
% with
%\begin{verbatim}
%   ! Emergency stop. (cannot \read from terminal in nonstop modes)
%\end{verbatim}
% and aborts the \TeX{} run.  In \texttt{latexrelease} mode, raise an
% error and do nothing.  Both ways, the error message shows the minimum
% \textsf{expl3} engine requirements.
%    \begin{macrocode}
%<2ekernel>          \def~{ }\def\MessageBreak{^^J~~~~~~~~~~~~~~~}%
%<2ekernel>          \errmessage{LaTeX Error:
%<latexrelease>          \@latex@error{%
            LaTeX requires the e-TeX primitives and additional\MessageBreak
            functionality available in the engines:\MessageBreak
              - pdfTeX v1.40\MessageBreak
              - XeTeX v0.99992\MessageBreak
              - LuaTeX v0.95\MessageBreak
              - e-(u)pTeX mid-2012\MessageBreak
            or later%
%<latexrelease>          }\@ehd \expandafter\@gobble
%<2ekernel>          }\batchmode \read -1 to \reserved@a
        \fi
      }
      {%
%<*2ekernel>
        \errmessage{LaTeX requires expl3}%
        \batchmode \read -1 to \reserved@a
%</2ekernel>
%    \end{macrocode}
%    We do not support a roll forward across 2019. You need to start
%    with 2019 if you want to get to 2020 or beyond.
% \changes{v1.2g}{2020/11/24}{Support for roll forward (gh/434)}
%    \begin{macrocode}
%<*latexrelease>
        \@latex@warning@no@line
          {You need a format that already contains a recent\MessageBreak
           expl3 as part of the kernel, e.g. at least a kernel\MessageBreak
           from 2019 to roll forward to that date!\MessageBreak
           --- I'm giving up!\MessageBreak\MessageBreak
           Note that manually loading the expl3 package\MessageBreak
           from your distribution is not enough}%
        \batchmode \read -1 to \reserved@a
%</latexrelease>
      }%
      {\input expl3.ltx }%
  }
%<latexrelease>\EndIncludeInRelease
%<latexrelease>
%    \end{macrocode}
% To support roll-forward for the case where \textsf{xparse} is fully
% integrated into the kernel, we do not need to repeat the complex test
% above as we can simply look for the marker command.
%    \begin{macrocode}
%<latexrelease>\IncludeInRelease{2020/02/02}%
%<latexrelease>                 {expl3}{Pre-load expl3}%
%<latexrelease>\IfFileExists{expl3.ltx}
%<latexrelease>  {%
%<latexrelease>    \ifnum0%
%<latexrelease>      \ifdefined\pdffilesize 1\fi
%<latexrelease>      \ifdefined\filesize 1\fi
%<latexrelease>      \ifdefined\luatexversion\ifnum\luatexversion>94 1\fi\fi
%<latexrelease>      >0 %
%<latexrelease>    \else
%<latexrelease>      \message{Skipping expl3-dependent extensions}
%<latexrelease>      \expandafter\@gobbletwo
%<latexrelease>    \fi
%<latexrelease>  }
%<latexrelease>  {%
%<latexrelease>    \message{Skipping expl3-dependent extensions}%
%<latexrelease>    \@gobbletwo
%<latexrelease>  }%
%<latexrelease>\input{expl3.ltx}
%<latexrelease>\EndIncludeInRelease
%    \end{macrocode}
%
% \changes{v1.3a}{2021/01/21}
%                {Move \pkg{xparse} rollback code to \texttt{ltcmd.dtx}}
%
%    \subsection{Using expl3 code}
%
%    In order to ease the implementation of some new features in
%    \LaTeXe\ we may (temporarily) use some coding based on the
%    \pkg{expl3}-code.
%    Such macros will eventually vanish and may be changed
%    unannounced. They are there for internal use in the \LaTeXe\
%    kernel and are not meant to be used in third-party
%    packages. These macros will always have the \verb|@expl@|
%    prefix in their name.
%
%    The rest of the name matches the \pkg{expl3} name but with all
%    underscores replaced by \texttt{@}s and the \texttt{:} replaced
%    by \texttt{@@}, e.g.,
%\begin{verbatim}
%  \cs_new_eq:NN \@expl@tl@trim@spaces@apply@@nN \tl_trim_spaces_apply:nN
%\end{verbatim}
%    if that \pkg{expl3} command is needed in places that are others
%    coded in \LaTeXe{} conventions.
%
%
%    In this file, each release of LaTeX adds an \cs{IncludeInRelease}
%    block, in which the macros copied for that release were defined.
%    In case a rollback is requested, the entire block is changed.
%
%    Each macro copied has a \cs{changes} entry to explain when and why
%    it was copied, so that further to that may spot it easily.
%
%    Here \cs{cs\string_gset\string_eq:NN} is used, instead of the |new|
%    variant because if different releases use that same name for
%    different purposes, each can copy the macro without worrying about
%    redefinitions.
%
%    \begin{macrocode}
%<latexrelease>\IncludeInRelease{2020/10/01}{\@expl@cs@to@str@@N}%
%<latexrelease>        {expl3 macros added for the 2020-10-01 release}%
%    \end{macrocode}
%
%    The expl3 activation needs to be inside the release guards as
%    otherwise rolling forward is broken in old kernels that do not
%    have expl3 loaded.
% \changes{v1.2g}{2020/11/24}{Support for roll forward (gh/434)}
%    \begin{macrocode}
\ExplSyntaxOn
%    \end{macrocode}
%
% \changes{v1.2e}{2020/08/19}
%         {Add \cs{@expl@cs@to@str@@N} and \cs{@expl@str@if@eq@@nnTF}
%          for \cs{NewCommandCopy} (gh/239)}
%    \begin{macrocode}
\cs_gset_eq:NN \@expl@cs@to@str@@N \cs_to_str:N
\cs_gset_eq:NN \@expl@str@if@eq@@nnTF \str_if_eq:nnTF
%    \end{macrocode}
%
% \changes{v1.2e}{2020/08/19}
%         {Add \cs{@expl@cs@\meta{thing}@spec@@N}
%          for \cs{ShowCommand} (gh/373)}
%    \begin{macrocode}
\cs_gset_eq:NN \@expl@cs@prefix@spec@@N \cs_prefix_spec:N
\cs_gset_eq:NN \@expl@cs@argument@spec@@N \cs_argument_spec:N
\cs_gset_eq:NN \@expl@cs@replacement@spec@@N \cs_replacement_spec:N
%    \end{macrocode}
%
% \changes{v1.2f}{2020/09/06}
%         {Add \cs{@expl@str@map@function@@NN
%          and \cs{@expl@char@generate@@nn}}
%          for \cs{string@makeletter} (gh/386)}
%    \begin{macrocode}
\cs_gset_eq:NN \@expl@str@map@function@@NN \str_map_function:NN
\cs_gset_eq:NN \@expl@char@generate@@nn \char_generate:nn
%    \end{macrocode}
%
%    \begin{macrocode}
\ExplSyntaxOff
%    \end{macrocode}
%
%
%    Here we can't assume that expl3 is available. It will be if we
%    roll back but if this code is executed rolling forward it needs
%    to be pure 2e.
% \changes{v1.2g}{2020/11/24}{Support for roll forward (gh/434)}
%    \begin{macrocode}
%<latexrelease>\EndIncludeInRelease
%<latexrelease>\IncludeInRelease{0000/00/00}{\@expl@cs@to@str@@N}%
%<latexrelease>        {expl3 macros added for the 2020-10-01 release}%
%<latexrelease>\let \@expl@cs@to@str@@N \@undefined
%<latexrelease>\let \@expl@str@if@eq@@nnTF \@undefined
%<latexrelease>\let \@expl@cs@prefix@spec@@N \@undefined
%<latexrelease>\let \@expl@cs@argument@spec@@N \@undefined
%<latexrelease>\let \@expl@cs@replacement@spec@@N \@undefined
%<latexrelease>\let \@expl@str@map@function@@NN \@undefined
%<latexrelease>\EndIncludeInRelease
%</2ekernel|latexrelease>
%    \end{macrocode}
%
%
% \Finale