Debian Codegraph @

texmf-dist/source/latex/l3kernel/l3bootstrap.dtx

raw
1 % \iffalse meta-comment
2 %
3 %% File: l3bootstrap.dtx
4 %
5 % Copyright (C) 2011-2026 The LaTeX Project
6 %
7 % It may be distributed and/or modified under the conditions of the
8 % LaTeX Project Public License (LPPL), either version 1.3c of this
9 % license or (at your option) any later version. The latest version
10 % of this license is in the file
11 %
12 % https://www.latex-project.org/lppl.txt
13 %
14 % This file is part of the "l3kernel bundle" (The Work in LPPL)
15 % and all files in that bundle must be distributed together.
16 %
17 % -----------------------------------------------------------------------
18 %
19 % The development version of the bundle can be found at
20 %
21 % https://github.com/latex3/latex3
22 %
23 % for those people who are interested.
24 %
25 %<*driver>
26 \documentclass[full,kernel]{l3doc}
27 \begin{document}
28 \DocInput{\jobname.dtx}
29 \end{document}
30 %</driver>
31 % \fi
32 %
33 % \title{^^A
34 % The \pkg{l3bootstrap} module\\ Bootstrap code^^A
35 % }
36 %
37 % \author{^^A
38 % The \LaTeX{} Project\thanks
39 % {^^A
40 % E-mail:
41 % \href{mailto:[email protected]}
42 % {[email protected]}^^A
43 % }^^A
44 % }
45 %
46 % \date{Released 2026-05-15}
47 %
48 % \maketitle
49 %
50 % \begin{documentation}
51 %
52 % \section{Using the \LaTeX3 modules}
53 %
54 % The modules documented in ^^A
55 % \ifinterface
56 % this file (and \file{source3} for documented sources) ^^A
57 % \else
58 % \file{interface3} (and this file) ^^A
59 % \fi
60 % are designed to be used on top of \LaTeXe{} and are already pre-loaded
61 % since \LaTeXe{} 2020-02-02.
62 % To support older formats, the |\usepackage{expl3}| or |\RequirePackage{expl3}|
63 % instructions are still available to load them all as one.
64 %
65 % As the modules use a coding syntax different from standard
66 % \LaTeXe{} it provides a few functions for setting it up.
67 %
68 % \begin{function}[updated = 2011-08-13]{\ExplSyntaxOn, \ExplSyntaxOff}
69 % \begin{syntax}
70 % \cs{ExplSyntaxOn} \meta{code} \cs{ExplSyntaxOff}
71 % \end{syntax}
72 % The \cs{ExplSyntaxOn} function switches to a category code
73 % régime in which spaces and new lines are ignored, and in which the colon (|:|)
74 % and underscore (|_|) are treated as \enquote{letters}, thus allowing
75 % access to the names of code functions and variables. Within this
76 % environment, |~| is used to input a space. The \cs{ExplSyntaxOff}
77 % reverts to the document category code régime.
78 % \begin{texnote}
79 % Spaces introduced by~|~| behave much in the same way as normal
80 % space characters in the standard category code régime: they are
81 % ignored after a control word or at the start of a line, and
82 % multiple consecutive~|~| are equivalent to a single one. However,
83 % |~|~is \emph{not} ignored at the end of a line.
84 % \end{texnote}
85 % \end{function}
86 %
87 % \begin{function}[updated = 2017-03-19, updated = 2023-08-03]
88 % {\ProvidesExplPackage, \ProvidesExplClass, \ProvidesExplFile}
89 % \begin{syntax}
90 % \cs{ProvidesExplPackage} \Arg{package} \Arg{date} \Arg{version} \Arg{description}
91 % \end{syntax}
92 % These functions act broadly in the same way as the corresponding
93 % \LaTeXe{} kernel
94 % functions \tn{ProvidesPackage}, \tn{ProvidesClass} and
95 % \tn{ProvidesFile}. However, they also implicitly switch
96 % \cs{ExplSyntaxOn} for the remainder of the code with the file. At the
97 % end of the file, \cs{ExplSyntaxOff} will be called to reverse this.
98 % (This is the same concept as \LaTeXe{} provides in turning on
99 % \tn{makeatletter} within package and class code.) The \meta{date} should
100 % be given in the format \meta{year}/\meta{month}/\meta{day} or in the ISO
101 % date format \meta{year}-\meta{month}-\meta{day}. If the
102 % \meta{version} is given then a leading \texttt{v} is optional: if given
103 % as a \enquote{pure} version string, a \texttt{v} will be prepended.
104 % \end{function}
105 %
106 % \begin{function}[updated = 2012-06-04]{\GetIdInfo}
107 % \begin{syntax}
108 % \cs{GetIdInfo} |$Id:| \meta{SVN info field} |$| \Arg{description}
109 % \end{syntax}
110 % Extracts all information from a SVN field. Spaces are not
111 % ignored in these fields. The information pieces are stored in
112 % separate control sequences with \cs{ExplFileName} for the part of the
113 % file name leading up to the period, \cs{ExplFileDate} for date,
114 % \cs{ExplFileVersion} for version and \cs{ExplFileDescription} for the
115 % description.
116 % \end{function}
117 %
118 % To summarize: Every single package using this syntax should identify
119 % itself using one of the above methods. Special care is taken so that
120 % every package or class file loaded with \tn{RequirePackage} or similar
121 % are loaded with usual \LaTeXe{} category codes and the \LaTeX3 category code
122 % scheme is reloaded when needed afterwards. See implementation for
123 % details. If you use the \cs{GetIdInfo} command you can use the
124 % information when loading a package with
125 % \begin{verbatim}
126 % \ProvidesExplPackage{\ExplFileName}
127 % {\ExplFileDate}{\ExplFileVersion}{\ExplFileDescription}
128 % \end{verbatim}
129 %
130 % \end{documentation}
131 %
132 % \begin{implementation}
133 %
134 % \section{\pkg{l3bootstrap} implementation}
135 %
136 % \begin{macrocode}
137 %<*code>
138 %<@@=kernel>
139 % \end{macrocode}
140 %
141 % \subsection{The \tn{pdfstrcmp} primitive in \XeTeX{}}
142 %
143 % Only \pdfTeX{} has a primitive called \tn{pdfstrcmp}. The \XeTeX{}
144 % version is just \tn{strcmp}, so there is some shuffling to do. As
145 % this is still a real primitive, using the \pdfTeX{} name is \enquote{safe}.
146 % \begin{macrocode}
147 \begingroup\expandafter\expandafter\expandafter\endgroup
148 \expandafter\ifx\csname pdfstrcmp\endcsname\relax
149 \let\pdfstrcmp\strcmp
150 \fi
151 % \end{macrocode}
152 %
153 % \subsection{Loading support \Lua{} code}
154 %
155 % When \LuaTeX{} is used there are various pieces of \Lua{} code which need to
156 % be loaded. The code itself is defined in \pkg{l3luatex} and is extracted into
157 % a separate file. Thus here the task is to load the \Lua{} code both now and
158 % (if required) at the start of each job.
159 % \begin{macrocode}
160 \begingroup\expandafter\expandafter\expandafter\endgroup
161 \expandafter\ifx\csname directlua\endcsname\relax
162 \else
163 \ifnum\luatexversion<110 %
164 \else
165 % \end{macrocode}
166 % For \LuaTeX{} we make sure the basic support is loaded:
167 % this is only necessary in plain.
168 % \begin{macrocode}
169 \begingroup\expandafter\expandafter\expandafter\endgroup
170 \expandafter\ifx\csname newcatcodetable\endcsname\relax
171 \input{ltluatex}%
172 \fi
173 \begingroup\expandafter\expandafter\expandafter\endgroup
174 \expandafter\ifx\csname newluabytecode\endcsname\relax
175 \else
176 \newluabytecode\@expl@luadata@bytecode
177 \fi
178 \directlua{require("expl3")}%
179 % \end{macrocode}
180 % As the user might be making a custom format, no assumption is made about
181 % matching package mode with only loading the \Lua{} code once. Instead, a
182 % query to \Lua{} reveals what mode is in operation.
183 % \begin{macrocode}
184 \ifnum 0%
185 \directlua{
186 if status.ini_version then
187 tex.write("1")
188 end
189 }>0 %
190 \everyjob\expandafter{%
191 \the\expandafter\everyjob
192 \csname\detokenize{lua_now:n}\endcsname{require("expl3")}%
193 }%
194 \fi
195 \fi
196 \fi
197 % \end{macrocode}
198 %
199 % \subsection{Engine requirements}
200 %
201 % The code currently requires \eTeX{}, the set of \enquote{\pdfTeX{}
202 % extensions} \emph{including} \tn{expanded}, and for Unicode engines the
203 % ability to generate arbitrary character tokens by expansion. That is covered
204 % by all supported engines since \TeX{} Live 2019, which we therefore use
205 % as a baseline for engine and \LaTeX{} format support.
206 % For \LuaTeX, we require at least Lua 5.3 and the |token.set_lua| function.
207 % This is available at least since \LuaTeX{} 1.10, which again is the one
208 % in \TeX{} Live 2019. (u)p\TeX{} only gained \tn{ifincsname} for \TeX{}
209 % Live 2020, but at present that primitive is unused in \pkg{expl3} so for
210 % the present it's not tested. If and when that changes, we will need to
211 % revisit the code here.
212 % \begin{macrocode}
213 \begingroup
214 \def\next{\endgroup}%
215 \def\ShortText{Required primitives not found}%
216 \def\LongText%
217 {%
218 The L3 programming layer requires the e-TeX primitives and the
219 \LineBreak 'pdfTeX utilities' as described in the README file.
220 \LineBreak
221 These are available in the engines\LineBreak
222 - pdfTeX v1.40.20\LineBreak
223 - XeTeX v0.999991\LineBreak
224 - LuaTeX v1.10\LineBreak
225 - e-(u)pTeX v3.8.2\LineBreak
226 - Prote (2021)\LineBreak
227 or later.\LineBreak
228 \LineBreak
229 }%
230 \ifnum0%
231 \expandafter\ifx\csname luatexversion\endcsname\relax
232 \expandafter\ifx\csname expanded\endcsname\relax\else 1\fi
233 \else
234 \ifnum\luatexversion<110 \else 1\fi
235 \fi
236 =0 %
237 \newlinechar`\^^J %
238 \def\LineBreak{\noexpand\MessageBreak}%
239 \expandafter\ifx\csname PackageError\endcsname\relax
240 \def\LineBreak{^^J}%
241 \begingroup
242 \lccode`\~=`\ \lccode`\}=`\ %
243 \lccode`\T=`\T\lccode`\H=`\H%
244 \catcode`\ =11 %
245 \lowercase{\endgroup\def\PackageError#1#2#3{%
246 \begingroup\errorcontextlines-1\immediate\write0{}\errhelp{#3}\def%
247 \ {#1 Error: #2.^^J^^J
248 Type H <return> for immediate help}\def~{\errmessage{%
249 \ }}~\endgroup}}%
250 \fi
251 \edef\next
252 {%
253 \noexpand\PackageError{expl3}{\ShortText}
254 {\LongText Loading of expl3 will abort!}%
255 \endgroup
256 \noexpand\endinput
257 }%
258 \fi
259 \next
260 % \end{macrocode}
261 %
262 % \subsection{The \LaTeX3 code environment}
263 %
264 % The code environment is now set up.
265 %
266 % \begin{macro}{\ExplSyntaxOff}
267 % Before changing any category codes, in package mode we need to save
268 % the situation before loading. Note the set up here means that once applied
269 % \cs{ExplSyntaxOff} becomes a \enquote{do nothing} command until
270 % \cs{ExplSyntaxOn} is used.
271 % \begin{macrocode}
272 \protected\edef\ExplSyntaxOff
273 {%
274 \protected\def\noexpand\ExplSyntaxOff{}%
275 \catcode 9 = \the\catcode 9\relax
276 \catcode 32 = \the\catcode 32\relax
277 \catcode 34 = \the\catcode 34\relax
278 \catcode 58 = \the\catcode 58\relax
279 \catcode 94 = \the\catcode 94\relax
280 \catcode 95 = \the\catcode 95\relax
281 \catcode 124 = \the\catcode 124\relax
282 \catcode 126 = \the\catcode 126\relax
283 \endlinechar = \the\endlinechar\relax
284 \chardef\csname\detokenize{l_@@_expl_bool}\endcsname = 0\relax
285 }%
286 % \end{macrocode}
287 % \end{macro}
288 %
289 % The code environment is now set up.
290 % \begin{macrocode}
291 \catcode 9 = 9\relax
292 \catcode 32 = 9\relax
293 \catcode 34 = 12\relax
294 \catcode 58 = 11\relax
295 \catcode 94 = 7\relax
296 \catcode 95 = 11\relax
297 \catcode 124 = 12\relax
298 \catcode 126 = 10\relax
299 \endlinechar = 32\relax
300 % \end{macrocode}
301 %
302 % \begin{variable}{\l_@@_expl_bool}
303 % The status for code syntax: this is on at present.
304 % \begin{macrocode}
305 \global\chardef\l_@@_expl_bool = 1\relax
306 % \end{macrocode}
307 %\end{variable}
308 %
309 % \begin{macro}{\ExplSyntaxOn}
310 % The idea here is that multiple \cs{ExplSyntaxOn} calls are not
311 % going to mess up category codes, and that multiple calls to
312 % \cs{ExplSyntaxOff} are also not wasting time. Applying
313 % \cs{ExplSyntaxOn} alters the definition of \cs{ExplSyntaxOff}
314 % and so in package mode this function should not be used until after
315 % the end of the loading process!
316 % \begin{macrocode}
317 \protected \def \ExplSyntaxOn
318 {
319 \bool_if:NF \l_@@_expl_bool
320 {
321 \cs_set_protected:Npe \ExplSyntaxOff
322 {
323 \char_set_catcode:nn { 9 } { \char_value_catcode:n { 9 } }
324 \char_set_catcode:nn { 32 } { \char_value_catcode:n { 32 } }
325 \char_set_catcode:nn { 34 } { \char_value_catcode:n { 34 } }
326 \char_set_catcode:nn { 58 } { \char_value_catcode:n { 58 } }
327 \char_set_catcode:nn { 94 } { \char_value_catcode:n { 94 } }
328 \char_set_catcode:nn { 95 } { \char_value_catcode:n { 95 } }
329 \char_set_catcode:nn { 124 } { \char_value_catcode:n { 124 } }
330 \char_set_catcode:nn { 126 } { \char_value_catcode:n { 126 } }
331 \tex_endlinechar:D =
332 \tex_the:D \tex_endlinechar:D \scan_stop:
333 \bool_set_false:N \l_@@_expl_bool
334 \cs_set_protected:Npn \ExplSyntaxOff { }
335 }
336 }
337 \char_set_catcode_ignore:n { 9 } % tab
338 \char_set_catcode_ignore:n { 32 } % space
339 \char_set_catcode_other:n { 34 } % double quote
340 \char_set_catcode_letter:n { 58 } % colon
341 \char_set_catcode_math_superscript:n { 94 } % circumflex
342 \char_set_catcode_letter:n { 95 } % underscore
343 \char_set_catcode_other:n { 124 } % pipe
344 \char_set_catcode_space:n { 126 } % tilde
345 \tex_endlinechar:D = 32 \scan_stop:
346 \bool_set_true:N \l_@@_expl_bool
347 }
348 % \end{macrocode}
349 % \end{macro}
350 %
351 % \begin{macrocode}
352 %</code>
353 % \end{macrocode}
354 %
355 % \end{implementation}
356 %
357 % \PrintIndex