| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
%% File: l3basics.dtx |
| 4 |
% |
| 5 |
% Copyright (C) 1990-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{l3basics} module\\ Basic definitions^^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 |
% As the name suggests, this module holds some basic definitions which |
| 53 |
% are needed by most or all other modules in this set. |
| 54 |
% |
| 55 |
% Here we describe those functions that are used all over the place. |
| 56 |
% By that, we mean functions dealing with the construction and testing of |
| 57 |
% control sequences. Furthermore the basic parts of conditional |
| 58 |
% processing are covered; conditional processing dealing with specific |
| 59 |
% data types is described in the modules specific for the respective |
| 60 |
% data types. |
| 61 |
% |
| 62 |
% \section{No operation functions} |
| 63 |
% |
| 64 |
% \begin{function}[EXP]{\prg_do_nothing:} |
| 65 |
% \begin{syntax} |
| 66 |
% \cs{prg_do_nothing:} |
| 67 |
% \end{syntax} |
| 68 |
% An expandable function which does nothing at all: leaves nothing |
| 69 |
% in the input stream after a single expansion. |
| 70 |
% \end{function} |
| 71 |
% |
| 72 |
% \begin{function}{\scan_stop:} |
| 73 |
% \begin{syntax} |
| 74 |
% \cs{scan_stop:} |
| 75 |
% \end{syntax} |
| 76 |
% A non-expandable function which does nothing. Does not vanish on |
| 77 |
% expansion but produces no typeset output. |
| 78 |
% \end{function} |
| 79 |
% |
| 80 |
% \section{Grouping material} |
| 81 |
% |
| 82 |
% \begin{function}{\group_begin:, \group_end:} |
| 83 |
% \begin{syntax} |
| 84 |
% \cs{group_begin:} |
| 85 |
% \cs{group_end:} |
| 86 |
% \end{syntax} |
| 87 |
% These functions begin and end a group for definition purposes. |
| 88 |
% Assignments are local to groups unless carried out in a global |
| 89 |
% manner. (A small number of exceptions to this rule will be noted |
| 90 |
% as necessary elsewhere in this document.) Each \cs{group_begin:} |
| 91 |
% must be matched by a \cs{group_end:}, although this does not have |
| 92 |
% to occur within the same function. Indeed, it is often necessary |
| 93 |
% to start a group within one function and finish it within another, |
| 94 |
% for example when seeking to use non-standard category codes. |
| 95 |
% \begin{texnote} |
| 96 |
% These are the \TeX{} primitives \tn{begingroup} and \tn{endgroup}. |
| 97 |
% \end{texnote} |
| 98 |
% \end{function} |
| 99 |
% |
| 100 |
% \begin{function}{\group_insert_after:N} |
| 101 |
% \begin{syntax} |
| 102 |
% \cs{group_insert_after:N} \meta{token} |
| 103 |
% \end{syntax} |
| 104 |
% Adds \meta{token} to the list of \meta{tokens} to be inserted |
| 105 |
% when the current group level ends. The list of \meta{tokens} to be |
| 106 |
% inserted is empty at the beginning of a group: multiple |
| 107 |
% applications of \cs{group_insert_after:N} may be used to build |
| 108 |
% the inserted list one \meta{token} at a time. The current group |
| 109 |
% level may be closed by a \cs{group_end:} function or by a token |
| 110 |
% with category code $2$ (close-group), namely a ^^A{ |
| 111 |
% |}| if standard category codes apply. |
| 112 |
% \begin{texnote} |
| 113 |
% This is the \TeX{} primitive \tn{aftergroup}. |
| 114 |
% \end{texnote} |
| 115 |
% \end{function} |
| 116 |
% |
| 117 |
% \begin{function}[added = 2021-05-11]{\group_show_list:, \group_log_list:} |
| 118 |
% \begin{syntax} |
| 119 |
% \cs{group_show_list:} |
| 120 |
% \cs{group_log_list:} |
| 121 |
% \end{syntax} |
| 122 |
% Display (to the terminal or log file) a list of the groups that are |
| 123 |
% currently opened. This is intended for tracking down problems. |
| 124 |
% \begin{texnote} |
| 125 |
% This is a wrapper around the \eTeX{} primitive \tn{showgroups}. |
| 126 |
% \end{texnote} |
| 127 |
% \end{function} |
| 128 |
% |
| 129 |
% \section{Control sequences and functions} |
| 130 |
% |
| 131 |
% As \TeX{} is a macro language, creating new functions means |
| 132 |
% creating macros. At point of use, a function is replaced by |
| 133 |
% the replacement text (\enquote{code}) in which each parameter |
| 134 |
% in the code (|#1|, |#2|, etc.) is replaced the appropriate |
| 135 |
% arguments absorbed by the function. In the following, \meta{code} |
| 136 |
% is therefore used as a shorthand for \enquote{replacement text}. |
| 137 |
% |
| 138 |
% Functions which are not \enquote{protected} are fully expanded |
| 139 |
% inside an \texttt{e}-type or \texttt{x}-type expansion. |
| 140 |
% In contrast, \enquote{protected} functions are not expanded within |
| 141 |
% \texttt{e} and \texttt{x} expansions. |
| 142 |
% |
| 143 |
% \subsection{Defining functions} |
| 144 |
% |
| 145 |
% Functions can be created with no requirement that they are declared |
| 146 |
% first (in contrast to variables, which must always be declared). |
| 147 |
% Declaring a function before setting up the code means that the name |
| 148 |
% chosen is checked and an error raised if it is already in use. |
| 149 |
% The name of a function can be checked at the point of definition using |
| 150 |
% the \cs[no-index]{cs_new\ldots} functions: this is recommended for all |
| 151 |
% functions which are defined for the first time. |
| 152 |
% |
| 153 |
% There are three ways to define new functions. |
| 154 |
% All classes define a function to expand to the substitution text. |
| 155 |
% Within the substitution text the actual parameters are substituted |
| 156 |
% for the formal parameters (|#1|, |#2|, \ldots). |
| 157 |
% \begin{description} |
| 158 |
% \item[\texttt{new}] |
| 159 |
% Create a new function with the \texttt{new} scope, |
| 160 |
% such as \cs{cs_new:Npn}. The definition is global and results in |
| 161 |
% an error if it is already defined. |
| 162 |
% \item[\texttt{set}] |
| 163 |
% Create a new function with the \texttt{set} scope, |
| 164 |
% such as \cs{cs_set:Npn}. The definition is restricted to the current |
| 165 |
% \TeX{} group and does not result in an error if the function is already |
| 166 |
% defined. |
| 167 |
% \item[\texttt{gset}] |
| 168 |
% Create a new function with the \texttt{gset} scope, |
| 169 |
% such as \cs{cs_gset:Npn}. The definition is global and |
| 170 |
% does not result in an error if the function is already defined. |
| 171 |
% \end{description} |
| 172 |
% |
| 173 |
% Within each set of scope there are different ways to define a function. |
| 174 |
% The differences depend on restrictions on the actual parameters and |
| 175 |
% the expandability of the resulting function. |
| 176 |
% \begin{description} |
| 177 |
% \item[\texttt{nopar}] |
| 178 |
% Create a new function with the \texttt{nopar} restriction, |
| 179 |
% such as \cs{cs_set_nopar:Npn}. The parameter may not contain |
| 180 |
% \cs{par} tokens. |
| 181 |
% \item[\texttt{protected}] |
| 182 |
% Create a new function with the \texttt{protected} restriction, |
| 183 |
% such as \cs{cs_set_protected:Npn}. The parameter may contain |
| 184 |
% \cs{par} tokens but the function will not expand within an |
| 185 |
% \texttt{e}-type or \texttt{x}-type expansion. |
| 186 |
% \end{description} |
| 187 |
% |
| 188 |
% Finally, the functions in |
| 189 |
% Subsections~\ref{sec:l3basics:defining-new-function-1}~and |
| 190 |
% \ref{sec:l3basics:defining-new-function-2} are primarily meant to define |
| 191 |
% \emph{base functions} only. Base functions can only have the following |
| 192 |
% argument specifiers: |
| 193 |
% \begin{description} |
| 194 |
% \item[|N| and |n|] No manipulation. |
| 195 |
% \item[|T| and |F|] Functionally equivalent to |n| (you are actually |
| 196 |
% encouraged to use the family of |\prg_new_conditional:| functions |
| 197 |
% described in Section~\ref{sec:l3prg:new-conditional-functions}). |
| 198 |
% \item[|p| and |w|] These are special cases. |
| 199 |
% \end{description} |
| 200 |
% |
| 201 |
% The |\cs_new:| functions below (and friends) do not stop you from using |
| 202 |
% other argument specifiers in your function names, but they do not handle |
| 203 |
% expansion for you. You should define the base function and then use |
| 204 |
% \cs{cs_generate_variant:Nn} to generate custom variants as described in |
| 205 |
% Section~\ref{sec:l3expan:variants-method}. |
| 206 |
% |
| 207 |
% \subsection{Defining new functions using parameter text} |
| 208 |
% \label{sec:l3basics:defining-new-function-1} |
| 209 |
% |
| 210 |
% \begin{function}[updated = 2023-09-27] |
| 211 |
% { |
| 212 |
% \cs_new:Npn, \cs_new:cpn, |
| 213 |
% \cs_new:Npe, \cs_new:cpe, |
| 214 |
% \cs_new:Npx, \cs_new:cpx |
| 215 |
% } |
| 216 |
% \begin{syntax} |
| 217 |
% \cs{cs_new:Npn} \meta{function} \meta{parameters} \Arg{code} |
| 218 |
% \end{syntax} |
| 219 |
% Creates \meta{function} to expand to \meta{code} as replacement text. |
| 220 |
% Within the \meta{code}, the \meta{parameters} (|#1|, |#2|, |
| 221 |
% etc.) will be replaced by those absorbed by the function. |
| 222 |
% The definition is global and an error results if the |
| 223 |
% \meta{function} is already defined. |
| 224 |
% \end{function} |
| 225 |
% |
| 226 |
% \begin{function}[updated = 2023-09-27] |
| 227 |
% { |
| 228 |
% \cs_new_nopar:Npn, \cs_new_nopar:cpn, |
| 229 |
% \cs_new_nopar:Npe, \cs_new_nopar:cpe, |
| 230 |
% \cs_new_nopar:Npx, \cs_new_nopar:cpx |
| 231 |
% } |
| 232 |
% \begin{syntax} |
| 233 |
% \cs{cs_new_nopar:Npn} \meta{function} \meta{parameters} \Arg{code} |
| 234 |
% \end{syntax} |
| 235 |
% Creates \meta{function} to expand to \meta{code} as replacement text. |
| 236 |
% Within the \meta{code}, the \meta{parameters} (|#1|, |#2|, |
| 237 |
% etc.) will be replaced by those absorbed by the function. |
| 238 |
% When the \meta{function} is used the \meta{parameters} absorbed |
| 239 |
% cannot contain \cs{par} tokens. The definition is global and |
| 240 |
% an error results if the \meta{function} is already defined. |
| 241 |
% \end{function} |
| 242 |
% |
| 243 |
% \begin{function}[updated = 2023-09-27] |
| 244 |
% { |
| 245 |
% \cs_new_protected:Npn, \cs_new_protected:cpn, |
| 246 |
% \cs_new_protected:Npe, \cs_new_protected:cpe, |
| 247 |
% \cs_new_protected:Npx, \cs_new_protected:cpx |
| 248 |
% } |
| 249 |
% \begin{syntax} |
| 250 |
% \cs{cs_new_protected:Npn} \meta{function} \meta{parameters} \Arg{code} |
| 251 |
% \end{syntax} |
| 252 |
% Creates \meta{function} to expand to \meta{code} as replacement text. |
| 253 |
% Within the \meta{code}, the \meta{parameters} (|#1|, |#2|, |
| 254 |
% etc.) will be replaced by those absorbed by the function. |
| 255 |
% The \meta{function} will not expand within an \texttt{e}-type or |
| 256 |
% or \texttt{x}-type |
| 257 |
% argument. The definition is global and an error results if the |
| 258 |
% \meta{function} is already defined. |
| 259 |
% \end{function} |
| 260 |
% |
| 261 |
% \begin{function}[updated = 2023-09-27] |
| 262 |
% { |
| 263 |
% \cs_new_protected_nopar:Npn, \cs_new_protected_nopar:cpn , |
| 264 |
% \cs_new_protected_nopar:Npe, \cs_new_protected_nopar:cpe , |
| 265 |
% \cs_new_protected_nopar:Npx, \cs_new_protected_nopar:cpx |
| 266 |
% } |
| 267 |
% \begin{syntax} |
| 268 |
% \cs{cs_new_protected_nopar:Npn} \meta{function} \meta{parameters} \Arg{code} |
| 269 |
% \end{syntax} |
| 270 |
% Creates \meta{function} to expand to \meta{code} as replacement text. |
| 271 |
% Within the \meta{code}, the \meta{parameters} (|#1|, |#2|, |
| 272 |
% etc.) will be replaced by those absorbed by the function. |
| 273 |
% When the \meta{function} is used the \meta{parameters} absorbed |
| 274 |
% cannot contain \cs{par} tokens. The \meta{function} will not |
| 275 |
% expand within an \texttt{e}-type or \texttt{x}-type argument. The definition is global |
| 276 |
% and an error results if the \meta{function} is already defined. |
| 277 |
% \end{function} |
| 278 |
% |
| 279 |
% \begin{function}[updated = 2023-09-27] |
| 280 |
% { |
| 281 |
% \cs_set:Npn, \cs_set:cpn, |
| 282 |
% \cs_set:Npe, \cs_set:cpe, |
| 283 |
% \cs_set:Npx, \cs_set:cpx |
| 284 |
% } |
| 285 |
% \begin{syntax} |
| 286 |
% \cs{cs_set:Npn} \meta{function} \meta{parameters} \Arg{code} |
| 287 |
% \end{syntax} |
| 288 |
% Sets \meta{function} to expand to \meta{code} as replacement text. |
| 289 |
% Within the \meta{code}, the \meta{parameters} (|#1|, |#2|, |
| 290 |
% etc.) will be replaced by those absorbed by the function. |
| 291 |
% The assignment of a meaning to the \meta{function} is restricted to |
| 292 |
% the current \TeX{} group level. |
| 293 |
% \end{function} |
| 294 |
% |
| 295 |
% \begin{function}[updated = 2023-09-27] |
| 296 |
% { |
| 297 |
% \cs_set_nopar:Npn, \cs_set_nopar:cpn, |
| 298 |
% \cs_set_nopar:Npe, \cs_set_nopar:cpe, |
| 299 |
% \cs_set_nopar:Npx, \cs_set_nopar:cpx |
| 300 |
% } |
| 301 |
% \begin{syntax} |
| 302 |
% \cs{cs_set_nopar:Npn} \meta{function} \meta{parameters} \Arg{code} |
| 303 |
% \end{syntax} |
| 304 |
% Sets \meta{function} to expand to \meta{code} as replacement text. |
| 305 |
% Within the \meta{code}, the \meta{parameters} (|#1|, |#2|, |
| 306 |
% etc.) will be replaced by those absorbed by the function. |
| 307 |
% When the \meta{function} is used the \meta{parameters} absorbed |
| 308 |
% cannot contain \cs{par} tokens. The assignment of a meaning |
| 309 |
% to the \meta{function} is restricted to the current \TeX{} group |
| 310 |
% level. |
| 311 |
% \end{function} |
| 312 |
% |
| 313 |
% \begin{function}[updated = 2023-09-27] |
| 314 |
% { |
| 315 |
% \cs_set_protected:Npn, \cs_set_protected:cpn, |
| 316 |
% \cs_set_protected:Npe, \cs_set_protected:cpe, |
| 317 |
% \cs_set_protected:Npx, \cs_set_protected:cpx |
| 318 |
% } |
| 319 |
% \begin{syntax} |
| 320 |
% \cs{cs_set_protected:Npn} \meta{function} \meta{parameters} \Arg{code} |
| 321 |
% \end{syntax} |
| 322 |
% Sets \meta{function} to expand to \meta{code} as replacement text. |
| 323 |
% Within the \meta{code}, the \meta{parameters} (|#1|, |#2|, |
| 324 |
% etc.) will be replaced by those absorbed by the function. |
| 325 |
% The assignment of a meaning to the \meta{function} is restricted to |
| 326 |
% the current \TeX{} group level. The \meta{function} will |
| 327 |
% not expand within an \texttt{e}-type or \texttt{x}-type argument. |
| 328 |
% \end{function} |
| 329 |
% |
| 330 |
% \begin{function}[updated = 2023-09-27] |
| 331 |
% { |
| 332 |
% \cs_set_protected_nopar:Npn, \cs_set_protected_nopar:cpn , |
| 333 |
% \cs_set_protected_nopar:Npe, \cs_set_protected_nopar:cpe , |
| 334 |
% \cs_set_protected_nopar:Npx, \cs_set_protected_nopar:cpx , |
| 335 |
% } |
| 336 |
% \begin{syntax} |
| 337 |
% \cs{cs_set_protected_nopar:Npn} \meta{function} \meta{parameters} \Arg{code} |
| 338 |
% \end{syntax} |
| 339 |
% Sets \meta{function} to expand to \meta{code} as replacement text. |
| 340 |
% Within the \meta{code}, the \meta{parameters} (|#1|, |#2|, |
| 341 |
% etc.) will be replaced by those absorbed by the function. |
| 342 |
% When the \meta{function} is used the \meta{parameters} absorbed |
| 343 |
% cannot contain \cs{par} tokens. The assignment of a meaning |
| 344 |
% to the \meta{function} is restricted to the current \TeX{} group |
| 345 |
% level. The \meta{function} will not expand within an |
| 346 |
% \texttt{e}-type or \texttt{x}-type argument. |
| 347 |
% \end{function} |
| 348 |
% |
| 349 |
% \begin{function}[updated = 2023-09-27] |
| 350 |
% { |
| 351 |
% \cs_gset:Npn, \cs_gset:cpn, |
| 352 |
% \cs_gset:Npe, \cs_gset:cpe, |
| 353 |
% \cs_gset:Npx, \cs_gset:cpx |
| 354 |
% } |
| 355 |
% \begin{syntax} |
| 356 |
% \cs{cs_gset:Npn} \meta{function} \meta{parameters} \Arg{code} |
| 357 |
% \end{syntax} |
| 358 |
% Globally sets \meta{function} to expand to \meta{code} as replacement |
| 359 |
% text. Within the \meta{code}, the \meta{parameters} (|#1|, |#2|, |
| 360 |
% etc.) will be replaced by those absorbed by the function. |
| 361 |
% The assignment of a meaning to the \meta{function} is \emph{not} |
| 362 |
% restricted to the current \TeX{} group level: the assignment is |
| 363 |
% global. |
| 364 |
% \end{function} |
| 365 |
% |
| 366 |
% \begin{function}[updated = 2023-09-27] |
| 367 |
% { |
| 368 |
% \cs_gset_nopar:Npn, \cs_gset_nopar:cpn, |
| 369 |
% \cs_gset_nopar:Npe, \cs_gset_nopar:cpe, |
| 370 |
% \cs_gset_nopar:Npx, \cs_gset_nopar:cpx |
| 371 |
% } |
| 372 |
% \begin{syntax} |
| 373 |
% \cs{cs_gset_nopar:Npn} \meta{function} \meta{parameters} \Arg{code} |
| 374 |
% \end{syntax} |
| 375 |
% Globally sets \meta{function} to expand to \meta{code} as replacement |
| 376 |
% text. Within the \meta{code}, the \meta{parameters} (|#1|, |#2|, |
| 377 |
% etc.) will be replaced by those absorbed by the function. |
| 378 |
% When the \meta{function} is used the \meta{parameters} absorbed |
| 379 |
% cannot contain \cs{par} tokens. The assignment of a meaning to the |
| 380 |
% \meta{function} is \emph{not} restricted to the current \TeX{} |
| 381 |
% group level: the assignment is global. |
| 382 |
% \end{function} |
| 383 |
% |
| 384 |
% \begin{function}[updated = 2023-09-27] |
| 385 |
% { |
| 386 |
% \cs_gset_protected:Npn, \cs_gset_protected:cpn, |
| 387 |
% \cs_gset_protected:Npe, \cs_gset_protected:cpe, |
| 388 |
% \cs_gset_protected:Npx, \cs_gset_protected:cpx |
| 389 |
% } |
| 390 |
% \begin{syntax} |
| 391 |
% \cs{cs_gset_protected:Npn} \meta{function} \meta{parameters} \Arg{code} |
| 392 |
% \end{syntax} |
| 393 |
% Globally sets \meta{function} to expand to \meta{code} as replacement |
| 394 |
% text. Within the \meta{code}, the \meta{parameters} (|#1|, |#2|, |
| 395 |
% etc.) will be replaced by those absorbed by the function. |
| 396 |
% The assignment of a meaning to the \meta{function} is \emph{not} |
| 397 |
% restricted to the current \TeX{} group level: the assignment is |
| 398 |
% global. The \meta{function} will not expand within an |
| 399 |
% \texttt{e}-type or \texttt{x}-type argument. |
| 400 |
% \end{function} |
| 401 |
% |
| 402 |
% \begin{function}[updated = 2023-09-27] |
| 403 |
% { |
| 404 |
% \cs_gset_protected_nopar:Npn, \cs_gset_protected_nopar:cpn, |
| 405 |
% \cs_gset_protected_nopar:Npe, \cs_gset_protected_nopar:cpe, |
| 406 |
% \cs_gset_protected_nopar:Npx, \cs_gset_protected_nopar:cpx |
| 407 |
% } |
| 408 |
% \begin{syntax} |
| 409 |
% \cs{cs_gset_protected_nopar:Npn} \meta{function} \meta{parameters} \Arg{code} |
| 410 |
% \end{syntax} |
| 411 |
% Globally sets \meta{function} to expand to \meta{code} as replacement |
| 412 |
% text. Within the \meta{code}, the \meta{parameters} (|#1|, |#2|, |
| 413 |
% etc.) will be replaced by those absorbed by the function. |
| 414 |
% When the \meta{function} is used the \meta{parameters} absorbed |
| 415 |
% cannot contain \cs{par} tokens. The assignment of a meaning to the |
| 416 |
% \meta{function} is \emph{not} restricted to the current \TeX{} |
| 417 |
% group level: the assignment is global. The \meta{function} will |
| 418 |
% not expand within an \texttt{e}-type or \texttt{x}-type argument. |
| 419 |
% \end{function} |
| 420 |
% |
| 421 |
% \subsection{Defining new functions using the signature} |
| 422 |
% \label{sec:l3basics:defining-new-function-2} |
| 423 |
% |
| 424 |
% \begin{function}[updated = 2023-09-27] |
| 425 |
% { |
| 426 |
% \cs_new:Nn, \cs_new:cn, |
| 427 |
% \cs_new:Ne, \cs_new:ce |
| 428 |
% } |
| 429 |
% \begin{syntax} |
| 430 |
% \cs{cs_new:Nn} \meta{function} \Arg{code} |
| 431 |
% \end{syntax} |
| 432 |
% Creates \meta{function} to expand to \meta{code} as replacement text. |
| 433 |
% Within the \meta{code}, the number of \meta{parameters} is detected |
| 434 |
% automatically from the function signature. These \meta{parameters} |
| 435 |
% (|#1|, |#2|, etc.) will be replaced by those absorbed by the |
| 436 |
% function. The definition is global and |
| 437 |
% an error results if the \meta{function} is already defined. |
| 438 |
% \end{function} |
| 439 |
% |
| 440 |
% \begin{function}[updated = 2023-09-27] |
| 441 |
% { |
| 442 |
% \cs_new_nopar:Nn, \cs_new_nopar:cn, |
| 443 |
% \cs_new_nopar:Ne, \cs_new_nopar:ce |
| 444 |
% } |
| 445 |
% \begin{syntax} |
| 446 |
% \cs{cs_new_nopar:Nn} \meta{function} \Arg{code} |
| 447 |
% \end{syntax} |
| 448 |
% Creates \meta{function} to expand to \meta{code} as replacement text. |
| 449 |
% Within the \meta{code}, the number of \meta{parameters} is detected |
| 450 |
% automatically from the function signature. These \meta{parameters} |
| 451 |
% (|#1|, |#2|, etc.) will be replaced by those absorbed by the |
| 452 |
% function. When the \meta{function} is used the \meta{parameters} |
| 453 |
% absorbed cannot contain \cs{par} tokens. The definition is global and |
| 454 |
% an error results if the \meta{function} is already defined. |
| 455 |
% \end{function} |
| 456 |
% |
| 457 |
% \begin{function}[updated = 2023-09-27] |
| 458 |
% { |
| 459 |
% \cs_new_protected:Nn, \cs_new_protected:cn, |
| 460 |
% \cs_new_protected:Ne, \cs_new_protected:ce |
| 461 |
% } |
| 462 |
% \begin{syntax} |
| 463 |
% \cs{cs_new_protected:Nn} \meta{function} \Arg{code} |
| 464 |
% \end{syntax} |
| 465 |
% Creates \meta{function} to expand to \meta{code} as replacement text. |
| 466 |
% Within the \meta{code}, the number of \meta{parameters} is detected |
| 467 |
% automatically from the function signature. These \meta{parameters} |
| 468 |
% (|#1|, |#2|, etc.) will be replaced by those absorbed by the |
| 469 |
% function. The \meta{function} will not expand within an \texttt{e}-type |
| 470 |
% or \texttt{x}-type argument. The definition is global and |
| 471 |
% an error results if the \meta{function} is already defined. |
| 472 |
% \end{function} |
| 473 |
% |
| 474 |
% \begin{function}[updated = 2023-09-27] |
| 475 |
% { |
| 476 |
% \cs_new_protected_nopar:Nn, \cs_new_protected_nopar:cn, |
| 477 |
% \cs_new_protected_nopar:Ne, \cs_new_protected_nopar:ce |
| 478 |
% } |
| 479 |
% \begin{syntax} |
| 480 |
% \cs{cs_new_protected_nopar:Nn} \meta{function} \Arg{code} |
| 481 |
% \end{syntax} |
| 482 |
% Creates \meta{function} to expand to \meta{code} as replacement text. |
| 483 |
% Within the \meta{code}, the number of \meta{parameters} is detected |
| 484 |
% automatically from the function signature. These \meta{parameters} |
| 485 |
% (|#1|, |#2|, etc.) will be replaced by those absorbed by the |
| 486 |
% function. When the \meta{function} is used the \meta{parameters} |
| 487 |
% absorbed cannot contain \cs{par} tokens. The \meta{function} will not |
| 488 |
% expand within an \texttt{e}-type or \texttt{x}-type argument. The definition is global and |
| 489 |
% an error results if the \meta{function} is already defined. |
| 490 |
% \end{function} |
| 491 |
% |
| 492 |
% \begin{function}[updated = 2023-09-27] |
| 493 |
% { |
| 494 |
% \cs_set:Nn, \cs_set:cn, |
| 495 |
% \cs_set:Ne, \cs_set:ce |
| 496 |
% } |
| 497 |
% \begin{syntax} |
| 498 |
% \cs{cs_set:Nn} \meta{function} \Arg{code} |
| 499 |
% \end{syntax} |
| 500 |
% Sets \meta{function} to expand to \meta{code} as replacement text. |
| 501 |
% Within the \meta{code}, the number of \meta{parameters} is detected |
| 502 |
% automatically from the function signature. These \meta{parameters} |
| 503 |
% (|#1|, |#2|, etc.) will be replaced by those absorbed by the |
| 504 |
% function. |
| 505 |
% The assignment of a meaning to the \meta{function} is restricted to |
| 506 |
% the current \TeX{} group level. |
| 507 |
% \end{function} |
| 508 |
% |
| 509 |
% \begin{function}[updated = 2023-09-27] |
| 510 |
% { |
| 511 |
% \cs_set_nopar:Nn, \cs_set_nopar:cn, |
| 512 |
% \cs_set_nopar:Ne, \cs_set_nopar:ce |
| 513 |
% } |
| 514 |
% \begin{syntax} |
| 515 |
% \cs{cs_set_nopar:Nn} \meta{function} \Arg{code} |
| 516 |
% \end{syntax} |
| 517 |
% Sets \meta{function} to expand to \meta{code} as replacement text. |
| 518 |
% Within the \meta{code}, the number of \meta{parameters} is detected |
| 519 |
% automatically from the function signature. These \meta{parameters} |
| 520 |
% (|#1|, |#2|, etc.) will be replaced by those absorbed by the |
| 521 |
% function. When the \meta{function} is used the \meta{parameters} |
| 522 |
% absorbed cannot contain \cs{par} tokens. |
| 523 |
% The assignment of a meaning to the \meta{function} is restricted to |
| 524 |
% the current \TeX{} group level. |
| 525 |
% \end{function} |
| 526 |
% |
| 527 |
% \begin{function}[updated = 2023-09-27] |
| 528 |
% { |
| 529 |
% \cs_set_protected:Nn, \cs_set_protected:cn, |
| 530 |
% \cs_set_protected:Ne, \cs_set_protected:ce |
| 531 |
% } |
| 532 |
% \begin{syntax} |
| 533 |
% \cs{cs_set_protected:Nn} \meta{function} \Arg{code} |
| 534 |
% \end{syntax} |
| 535 |
% Sets \meta{function} to expand to \meta{code} as replacement text. |
| 536 |
% Within the \meta{code}, the number of \meta{parameters} is detected |
| 537 |
% automatically from the function signature. These \meta{parameters} |
| 538 |
% (|#1|, |#2|, etc.) will be replaced by those absorbed by the |
| 539 |
% function. The \meta{function} will not expand within an \texttt{e}-type |
| 540 |
% or \texttt{x}-type argument. |
| 541 |
% The assignment of a meaning to the \meta{function} is restricted to |
| 542 |
% the current \TeX{} group level. |
| 543 |
% \end{function} |
| 544 |
% |
| 545 |
% \begin{function}[updated = 2023-09-27] |
| 546 |
% { |
| 547 |
% \cs_set_protected_nopar:Nn, \cs_set_protected_nopar:cn, |
| 548 |
% \cs_set_protected_nopar:Ne, \cs_set_protected_nopar:ce |
| 549 |
% } |
| 550 |
% \begin{syntax} |
| 551 |
% \cs{cs_set_protected_nopar:Nn} \meta{function} \Arg{code} |
| 552 |
% \end{syntax} |
| 553 |
% Sets \meta{function} to expand to \meta{code} as replacement text. |
| 554 |
% Within the \meta{code}, the number of \meta{parameters} is detected |
| 555 |
% automatically from the function signature. These \meta{parameters} |
| 556 |
% (|#1|, |#2|, etc.) will be replaced by those absorbed by the |
| 557 |
% function. When the \meta{function} is used the \meta{parameters} |
| 558 |
% absorbed cannot contain \cs{par} tokens. The \meta{function} will not |
| 559 |
% expand within an \texttt{e}-type or \texttt{x}-type argument. |
| 560 |
% The assignment of a meaning to the \meta{function} is restricted to |
| 561 |
% the current \TeX{} group level. |
| 562 |
% \end{function} |
| 563 |
% |
| 564 |
% \begin{function}[updated = 2023-09-27] |
| 565 |
% { |
| 566 |
% \cs_gset:Nn, \cs_gset:cn, |
| 567 |
% \cs_gset:Ne, \cs_gset:ce |
| 568 |
% } |
| 569 |
% \begin{syntax} |
| 570 |
% \cs{cs_gset:Nn} \meta{function} \Arg{code} |
| 571 |
% \end{syntax} |
| 572 |
% Sets \meta{function} to expand to \meta{code} as replacement text. |
| 573 |
% Within the \meta{code}, the number of \meta{parameters} is detected |
| 574 |
% automatically from the function signature. These \meta{parameters} |
| 575 |
% (|#1|, |#2|, etc.) will be replaced by those absorbed by the |
| 576 |
% function. |
| 577 |
% The assignment of a meaning to the \meta{function} is global. |
| 578 |
% \end{function} |
| 579 |
% |
| 580 |
% \begin{function}[updated = 2023-09-27] |
| 581 |
% { |
| 582 |
% \cs_gset_nopar:Nn, \cs_gset_nopar:cn, |
| 583 |
% \cs_gset_nopar:Ne, \cs_gset_nopar:ce |
| 584 |
% } |
| 585 |
% \begin{syntax} |
| 586 |
% \cs{cs_gset_nopar:Nn} \meta{function} \Arg{code} |
| 587 |
% \end{syntax} |
| 588 |
% Sets \meta{function} to expand to \meta{code} as replacement text. |
| 589 |
% Within the \meta{code}, the number of \meta{parameters} is detected |
| 590 |
% automatically from the function signature. These \meta{parameters} |
| 591 |
% (|#1|, |#2|, etc.) will be replaced by those absorbed by the |
| 592 |
% function. When the \meta{function} is used the \meta{parameters} |
| 593 |
% absorbed cannot contain \cs{par} tokens. |
| 594 |
% The assignment of a meaning to the \meta{function} is global. |
| 595 |
% \end{function} |
| 596 |
% |
| 597 |
% \begin{function}[updated = 2023-09-27] |
| 598 |
% { |
| 599 |
% \cs_gset_protected:Nn, \cs_gset_protected:cn, |
| 600 |
% \cs_gset_protected:Ne, \cs_gset_protected:ce |
| 601 |
% } |
| 602 |
% \begin{syntax} |
| 603 |
% \cs{cs_gset_protected:Nn} \meta{function} \Arg{code} |
| 604 |
% \end{syntax} |
| 605 |
% Sets \meta{function} to expand to \meta{code} as replacement text. |
| 606 |
% Within the \meta{code}, the number of \meta{parameters} is detected |
| 607 |
% automatically from the function signature. These \meta{parameters} |
| 608 |
% (|#1|, |#2|, etc.) will be replaced by those absorbed by the |
| 609 |
% function. The \meta{function} will not expand within an \texttt{e}-type |
| 610 |
% or \texttt{x}-type argument. |
| 611 |
% The assignment of a meaning to the \meta{function} is global. |
| 612 |
% \end{function} |
| 613 |
% |
| 614 |
% \begin{function}[updated = 2023-09-27] |
| 615 |
% { |
| 616 |
% \cs_gset_protected_nopar:Nn, \cs_gset_protected_nopar:cn, |
| 617 |
% \cs_gset_protected_nopar:Ne, \cs_gset_protected_nopar:ce |
| 618 |
% } |
| 619 |
% \begin{syntax} |
| 620 |
% \cs{cs_gset_protected_nopar:Nn} \meta{function} \Arg{code} |
| 621 |
% \end{syntax} |
| 622 |
% Sets \meta{function} to expand to \meta{code} as replacement text. |
| 623 |
% Within the \meta{code}, the number of \meta{parameters} is detected |
| 624 |
% automatically from the function signature. These \meta{parameters} |
| 625 |
% (|#1|, |#2|, etc.) will be replaced by those absorbed by the |
| 626 |
% function. When the \meta{function} is used the \meta{parameters} |
| 627 |
% absorbed cannot contain \cs{par} tokens. The \meta{function} will not |
| 628 |
% expand within an \texttt{e}-type or \texttt{x}-type argument. |
| 629 |
% The assignment of a meaning to the \meta{function} is global. |
| 630 |
% \end{function} |
| 631 |
% |
| 632 |
% \begin{function}[updated = 2012-01-14] |
| 633 |
% { |
| 634 |
% \cs_generate_from_arg_count:NNnn, |
| 635 |
% \cs_generate_from_arg_count:NNno, |
| 636 |
% \cs_generate_from_arg_count:cNnn, |
| 637 |
% \cs_generate_from_arg_count:Ncnn |
| 638 |
% } |
| 639 |
% \begin{syntax} |
| 640 |
% \cs{cs_generate_from_arg_count:NNnn} \meta{function} \meta{creator} \Arg{number} \Arg{code} |
| 641 |
% \end{syntax} |
| 642 |
% Uses the \meta{creator} function (which should have signature |
| 643 |
% |Npn|, for example \cs{cs_new:Npn}) to define a \meta{function} |
| 644 |
% which takes \meta{number} arguments and has \meta{code} as |
| 645 |
% replacement text. The \meta{number} of arguments is an integer expression, |
| 646 |
% evaluated as detailed for \cs{int_eval:n}. |
| 647 |
% \end{function} |
| 648 |
% |
| 649 |
% \subsection{Copying control sequences} |
| 650 |
% |
| 651 |
% Control sequences (not just functions as defined above) can |
| 652 |
% be set to have the same meaning using the functions described |
| 653 |
% here. Making two control sequences equivalent means that the |
| 654 |
% second control sequence is a \emph{copy} of the first (rather than |
| 655 |
% a pointer to it). Thus the old and new control sequence are not |
| 656 |
% tied together: changes to one are not reflected in the other. |
| 657 |
% |
| 658 |
% In the following text \enquote{cs} is used as an abbreviation for |
| 659 |
% \enquote{control sequence}. |
| 660 |
% |
| 661 |
% \begin{function} |
| 662 |
% {\cs_new_eq:NN, \cs_new_eq:Nc, \cs_new_eq:cN, \cs_new_eq:cc} |
| 663 |
% \begin{syntax} |
| 664 |
% \cs{cs_new_eq:NN} \meta{cs_1} \meta{cs_2} |
| 665 |
% \cs{cs_new_eq:NN} \meta{cs_1} \meta{token} |
| 666 |
% \end{syntax} |
| 667 |
% Globally creates \meta{control sequence_1} and sets it to have the same |
| 668 |
% meaning as \meta{control sequence_2} or <token>. |
| 669 |
% The second control sequence may |
| 670 |
% subsequently be altered without affecting the copy. |
| 671 |
% \end{function} |
| 672 |
% |
| 673 |
% \begin{function} |
| 674 |
% {\cs_set_eq:NN, \cs_set_eq:Nc, \cs_set_eq:cN, \cs_set_eq:cc} |
| 675 |
% \begin{syntax} |
| 676 |
% \cs{cs_set_eq:NN} \meta{cs_1} \meta{cs_2} |
| 677 |
% \cs{cs_set_eq:NN} \meta{cs_1} \meta{token} |
| 678 |
% \end{syntax} |
| 679 |
% Sets \meta{control sequence_1} to have the same meaning as |
| 680 |
% \meta{control sequence_2} (or <token>). |
| 681 |
% The second control sequence may subsequently be |
| 682 |
% altered without affecting the copy. The assignment of a meaning |
| 683 |
% to the \meta{control sequence_1} is restricted to the current |
| 684 |
% \TeX{} group level. |
| 685 |
% \end{function} |
| 686 |
% |
| 687 |
% \begin{function} |
| 688 |
% {\cs_gset_eq:NN, \cs_gset_eq:Nc, \cs_gset_eq:cN, \cs_gset_eq:cc} |
| 689 |
% \begin{syntax} |
| 690 |
% \cs{cs_gset_eq:NN} \meta{cs_1} \meta{cs_2} |
| 691 |
% \cs{cs_gset_eq:NN} \meta{cs_1} \meta{token} |
| 692 |
% \end{syntax} |
| 693 |
% Globally sets \meta{control sequence_1} to have the same meaning as |
| 694 |
% \meta{control sequence_2} (or <token>). |
| 695 |
% The second control sequence may subsequently be |
| 696 |
% altered without affecting the copy. The assignment of a meaning to |
| 697 |
% the \meta{control sequence_1} is \emph{not} restricted to the current |
| 698 |
% \TeX{} group level: the assignment is global. |
| 699 |
% \end{function} |
| 700 |
% |
| 701 |
% \subsection{Deleting control sequences} |
| 702 |
% |
| 703 |
% There are occasions where control sequences need to be deleted. |
| 704 |
% This is handled in a very simple manner. |
| 705 |
% |
| 706 |
% \begin{function}[updated = 2011-09-15]{\cs_undefine:N, \cs_undefine:c} |
| 707 |
% \begin{syntax} |
| 708 |
% \cs{cs_undefine:N} \meta{control sequence} |
| 709 |
% \end{syntax} |
| 710 |
% Sets \meta{control sequence} to be globally undefined. |
| 711 |
% \end{function} |
| 712 |
% |
| 713 |
% \subsection{Showing control sequences} |
| 714 |
% |
| 715 |
% \begin{function}[EXP, updated = 2011-12-22]{\cs_meaning:N, \cs_meaning:c} |
| 716 |
% \begin{syntax} |
| 717 |
% \cs{cs_meaning:N} \meta{control sequence} |
| 718 |
% \end{syntax} |
| 719 |
% This function expands to the \emph{meaning} of the \meta{control sequence} |
| 720 |
% control sequence. For a macro, this includes the \meta{replacement text}. |
| 721 |
% \begin{texnote} |
| 722 |
% This is the \TeX{} primitive \tn{meaning}. |
| 723 |
% For tokens that are not control sequences, it is more logical to |
| 724 |
% use \cs{token_to_meaning:N}. |
| 725 |
% The \texttt{c} variant correctly reports undefined arguments. |
| 726 |
% \end{texnote} |
| 727 |
% \end{function} |
| 728 |
% |
| 729 |
% \begin{function}[updated = 2017-02-14]{\cs_show:N, \cs_show:c} |
| 730 |
% \begin{syntax} |
| 731 |
% \cs{cs_show:N} \meta{control sequence} |
| 732 |
% \end{syntax} |
| 733 |
% Displays the definition of the \meta{control sequence} on the |
| 734 |
% terminal. |
| 735 |
% \begin{texnote} |
| 736 |
% This is similar to the \TeX{} primitive \tn{show}, wrapped to a |
| 737 |
% fixed number of characters per line. |
| 738 |
% \end{texnote} |
| 739 |
% \end{function} |
| 740 |
% |
| 741 |
% \begin{function}[added = 2014-08-22, updated = 2017-02-14]{\cs_log:N, \cs_log:c} |
| 742 |
% \begin{syntax} |
| 743 |
% \cs{cs_log:N} \meta{control sequence} |
| 744 |
% \end{syntax} |
| 745 |
% Writes the definition of the \meta{control sequence} in the log |
| 746 |
% file. See also \cs{cs_show:N} which displays the result in the |
| 747 |
% terminal. |
| 748 |
% \end{function} |
| 749 |
% |
| 750 |
% \subsection{Converting to and from control sequences} |
| 751 |
% |
| 752 |
% \begin{function}[EXP]{\use:c} |
| 753 |
% \begin{syntax} |
| 754 |
% \cs{use:c} \Arg{control sequence name} |
| 755 |
% \end{syntax} |
| 756 |
% Expands the \meta{control sequence name} until only characters |
| 757 |
% remain, and then converts this into a control sequence. This process |
| 758 |
% requires two expansions. As in other \texttt{c}-type arguments the |
| 759 |
% \meta{control sequence name} must, when fully expanded, consist of |
| 760 |
% character tokens, typically a mixture of category code $10$ (space), |
| 761 |
% $11$ (letter) and $12$ (other). |
| 762 |
% \end{function} |
| 763 |
% |
| 764 |
% As an example of the \cs{use:c} function, both |
| 765 |
% \begin{verbatim} |
| 766 |
% \use:c { a b c } |
| 767 |
% \end{verbatim} |
| 768 |
% and |
| 769 |
% \begin{verbatim} |
| 770 |
% \tl_new:N \l_my_tl |
| 771 |
% \tl_set:Nn \l_my_tl { a b c } |
| 772 |
% \use:c { \tl_use:N \l_my_tl } |
| 773 |
% \end{verbatim} |
| 774 |
% would be equivalent to |
| 775 |
% \begin{verbatim} |
| 776 |
% \abc |
| 777 |
% \end{verbatim} |
| 778 |
% after two expansions of \cs{use:c}. |
| 779 |
% |
| 780 |
% \begin{function}[noTF, EXP, added = 2011-10-10] |
| 781 |
% {\cs_if_exist_use:N, \cs_if_exist_use:c} |
| 782 |
% \begin{syntax} |
| 783 |
% \cs{cs_if_exist_use:N} \meta{control sequence} |
| 784 |
% \cs{cs_if_exist_use:NTF} \meta{control sequence} \Arg{true code} \Arg{false code} |
| 785 |
% \end{syntax} |
| 786 |
% Tests whether the \meta{control sequence} is currently defined |
| 787 |
% according to the conditional \cs{cs_if_exist:NTF} |
| 788 |
% (whether as a function or another control sequence type), and if it |
| 789 |
% is inserts the \meta{control sequence} into the input stream followed |
| 790 |
% by the \meta{true code}. Otherwise the \meta{false code} is used. |
| 791 |
% \end{function} |
| 792 |
% |
| 793 |
% \begin{function}[EXP]{\cs:w, \cs_end:} |
| 794 |
% \begin{syntax} |
| 795 |
% \cs{cs:w} \meta{control sequence name} \cs{cs_end:} |
| 796 |
% \end{syntax} |
| 797 |
% Converts the given \meta{control sequence name} into a single |
| 798 |
% control sequence token. This process requires one expansion. |
| 799 |
% The content for \meta{control sequence name} may be literal |
| 800 |
% material or from other expandable functions. The |
| 801 |
% \meta{control sequence name} must, when fully expanded, consist |
| 802 |
% of character tokens which are not active: typically |
| 803 |
% of category code $10$ (space), $11$ (letter) |
| 804 |
% or $12$ (other), or a mixture of these. |
| 805 |
% \begin{texnote} |
| 806 |
% These are the \TeX{} primitives \tn{csname} and \tn{endcsname}. |
| 807 |
% \end{texnote} |
| 808 |
% \end{function} |
| 809 |
% |
| 810 |
% As an example of the \cs{cs:w} and \cs{cs_end:} functions, both |
| 811 |
% \begin{verbatim} |
| 812 |
% \cs:w a b c \cs_end: |
| 813 |
% \end{verbatim} |
| 814 |
% and |
| 815 |
% \begin{verbatim} |
| 816 |
% \tl_new:N \l_my_tl |
| 817 |
% \tl_set:Nn \l_my_tl { a b c } |
| 818 |
% \cs:w \tl_use:N \l_my_tl \cs_end: |
| 819 |
% \end{verbatim} |
| 820 |
% would be equivalent to |
| 821 |
% \begin{verbatim} |
| 822 |
% \abc |
| 823 |
% \end{verbatim} |
| 824 |
% after one expansion of \cs{cs:w}. |
| 825 |
% |
| 826 |
% \begin{function}[EXP]{\cs_to_str:N} |
| 827 |
% \begin{syntax} |
| 828 |
% \cs{cs_to_str:N} \meta{control sequence} |
| 829 |
% \end{syntax} |
| 830 |
% Converts the given \meta{control sequence} into a series of |
| 831 |
% characters with category code $12$ (other), except spaces, |
| 832 |
% of category code $10$. The result does \emph{not} include |
| 833 |
% the current escape token, contrarily to \cs{token_to_str:N}. |
| 834 |
% Full expansion of this function requires exactly $2$ expansion |
| 835 |
% steps, and so an \texttt{e}-type or \texttt{x}-type expansion, or two |
| 836 |
% \texttt{o}-type expansions are required to |
| 837 |
% convert the \meta{control sequence} to a sequence of characters |
| 838 |
% in the input stream. In most cases, an \texttt{f}-expansion |
| 839 |
% is correct as well, but this loses a space at the start |
| 840 |
% of the result. |
| 841 |
% \end{function} |
| 842 |
% |
| 843 |
% \section{Analyzing control sequences} |
| 844 |
% |
| 845 |
% \begin{function}[EXP, added = 2018-04-06]{\cs_split_function:N} |
| 846 |
% \begin{syntax} |
| 847 |
% \cs{cs_split_function:N} \meta{function} |
| 848 |
% \end{syntax} |
| 849 |
% Splits the \meta{function} into the \meta{name} (i.e., the part |
| 850 |
% before the colon) and the \meta{signature} (i.e., after the colon). |
| 851 |
% This information is then placed in the input stream |
| 852 |
% in three parts: the \meta{name}, the |
| 853 |
% \meta{signature} and a logic token indicating if a colon was found |
| 854 |
% (to differentiate variables from function names). The \meta{name} |
| 855 |
% does not include the escape character, and both the \meta{name} and |
| 856 |
% \meta{signature} are made up of tokens with category code $12$ |
| 857 |
% (other). |
| 858 |
% \end{function} |
| 859 |
% |
| 860 |
% The next three functions decompose \TeX{} macros into their |
| 861 |
% constituent parts: if the \meta{token} passed is not a macro then no |
| 862 |
% decomposition can occur. In the latter case, all three functions leave |
| 863 |
% \cs{scan_stop:} in the input stream. |
| 864 |
% |
| 865 |
% \begin{function}[EXP, added = 2019-02-27]{\cs_prefix_spec:N} |
| 866 |
% \begin{syntax} |
| 867 |
% \cs{cs_prefix_spec:N} \meta{token} |
| 868 |
% \end{syntax} |
| 869 |
% If the \meta{token} is a macro, this function leaves the applicable |
| 870 |
% \TeX{} prefixes in input stream as a string of tokens of category |
| 871 |
% code $12$ (with spaces having category code $10$). Thus for example |
| 872 |
% \begin{verbatim} |
| 873 |
% \cs_set:Npn \next:nn #1#2 { x #1~y #2 } |
| 874 |
% \cs_prefix_spec:N \next:nn |
| 875 |
% \end{verbatim} |
| 876 |
% leaves |\long| in the input stream. If the \meta{token} is |
| 877 |
% not a macro then \cs{scan_stop:} is left in the input stream. |
| 878 |
% \begin{texnote} |
| 879 |
% The prefix can be empty, |\long|, |\protected| or |
| 880 |
% |\protected\long| with backslash replaced by the current escape |
| 881 |
% character. |
| 882 |
% \end{texnote} |
| 883 |
% \end{function} |
| 884 |
% |
| 885 |
% \begin{function}[EXP, added = 2022-06-24]{\cs_parameter_spec:N} |
| 886 |
% \begin{syntax} |
| 887 |
% \cs{cs_parameter_spec:N} \meta{token} |
| 888 |
% \end{syntax} |
| 889 |
% If the \meta{token} is a macro, this function leaves the primitive |
| 890 |
% \TeX{} parameter specification in input stream as a string of |
| 891 |
% character tokens of category code $12$ (with spaces having category |
| 892 |
% code $10$). Thus for example |
| 893 |
% \begin{verbatim} |
| 894 |
% \cs_set:Npn \next:nn #1#2 { x #1 y #2 } |
| 895 |
% \cs_parameter_spec:N \next:nn |
| 896 |
% \end{verbatim} |
| 897 |
% leaves |#1#2| in the input stream. If the \meta{token} is |
| 898 |
% not a macro then \cs{scan_stop:} is left in the input stream. |
| 899 |
% \begin{texnote} |
| 900 |
% If the parameter specification contains the string |->|, then the |
| 901 |
% function produces incorrect results. |
| 902 |
% \end{texnote} |
| 903 |
% \end{function} |
| 904 |
% |
| 905 |
% \begin{function}[EXP, added = 2019-02-27]{\cs_replacement_spec:N, \cs_replacement_spec:c} |
| 906 |
% \begin{syntax} |
| 907 |
% \cs{cs_replacement_spec:N} \meta{token} |
| 908 |
% \end{syntax} |
| 909 |
% If the \meta{token} is a macro, this function leaves the replacement |
| 910 |
% text in input stream as a string of character tokens of category |
| 911 |
% code $12$ (with spaces having category code $10$). Thus for example |
| 912 |
% \begin{verbatim} |
| 913 |
% \cs_set:Npn \next:nn #1#2 { x #1~y #2 } |
| 914 |
% \cs_replacement_spec:N \next:nn |
| 915 |
% \end{verbatim} |
| 916 |
% leaves \verb*|x#1 y#2| in the input stream. If the \meta{token} is |
| 917 |
% not a macro then \cs{scan_stop:} is left in the input stream. |
| 918 |
% \begin{texnote} |
| 919 |
% If the parameter specification contains the string |->|, then the |
| 920 |
% function produces incorrect results. |
| 921 |
% \end{texnote} |
| 922 |
% \end{function} |
| 923 |
% |
| 924 |
% \section{Using or removing tokens and arguments} |
| 925 |
% |
| 926 |
% Tokens in the input can be read and used or read and discarded. |
| 927 |
% If one or more tokens are wrapped in braces then when absorbing them |
| 928 |
% the outer set is removed. At the same time, the category code |
| 929 |
% of each token is set when the token is read by a function (if it |
| 930 |
% is read more than once, the category code is determined by |
| 931 |
% the situation in force when first function absorbs the token). |
| 932 |
% |
| 933 |
% \begin{function}[EXP]{\use:n, \use:nn, \use:nnn, \use:nnnn} |
| 934 |
% \begin{syntax} |
| 935 |
% \cs{use:n} \Arg{group_1} |
| 936 |
% \cs{use:nn} \Arg{group_1} \Arg{group_2} |
| 937 |
% \cs{use:nnn} \Arg{group_1} \Arg{group_2} \Arg{group_3} |
| 938 |
% \cs{use:nnnn} \Arg{group_1} \Arg{group_2} \Arg{group_3} \Arg{group_4} |
| 939 |
% \end{syntax} |
| 940 |
% As illustrated, these functions absorb between one and four |
| 941 |
% arguments, as indicated by the argument specifier. The braces |
| 942 |
% surrounding each argument are removed and the remaining tokens are |
| 943 |
% left in the input stream. The category code of these tokens is |
| 944 |
% also fixed by this process (if it has not already been by some |
| 945 |
% other absorption). All of these functions require only a single |
| 946 |
% expansion to operate, so that one expansion of |
| 947 |
% \begin{verbatim} |
| 948 |
% \use:nn { abc } { { def } } |
| 949 |
% \end{verbatim} |
| 950 |
% results in the input stream containing |
| 951 |
% \begin{verbatim} |
| 952 |
% abc { def } |
| 953 |
% \end{verbatim} |
| 954 |
% i.e. only the outer braces are removed. |
| 955 |
% \begin{texnote} |
| 956 |
% The \cs{use:n} function is equivalent to \LaTeXe{}'s \tn{@firstofone}. |
| 957 |
% \end{texnote} |
| 958 |
% \end{function} |
| 959 |
% |
| 960 |
% \begin{function}[EXP] |
| 961 |
% { |
| 962 |
% \use_i:nn, \use_ii:nn , |
| 963 |
% \use_i:nnn , \use_ii:nnn , \use_iii:nnn , |
| 964 |
% \use_i:nnnn, \use_ii:nnnn, \use_iii:nnnn, \use_iv:nnnn , |
| 965 |
% \use_i:nnnnn, \use_ii:nnnnn, \use_iii:nnnnn, \use_iv:nnnnn , |
| 966 |
% \use_v:nnnnn , |
| 967 |
% \use_i:nnnnnn, \use_ii:nnnnnn, \use_iii:nnnnnn, \use_iv:nnnnnn , |
| 968 |
% \use_v:nnnnnn , \use_vi:nnnnnn , |
| 969 |
% \use_i:nnnnnnn, \use_ii:nnnnnnn, \use_iii:nnnnnnn, \use_iv:nnnnnnn , |
| 970 |
% \use_v:nnnnnnn , \use_vi:nnnnnnn , \use_vii:nnnnnnn , |
| 971 |
% \use_i:nnnnnnnn, \use_ii:nnnnnnnn, \use_iii:nnnnnnnn, \use_iv:nnnnnnnn , |
| 972 |
% \use_v:nnnnnnnn , \use_vi:nnnnnnnn , \use_vii:nnnnnnnn , \use_viii:nnnnnnnn , |
| 973 |
% \use_i:nnnnnnnnn, \use_ii:nnnnnnnnn, \use_iii:nnnnnnnnn, \use_iv:nnnnnnnnn , |
| 974 |
% \use_v:nnnnnnnnn , \use_vi:nnnnnnnnn , \use_vii:nnnnnnnnn , \use_viii:nnnnnnnnn , |
| 975 |
% \use_ix:nnnnnnnnn |
| 976 |
% } |
| 977 |
% \begin{syntax} |
| 978 |
% \cs{use_i:nn} \Arg{arg_1} \Arg{arg_2} |
| 979 |
% \cs{use_i:nnn} \Arg{arg_1} \Arg{arg_2} \Arg{arg_3} |
| 980 |
% \cs{use_i:nnnn} \Arg{arg_1} \Arg{arg_2} \Arg{arg_3} \Arg{arg_4} |
| 981 |
% \cs{use_i:nnnnn} \Arg{arg_1} \Arg{arg_2} \Arg{arg_3} \Arg{arg_4} \Arg{arg_5} |
| 982 |
% \cs{use_i:nnnnnn} \Arg{arg_1} \Arg{arg_2} \Arg{arg_3} \Arg{arg_4} \Arg{arg_5} \Arg{arg_6} |
| 983 |
% \cs{use_i:nnnnnnn} \Arg{arg_1} \Arg{arg_2} \Arg{arg_3} \Arg{arg_4} \Arg{arg_5} \Arg{arg_6} \Arg{arg_7} |
| 984 |
% \cs{use_i:nnnnnnnn} \Arg{arg_1} \Arg{arg_2} \Arg{arg_3} \Arg{arg_4} \Arg{arg_5} \Arg{arg_6} \Arg{arg_7} \Arg{arg_8} |
| 985 |
% \cs{use_i:nnnnnnnnn} \Arg{arg_1} \Arg{arg_2} \Arg{arg_3} \Arg{arg_4} \Arg{arg_5} \Arg{arg_6} \Arg{arg_7} \Arg{arg_8} \Arg{arg_9} |
| 986 |
% \end{syntax} |
| 987 |
% These functions absorb a number ($n$) arguments from the input stream. |
| 988 |
% They then discard all arguments other than that indicated by the roman |
| 989 |
% numeral, which is left in the input stream. For example, \cs{use_i:nn} |
| 990 |
% discards the second argument, and leaves the content of the first |
| 991 |
% argument in the input stream. |
| 992 |
% The category code |
| 993 |
% of these tokens is also fixed (if it has not already been by |
| 994 |
% some other absorption). A single expansion is needed for the |
| 995 |
% functions to take effect. |
| 996 |
% \end{function} |
| 997 |
% |
| 998 |
% \begin{function}[EXP]{\use_i_ii:nnn} |
| 999 |
% \begin{syntax} |
| 1000 |
% \cs{use_i_ii:nnn} \Arg{arg_1} \Arg{arg_2} \Arg{arg_3} |
| 1001 |
% \end{syntax} |
| 1002 |
% This function absorbs three arguments and leaves the content of the |
| 1003 |
% first and second in the input stream. The category code of |
| 1004 |
% these tokens is also fixed (if it has not already been by |
| 1005 |
% some other absorption). A single expansion is needed for the |
| 1006 |
% function to take effect. An example: |
| 1007 |
% \begin{verbatim} |
| 1008 |
% \use_i_ii:nnn { abc } { { def } } { ghi } |
| 1009 |
% \end{verbatim} |
| 1010 |
% results in the input stream containing |
| 1011 |
% \begin{verbatim} |
| 1012 |
% abc { def } |
| 1013 |
% \end{verbatim} |
| 1014 |
% i.e. the outer braces are removed and the third group |
| 1015 |
% is removed. |
| 1016 |
% \end{function} |
| 1017 |
% |
| 1018 |
% \begin{function}[EXP, added = 2019-06-02]{\use_ii_i:nn} |
| 1019 |
% \begin{syntax} |
| 1020 |
% \cs{use_ii_i:nn} \Arg{arg_1} \Arg{arg_2} |
| 1021 |
% \end{syntax} |
| 1022 |
% This function absorbs two arguments and leaves the content of the |
| 1023 |
% second and first in the input stream. The category code of |
| 1024 |
% these tokens is also fixed (if it has not already been by |
| 1025 |
% some other absorption). A single expansion is needed for the |
| 1026 |
% function to take effect. |
| 1027 |
% \end{function} |
| 1028 |
% |
| 1029 |
% \begin{function}[EXP] |
| 1030 |
% { |
| 1031 |
% \use_none:n , |
| 1032 |
% \use_none:nn , |
| 1033 |
% \use_none:nnn , |
| 1034 |
% \use_none:nnnn , |
| 1035 |
% \use_none:nnnnn , |
| 1036 |
% \use_none:nnnnnn , |
| 1037 |
% \use_none:nnnnnnn , |
| 1038 |
% \use_none:nnnnnnnn , |
| 1039 |
% \use_none:nnnnnnnnn |
| 1040 |
% } |
| 1041 |
% \begin{syntax} |
| 1042 |
% \cs{use_none:n} \Arg{group_1} |
| 1043 |
% \end{syntax} |
| 1044 |
% These functions absorb between one and nine groups from the |
| 1045 |
% input stream, leaving nothing on the resulting input stream. |
| 1046 |
% These functions work after a single expansion. One or more of the |
| 1047 |
% \texttt{n} arguments may be an unbraced single token |
| 1048 |
% (i.e., an \texttt{N} argument). |
| 1049 |
% \begin{texnote} |
| 1050 |
% These are equivalent to \LaTeXe{}'s \tn{@gobble}, \tn{@gobbletwo}, |
| 1051 |
% etc. |
| 1052 |
% \end{texnote} |
| 1053 |
% \end{function} |
| 1054 |
% |
| 1055 |
% \begin{function}[EXP, added = 2018-06-18, updated = 2023-07-05]{\use:e} |
| 1056 |
% \begin{syntax} |
| 1057 |
% \cs{use:e} \Arg{expandable tokens} |
| 1058 |
% \end{syntax} |
| 1059 |
% Fully expands the \meta{token list} in an \texttt{e}-type manner, |
| 1060 |
% in which parameter character (usually~|#|) need not be doubled, \emph{and} |
| 1061 |
% the function remains fully expandable. |
| 1062 |
% \begin{texnote} |
| 1063 |
% \cs{use:e} is a wrapper around the primitive \tn{expanded}. |
| 1064 |
% It requires two expansions to complete its action. |
| 1065 |
% \end{texnote} |
| 1066 |
% \end{function} |
| 1067 |
% |
| 1068 |
% \subsection{Selecting tokens from delimited arguments} |
| 1069 |
% |
| 1070 |
% A different kind of function for selecting tokens from the token |
| 1071 |
% stream are those that use delimited arguments. |
| 1072 |
% |
| 1073 |
% \begin{function}[EXP] |
| 1074 |
% { |
| 1075 |
% \use_none_delimit_by_q_nil:w, |
| 1076 |
% \use_none_delimit_by_q_stop:w, |
| 1077 |
% \use_none_delimit_by_q_recursion_stop:w |
| 1078 |
% } |
| 1079 |
% \begin{syntax} |
| 1080 |
% \cs{use_none_delimit_by_q_nil:w} \meta{balanced text} \cs{q_nil} |
| 1081 |
% \cs{use_none_delimit_by_q_stop:w} \meta{balanced text} \cs{q_stop} |
| 1082 |
% \cs{use_none_delimit_by_q_recursion_stop:w} \meta{balanced text} \cs{q_recursion_stop} |
| 1083 |
% \end{syntax} |
| 1084 |
% Absorb the \meta{balanced text} from the input stream delimited by |
| 1085 |
% the marker given in the function name, leaving nothing in the |
| 1086 |
% input stream. |
| 1087 |
% \end{function} |
| 1088 |
% |
| 1089 |
% \begin{function}[EXP] |
| 1090 |
% { |
| 1091 |
% \use_i_delimit_by_q_nil:nw, |
| 1092 |
% \use_i_delimit_by_q_stop:nw, |
| 1093 |
% \use_i_delimit_by_q_recursion_stop:nw |
| 1094 |
% } |
| 1095 |
% \begin{syntax} |
| 1096 |
% \cs{use_i_delimit_by_q_nil:nw} \Arg{inserted tokens} \meta{balanced text} \cs{q_nil} |
| 1097 |
% \cs{use_i_delimit_by_q_stop:nw} \Arg{inserted tokens} \meta{balanced text} \cs{q_stop} |
| 1098 |
% \cs{use_i_delimit_by_q_recursion_stop:nw} \Arg{inserted tokens} \meta{balanced text} \cs{q_recursion_stop} |
| 1099 |
% \end{syntax} |
| 1100 |
% Absorb the \meta{balanced text} from the input stream delimited by |
| 1101 |
% the marker given in the function name, leaving \meta{inserted tokens} |
| 1102 |
% in the input stream for further processing. |
| 1103 |
% \end{function} |
| 1104 |
% |
| 1105 |
% \section{Predicates and conditionals} |
| 1106 |
% |
| 1107 |
% \LaTeX3 has three concepts for conditional flow processing: |
| 1108 |
% \begin{description} |
| 1109 |
% \item[Branching conditionals] |
| 1110 |
% Functions that carry out a test and then execute, depending on its |
| 1111 |
% result, either the code supplied as the \meta{true code} or the |
| 1112 |
% \meta{false code}. |
| 1113 |
% These arguments are denoted with |T| and |F|, respectively. An |
| 1114 |
% example would be |
| 1115 |
% \begin{quote} |
| 1116 |
% |\cs_if_free:cTF {abc}| \Arg{true code} \Arg{false code} |
| 1117 |
% \end{quote} |
| 1118 |
% a function that turns the first argument into a control sequence |
| 1119 |
% (since it's marked as |c|) then checks whether this control sequence |
| 1120 |
% is still free and then depending on the result carries out the code in |
| 1121 |
% the second argument (true case) or in the third argument (false |
| 1122 |
% case). |
| 1123 |
% |
| 1124 |
% These type of functions are known as \enquote{conditionals}; |
| 1125 |
% whenever a |TF| function is defined it is usually accompanied by |
| 1126 |
% |T| and |F| functions as well. These are provided for convenience when |
| 1127 |
% the branch only needs to go a single way. Package writers are free to |
| 1128 |
% choose which types to define but the kernel definitions always |
| 1129 |
% provide all three versions. |
| 1130 |
% |
| 1131 |
% Important to note is that these branching conditionals with \meta{true |
| 1132 |
% code} and/or \meta{false code} are always defined in a way that the |
| 1133 |
% code of the chosen alternative can operate on following tokens in |
| 1134 |
% the input stream. |
| 1135 |
% |
| 1136 |
% These conditional functions may or may not be fully expandable, but if |
| 1137 |
% they are expandable they are accompanied by a \enquote{predicate} |
| 1138 |
% for the same test as described below. |
| 1139 |
% |
| 1140 |
% \item[Predicates] |
| 1141 |
% \enquote{Predicates} are functions that return a special type of |
| 1142 |
% boolean value which can be tested by the boolean expression parser. |
| 1143 |
% All functions of this type |
| 1144 |
% are expandable and have names that end with |_p| in the |
| 1145 |
% description part. For example, |
| 1146 |
% \begin{quote} |
| 1147 |
% \cs{cs_if_free_p:N} |
| 1148 |
% \end{quote} |
| 1149 |
% would be a predicate function for the same type of test as the |
| 1150 |
% conditional described above. It would return \enquote{true} if its |
| 1151 |
% argument (a single token denoted by |N|) is still free for definition. |
| 1152 |
% It would be used in constructions like |
| 1153 |
% \begin{quote} |
| 1154 |
% "\bool_if:nTF" \\ |
| 1155 |
% " { \cs_if_free_p:N \l_tmpz_tl || \cs_if_free_p:N \g_tmpz_tl }" \\ |
| 1156 |
% " "\Arg{true code} \Arg{false code} |
| 1157 |
% \end{quote} |
| 1158 |
% |
| 1159 |
% For each predicate defined, a \enquote{branching conditional} |
| 1160 |
% also exists that behaves like a conditional described above. |
| 1161 |
% |
| 1162 |
% \item[Primitive conditionals] |
| 1163 |
% There is a third variety of conditional, which is the original |
| 1164 |
% concept used in plain \TeX{} and \LaTeXe{}. Their use is discouraged |
| 1165 |
% in \pkg{expl3} (although still used in low-level definitions) |
| 1166 |
% because they are more fragile and in many cases require more |
| 1167 |
% expansion control (hence more code) than the two types of |
| 1168 |
% conditionals described above. |
| 1169 |
% \end{description} |
| 1170 |
% |
| 1171 |
% \subsection{Tests on control sequences} |
| 1172 |
% |
| 1173 |
% \begin{function}[EXP,pTF]{\cs_if_eq:NN, \cs_if_eq:Nc, \cs_if_eq:cN, \cs_if_eq:cc} |
| 1174 |
% \begin{syntax} |
| 1175 |
% \cs{cs_if_eq_p:NN} \meta{cs_1} \meta{cs_2} |
| 1176 |
% \cs{cs_if_eq:NNTF} \meta{cs_1} \meta{cs_2} \Arg{true code} \Arg{false code} |
| 1177 |
% \end{syntax} |
| 1178 |
% Compares the definition of two \meta{control sequences} and |
| 1179 |
% is logically \texttt{true} if they are the same, i.e., if they have exactly |
| 1180 |
% the same definition when examined with \cs{cs_show:N}. |
| 1181 |
% \end{function} |
| 1182 |
% |
| 1183 |
% \begin{function}[EXP,pTF]{\cs_if_exist:N, \cs_if_exist:c} |
| 1184 |
% \begin{syntax} |
| 1185 |
% \cs{cs_if_exist_p:N} \meta{control sequence} |
| 1186 |
% \cs{cs_if_exist:NTF} \meta{control sequence} \Arg{true code} \Arg{false code} |
| 1187 |
% \end{syntax} |
| 1188 |
% Tests whether the \meta{control sequence} is currently defined |
| 1189 |
% (whether as a function or another control sequence type), |
| 1190 |
% and its meaning is not the primitive \tn{relax} token. |
| 1191 |
% This is different from \cs{if_cs_exist:N}, which evaluates to |
| 1192 |
% \texttt{true} if passed the token \tn{relax} as an argument. |
| 1193 |
% \end{function} |
| 1194 |
% |
| 1195 |
% \begin{function}[EXP,pTF]{\cs_if_free:N, \cs_if_free:c} |
| 1196 |
% \begin{syntax} |
| 1197 |
% \cs{cs_if_free_p:N} \meta{control sequence} |
| 1198 |
% \cs{cs_if_free:NTF} \meta{control sequence} \Arg{true code} \Arg{false code} |
| 1199 |
% \end{syntax} |
| 1200 |
% This test is the negation of the above \cs{cs_if_exist:NTF}. |
| 1201 |
% \end{function} |
| 1202 |
% |
| 1203 |
% \subsection{Primitive conditionals} |
| 1204 |
% |
| 1205 |
% The \eTeX{} engine itself provides many different conditionals. Some |
| 1206 |
% expand whatever comes after them and others don't. Hence the names |
| 1207 |
% for these underlying functions often contains a |:w| part but |
| 1208 |
% higher level functions are often available. See for instance |
| 1209 |
% \cs{int_compare_p:nNn} which is a wrapper for \cs{if_int_compare:w}. |
| 1210 |
% |
| 1211 |
% Certain conditionals deal with specific data types like boxes and |
| 1212 |
% fonts and are described there. The ones described below are either |
| 1213 |
% the universal conditionals or deal with control sequences. We |
| 1214 |
% prefix primitive conditionals with |\if_|, except for \cs{if:w}. |
| 1215 |
% |
| 1216 |
% \begin{function}[EXP] |
| 1217 |
% {\if_true:, \if_false:, \else:, \fi:, \reverse_if:N} |
| 1218 |
% \begin{syntax} |
| 1219 |
% "\if_true:" <true code> "\else:" <false code> "\fi:" \\ |
| 1220 |
% "\if_false:" <true code> "\else:" <false code> "\fi:" \\ |
| 1221 |
% "\reverse_if:N" <primitive conditional> |
| 1222 |
% \end{syntax} |
| 1223 |
% "\if_true:" always executes <true code>, while "\if_false:" always |
| 1224 |
% executes <false code>. "\reverse_if:N" reverses any two-way primitive |
| 1225 |
% conditional. "\else:" and "\fi:" delimit the branches of the |
| 1226 |
% conditional. The function "\or:" is documented in \pkg{l3int} and |
| 1227 |
% used in case switches. |
| 1228 |
% \begin{texnote} |
| 1229 |
% \cs{if_true:} and \cs{if_false:} are equivalent to their corresponding |
| 1230 |
% \TeX{} primitive conditionals \tn{iftrue} and \tn{iffalse}; |
| 1231 |
% \cs{else:} and \cs{fi:} are the \TeX{} primitives \tn{else} and \tn{fi}; |
| 1232 |
% \cs{reverse_if:N} is the \eTeX{} primitive \tn{unless}. |
| 1233 |
% \end{texnote} |
| 1234 |
% \end{function} |
| 1235 |
% |
| 1236 |
% \begin{function}[EXP]{\if_meaning:w} |
| 1237 |
% \begin{syntax} |
| 1238 |
% "\if_meaning:w" <arg_1> <arg_2> <true code> "\else:" <false code> "\fi:" |
| 1239 |
% \end{syntax} |
| 1240 |
% "\if_meaning:w" executes <true code> when <arg_1> and <arg_2> are the same, |
| 1241 |
% otherwise it executes <false code>. |
| 1242 |
% <arg_1> and <arg_2> could be functions, variables, tokens; in all cases the |
| 1243 |
% \emph{unexpanded} definitions are compared. |
| 1244 |
% \begin{texnote} |
| 1245 |
% This is the \TeX{} primitive \tn{ifx}. |
| 1246 |
% \end{texnote} |
| 1247 |
% \end{function} |
| 1248 |
% |
| 1249 |
% \begin{function}[EXP]{\if:w, \if_charcode:w, \if_catcode:w} |
| 1250 |
% \begin{syntax} |
| 1251 |
% "\if:w" <token(s)> <true code> "\else:" <false code> "\fi:" \\ |
| 1252 |
% "\if_catcode:w" <token(s)> <true code> "\else:" <false code> "\fi:" |
| 1253 |
% \end{syntax} |
| 1254 |
% "\if_charcode:w" is an alternative name for "\if:w". |
| 1255 |
% These conditionals expand \meta{token(s)} until two |
| 1256 |
% unexpandable tokens \meta{token_1} and \meta{token_2} are found; |
| 1257 |
% any further tokens up to the next unbalanced "\else:" are the true branch, |
| 1258 |
% ending with \meta{true code}. It is executed if the condition is fulfilled, |
| 1259 |
% otherwise \meta{false code} is executed. |
| 1260 |
% You can omit "\else:" when just in front of "\fi:" and |
| 1261 |
% you can nest "\if...\else:...\fi:" constructs inside the true branch or the |
| 1262 |
% \meta{false code}. |
| 1263 |
% With "\exp_not:N", you can prevent the expansion of a token. |
| 1264 |
% |
| 1265 |
% "\if_catcode:w" |
| 1266 |
% tests if \meta{token_1} and \meta{token_2} have the same category code whereas |
| 1267 |
% "\if:w" and \cs{if_charcode:w} test if they have the same character code. |
| 1268 |
% \begin{texnote} |
| 1269 |
% \cs{if:w} and \cs{if_charcode:w} are both the \TeX{} primitive \tn{if}. |
| 1270 |
% \cs{if_catcode:w} is the \TeX{} primitive \tn{ifcat}. |
| 1271 |
% \end{texnote} |
| 1272 |
% \end{function} |
| 1273 |
% |
| 1274 |
% \begin{function}[EXP]{\if_cs_exist:N, \if_cs_exist:w} |
| 1275 |
% \begin{syntax} |
| 1276 |
% "\if_cs_exist:N" <cs> <true code> "\else:" <false code> "\fi:" \\ |
| 1277 |
% "\if_cs_exist:w" <tokens> "\cs_end:" <true code> "\else:" <false code> "\fi:" |
| 1278 |
% \end{syntax} |
| 1279 |
% Check if <cs> appears in the hash table or if the control sequence |
| 1280 |
% that can be formed from <tokens> appears in the hash table. The |
| 1281 |
% latter function does not turn the control sequence in question into |
| 1282 |
% the primitive \tn{relax} token. This can be useful when dealing with control |
| 1283 |
% sequences which cannot be entered as a single token. |
| 1284 |
% \begin{texnote} |
| 1285 |
% These are the \TeX{} primitives \tn{ifdefined} and \tn{ifcsname}. |
| 1286 |
% \end{texnote} |
| 1287 |
% \end{function} |
| 1288 |
% |
| 1289 |
% \begin{function}[EXP] |
| 1290 |
% { |
| 1291 |
% \if_mode_horizontal:, \if_mode_vertical:, |
| 1292 |
% \if_mode_math:, \if_mode_inner: |
| 1293 |
% } |
| 1294 |
% \begin{syntax} |
| 1295 |
% "\if_mode_horizontal:" <true code> "\else:" <false code> "\fi:" |
| 1296 |
% \end{syntax} |
| 1297 |
% Execute <true code> if currently in horizontal mode, otherwise |
| 1298 |
% execute <false code>. Similar for the other functions. |
| 1299 |
% \begin{texnote} |
| 1300 |
% These are the \TeX{} primitives \tn{ifhmode}, \tn{ifvmode}, \tn{ifmmode}, |
| 1301 |
% and~\tn{ifinner}. |
| 1302 |
% \end{texnote} |
| 1303 |
% \end{function} |
| 1304 |
% |
| 1305 |
% \section{Starting a paragraph} |
| 1306 |
% |
| 1307 |
% \begin{function}[added = 2017-07-04]{\mode_leave_vertical:} |
| 1308 |
% \begin{syntax} |
| 1309 |
% \cs{mode_leave_vertical:} |
| 1310 |
% \end{syntax} |
| 1311 |
% Ensures that \TeX{} is not in vertical (inter-paragraph) mode. In |
| 1312 |
% horizontal or math mode this command has no effect, in vertical mode it |
| 1313 |
% switches to horizontal mode, and inserts a box of width |
| 1314 |
% \tn{parindent}, followed by the \tn{everypar} token list. |
| 1315 |
% \begin{texnote} |
| 1316 |
% This results in the contents of the \tn{everypar} token register being |
| 1317 |
% inserted, after \cs{mode_leave_vertical:} is complete. Notice that in |
| 1318 |
% contrast to the \LaTeXe{} \tn{leavevmode} approach, no box is used |
| 1319 |
% by the method implemented here. |
| 1320 |
% \end{texnote} |
| 1321 |
% \end{function} |
| 1322 |
% |
| 1323 |
% \section{Debugging support} |
| 1324 |
% |
| 1325 |
% \begin{function}[added = 2017-07-16, updated = 2023-05-23]{\debug_on:n, \debug_off:n} |
| 1326 |
% \begin{syntax} |
| 1327 |
% \cs{debug_on:n} \Arg{comma-separated list} |
| 1328 |
% \cs{debug_off:n} \Arg{comma-separated list} |
| 1329 |
% \end{syntax} |
| 1330 |
% Turn on and off within a group various debugging code, some of which |
| 1331 |
% is also available as \pkg{expl3} load-time options. The items that |
| 1332 |
% can be used in the \meta{list} are |
| 1333 |
% \begin{itemize} |
| 1334 |
% \item \texttt{check-assertions} that checks the invariants declared in |
| 1335 |
% \cs{debug_assert:nn} and friends; |
| 1336 |
% \item \texttt{check-declarations} that checks all \pkg{expl3} |
| 1337 |
% variables used were previously declared and that local/global |
| 1338 |
% variables (based on their name or on their first assignment) are |
| 1339 |
% only locally/globally assigned; |
| 1340 |
% \item \texttt{check-expressions} that checks integer, dimension, |
| 1341 |
% skip, and muskip expressions are not terminated prematurely; |
| 1342 |
% \item \texttt{deprecation} that makes deprecated commands produce errors; |
| 1343 |
% \item \texttt{log-functions} that logs function definitions and |
| 1344 |
% variable declarations; |
| 1345 |
% \item \texttt{all} that does all of the above. |
| 1346 |
% \end{itemize} |
| 1347 |
% Providing these as switches rather than options allows testing code |
| 1348 |
% even if it relies on other packages: load all other packages, call |
| 1349 |
% \cs{debug_on:n}, and load the code that one is interested in |
| 1350 |
% testing. |
| 1351 |
% \end{function} |
| 1352 |
% |
| 1353 |
% \begin{function}[added = 2017-11-28]{\debug_suspend:, \debug_resume:} |
| 1354 |
% \begin{syntax} |
| 1355 |
% \cs{debug_suspend:} \ldots{} \cs{debug_resume:} |
| 1356 |
% \end{syntax} |
| 1357 |
% Suppress (locally) errors and logging from \texttt{debug} commands, |
| 1358 |
% except for the \texttt{deprecation} errors. These pairs |
| 1359 |
% of commands can be nested. This can be used around pieces of code |
| 1360 |
% that are known to fail checks, if such failures should be ignored. |
| 1361 |
% See for instance \pkg{l3cctab} and \pkg{l3coffins}. |
| 1362 |
% \end{function} |
| 1363 |
% |
| 1364 |
% \begin{function}[added = 2026-03-06, EXP] |
| 1365 |
% { |
| 1366 |
% \debug_assert:nN, |
| 1367 |
% \debug_assert:nn, |
| 1368 |
% \debug_assert:nNn, \debug_assert:nNe, |
| 1369 |
% \debug_assert:nnn, \debug_assert:nne |
| 1370 |
% } |
| 1371 |
% \begin{syntax} |
| 1372 |
% \cs{debug_assert:nN} \Arg{module} \meta{boolean} |
| 1373 |
% \cs{debug_assert:nn} \Arg{module} \Arg{boolean expression} |
| 1374 |
% \cs{debug_assert:nNn} \Arg{module} \meta{boolean} \Arg{message text} |
| 1375 |
% \cs{debug_assert:nnn} \Arg{module} \Arg{boolean expression} \Arg{message text} |
| 1376 |
% \end{syntax} |
| 1377 |
% Assert that the invariant specified by \meta{boolean} or \meta{boolean |
| 1378 |
% expression} is |true| at this point in the code. |
| 1379 |
% |
| 1380 |
% When assertion checking has been enabled with \cs{debug_on:n} |
| 1381 |
% |{check-assertions}|, a violation of the invariant will produce an error |
| 1382 |
% with a message formed from \meta{module} and the optional |
| 1383 |
% \meta{message text}. |
| 1384 |
% |
| 1385 |
% The invariant will \emph{only} be evaluated when assertion checking has |
| 1386 |
% been enabled. Therefore, assertions can be used liberally throughout the |
| 1387 |
% code without significant performance impact outside debugging. |
| 1388 |
% \end{function} |
| 1389 |
% |
| 1390 |
% \end{documentation} |
| 1391 |
% |
| 1392 |
% \begin{implementation} |
| 1393 |
% |
| 1394 |
% \section{\pkg{l3basics} implementation} |
| 1395 |
% |
| 1396 |
% \begin{macrocode} |
| 1397 |
%<*code> |
| 1398 |
% \end{macrocode} |
| 1399 |
% |
| 1400 |
% \subsection{Renaming some \TeX{} primitives (again)} |
| 1401 |
% |
| 1402 |
% Having given all the \TeX{} primitives a consistent name, we need to |
| 1403 |
% give sensible names to the ones we actually want to use. |
| 1404 |
% These will be defined as needed in the appropriate modules, but we |
| 1405 |
% do a few now, just to get started.\footnote{This renaming gets expensive |
| 1406 |
% in terms of csname usage, an alternative scheme would be to just use |
| 1407 |
% the \cs[no-index]{tex_\ldots:D} name in the cases where no good alternative exists.} |
| 1408 |
% |
| 1409 |
% \begin{macro}[EXP] |
| 1410 |
% { |
| 1411 |
% \if_true:, \if_false:, \or:, \else:, \fi:, \reverse_if:N, |
| 1412 |
% \if:w, \if_charcode:w, \if_catcode:w, \if_meaning:w |
| 1413 |
% } |
| 1414 |
% Then some conditionals. |
| 1415 |
% \begin{macrocode} |
| 1416 |
\tex_global:D \tex_let:D \if_true: \tex_iftrue:D |
| 1417 |
\tex_global:D \tex_let:D \if_false: \tex_iffalse:D |
| 1418 |
\tex_global:D \tex_let:D \or: \tex_or:D |
| 1419 |
\tex_global:D \tex_let:D \else: \tex_else:D |
| 1420 |
\tex_global:D \tex_let:D \fi: \tex_fi:D |
| 1421 |
\tex_global:D \tex_let:D \reverse_if:N \tex_unless:D |
| 1422 |
\tex_global:D \tex_let:D \if:w \tex_if:D |
| 1423 |
\tex_global:D \tex_let:D \if_charcode:w \tex_if:D |
| 1424 |
\tex_global:D \tex_let:D \if_catcode:w \tex_ifcat:D |
| 1425 |
\tex_global:D \tex_let:D \if_meaning:w \tex_ifx:D |
| 1426 |
\tex_global:D \tex_let:D \if_bool:N \tex_ifodd:D |
| 1427 |
% \end{macrocode} |
| 1428 |
% \end{macro} |
| 1429 |
% |
| 1430 |
% \begin{macro}[EXP] |
| 1431 |
% { |
| 1432 |
% \if_mode_math:, |
| 1433 |
% \if_mode_horizontal:, |
| 1434 |
% \if_mode_vertical:, |
| 1435 |
% \if_mode_inner: |
| 1436 |
% } |
| 1437 |
% \TeX{} lets us detect some if its modes. |
| 1438 |
% \begin{macrocode} |
| 1439 |
\tex_global:D \tex_let:D \if_mode_math: \tex_ifmmode:D |
| 1440 |
\tex_global:D \tex_let:D \if_mode_horizontal: \tex_ifhmode:D |
| 1441 |
\tex_global:D \tex_let:D \if_mode_vertical: \tex_ifvmode:D |
| 1442 |
\tex_global:D \tex_let:D \if_mode_inner: \tex_ifinner:D |
| 1443 |
% \end{macrocode} |
| 1444 |
% \end{macro} |
| 1445 |
% |
| 1446 |
% \begin{macro}[EXP]{\if_cs_exist:N, \if_cs_exist:w, \cs:w, \cs_end:} |
| 1447 |
% Building csnames and testing if control sequences exist. |
| 1448 |
% \begin{macrocode} |
| 1449 |
\tex_global:D \tex_let:D \if_cs_exist:N \tex_ifdefined:D |
| 1450 |
\tex_global:D \tex_let:D \if_cs_exist:w \tex_ifcsname:D |
| 1451 |
\tex_global:D \tex_let:D \cs:w \tex_csname:D |
| 1452 |
\tex_global:D \tex_let:D \cs_end: \tex_endcsname:D |
| 1453 |
% \end{macrocode} |
| 1454 |
% \end{macro} |
| 1455 |
% |
| 1456 |
% \begin{macro}[EXP]{\exp_after:wN, \exp_not:N, \exp_not:n} |
| 1457 |
% The five |\exp_| functions are used in the \pkg{l3expan} module |
| 1458 |
% where they are described. |
| 1459 |
% \begin{macrocode} |
| 1460 |
\tex_global:D \tex_let:D \exp_after:wN \tex_expandafter:D |
| 1461 |
\tex_global:D \tex_let:D \exp_not:N \tex_noexpand:D |
| 1462 |
\tex_global:D \tex_let:D \exp_not:n \tex_unexpanded:D |
| 1463 |
\tex_global:D \tex_let:D \exp:w \tex_romannumeral:D |
| 1464 |
\tex_global:D \tex_chardef:D \exp_end: = 0 ~ |
| 1465 |
% \end{macrocode} |
| 1466 |
% \end{macro} |
| 1467 |
% |
| 1468 |
% \begin{macro}[EXP]{\token_to_meaning:N, \cs_meaning:N} |
| 1469 |
% Examining a control sequence or token. |
| 1470 |
% \begin{macrocode} |
| 1471 |
\tex_global:D \tex_let:D \token_to_meaning:N \tex_meaning:D |
| 1472 |
\tex_global:D \tex_let:D \cs_meaning:N \tex_meaning:D |
| 1473 |
% \end{macrocode} |
| 1474 |
% \end{macro} |
| 1475 |
% |
| 1476 |
% \begin{macro}[EXP]{\tl_to_str:n, \token_to_str:N, \__kernel_tl_to_str:w} |
| 1477 |
% Making strings. |
| 1478 |
% \begin{macrocode} |
| 1479 |
\tex_global:D \tex_let:D \tl_to_str:n \tex_detokenize:D |
| 1480 |
\tex_global:D \tex_let:D \token_to_str:N \tex_string:D |
| 1481 |
\tex_global:D \tex_let:D \__kernel_tl_to_str:w \tex_detokenize:D |
| 1482 |
% \end{macrocode} |
| 1483 |
% \end{macro} |
| 1484 |
% |
| 1485 |
% \begin{macro}{\scan_stop:, \group_begin:, \group_end:} |
| 1486 |
% The next three are basic functions for which there also exist |
| 1487 |
% versions that are safe inside alignments. These safe versions are |
| 1488 |
% defined in the \pkg{l3prg} module. |
| 1489 |
% \begin{macrocode} |
| 1490 |
\tex_global:D \tex_let:D \scan_stop: \tex_relax:D |
| 1491 |
\tex_global:D \tex_let:D \group_begin: \tex_begingroup:D |
| 1492 |
\tex_global:D \tex_let:D \group_end: \tex_endgroup:D |
| 1493 |
% \end{macrocode} |
| 1494 |
% \end{macro} |
| 1495 |
% |
| 1496 |
% \begin{macrocode} |
| 1497 |
%<@@=int> |
| 1498 |
% \end{macrocode} |
| 1499 |
% |
| 1500 |
% \begin{macro}[EXP]{\if_int_compare:w, \@@_to_roman:w} |
| 1501 |
% For integers. |
| 1502 |
% \begin{macrocode} |
| 1503 |
\tex_global:D \tex_let:D \if_int_compare:w \tex_ifnum:D |
| 1504 |
\tex_global:D \tex_let:D \@@_to_roman:w \tex_romannumeral:D |
| 1505 |
% \end{macrocode} |
| 1506 |
% \end{macro} |
| 1507 |
% |
| 1508 |
% \begin{macro}{\group_insert_after:N} |
| 1509 |
% Adding material after the end of a group. |
| 1510 |
% \begin{macrocode} |
| 1511 |
\tex_global:D \tex_let:D \group_insert_after:N \tex_aftergroup:D |
| 1512 |
% \end{macrocode} |
| 1513 |
% \end{macro} |
| 1514 |
% |
| 1515 |
% \begin{macro}[EXP]{\exp_args:Nc, \exp_args:cc} |
| 1516 |
% Discussed in \pkg{l3expan}, but needed much earlier. |
| 1517 |
% \begin{macrocode} |
| 1518 |
\tex_long:D \tex_gdef:D \exp_args:Nc #1#2 |
| 1519 |
{ \exp_after:wN #1 \cs:w #2 \cs_end: } |
| 1520 |
\tex_long:D \tex_gdef:D \exp_args:cc #1#2 |
| 1521 |
{ \cs:w #1 \exp_after:wN \cs_end: \cs:w #2 \cs_end: } |
| 1522 |
% \end{macrocode} |
| 1523 |
% \end{macro} |
| 1524 |
% |
| 1525 |
% \begin{macro}[EXP, documented-as=\token_to_meaning:N] |
| 1526 |
% {\token_to_meaning:c, \token_to_str:c, \cs_meaning:c} |
| 1527 |
% A small number of variants defined by hand. |
| 1528 |
% Some of the necessary functions |
| 1529 |
% (\cs{use_i:nn}, \cs{use_ii:nn}, and \cs{exp_args:NNc}) are not |
| 1530 |
% defined at that point yet, but will be defined before those variants |
| 1531 |
% are used. The \cs{cs_meaning:c} command must check for an undefined |
| 1532 |
% control sequence to avoid defining it mistakenly. |
| 1533 |
% \begin{macrocode} |
| 1534 |
\tex_gdef:D \token_to_str:c { \exp_args:Nc \token_to_str:N } |
| 1535 |
\tex_long:D \tex_gdef:D \cs_meaning:c #1 |
| 1536 |
{ |
| 1537 |
\if_cs_exist:w #1 \cs_end: |
| 1538 |
\exp_after:wN \use_i:nn |
| 1539 |
\else: |
| 1540 |
\exp_after:wN \use_ii:nn |
| 1541 |
\fi: |
| 1542 |
{ \exp_args:Nc \cs_meaning:N {#1} } |
| 1543 |
{ \tl_to_str:n {undefined} } |
| 1544 |
} |
| 1545 |
\tex_global:D \tex_let:D \token_to_meaning:c = \cs_meaning:c |
| 1546 |
% \end{macrocode} |
| 1547 |
% \end{macro} |
| 1548 |
% |
| 1549 |
% \subsection{Defining some constants} |
| 1550 |
% |
| 1551 |
% \begin{variable}{\c_zero_int} |
| 1552 |
% We need the constant \cs{c_zero_int} |
| 1553 |
% which is used by some functions in current module. The |
| 1554 |
% rest are defined in the \pkg{l3int} module -- at least for the |
| 1555 |
% ones that can be defined with \cs{tex_chardef:D} or |
| 1556 |
% \cs{tex_mathchardef:D}. For other constants the \pkg{l3int} module is |
| 1557 |
% required but it can't be used until the allocation has been set |
| 1558 |
% up properly! |
| 1559 |
% \begin{macrocode} |
| 1560 |
\tex_global:D \tex_chardef:D \c_zero_int = 0 ~ |
| 1561 |
% \end{macrocode} |
| 1562 |
% \end{variable} |
| 1563 |
% |
| 1564 |
% \begin{variable}{\c_max_register_int} |
| 1565 |
% This is here as this particular integer is needed in modules |
| 1566 |
% loaded before \pkg{l3int}, and is documented in \pkg{l3int}. |
| 1567 |
% \LuaTeX{} and those which contain parts of the Omega extensions have |
| 1568 |
% more registers available than \eTeX{}. |
| 1569 |
% \begin{macrocode} |
| 1570 |
\tex_ifdefined:D \tex_luatexversion:D |
| 1571 |
\tex_global:D \tex_chardef:D \c_max_register_int = 65 535 ~ |
| 1572 |
\tex_else:D |
| 1573 |
\tex_ifdefined:D \tex_omathchardef:D |
| 1574 |
\tex_global:D \tex_omathchardef:D \c_max_register_int = 65535 ~ |
| 1575 |
\tex_else:D |
| 1576 |
\tex_global:D \tex_mathchardef:D \c_max_register_int = 32767 ~ |
| 1577 |
\tex_fi:D |
| 1578 |
\tex_fi:D |
| 1579 |
% \end{macrocode} |
| 1580 |
% \end{variable} |
| 1581 |
% |
| 1582 |
% \subsection{Defining functions} |
| 1583 |
% |
| 1584 |
% We start by providing functions for the typical definition |
| 1585 |
% functions. First the global ones. |
| 1586 |
% |
| 1587 |
% \begin{macro} |
| 1588 |
% { |
| 1589 |
% \cs_gset_nopar:Npn , \cs_gset_nopar:Npe , \cs_gset_nopar:Npx , |
| 1590 |
% \cs_gset:Npn , \cs_gset:Npe , \cs_gset:Npx , |
| 1591 |
% \cs_gset_protected_nopar:Npn , \cs_gset_protected_nopar:Npe , \cs_gset_protected_nopar:Npx , |
| 1592 |
% \cs_gset_protected:Npn , \cs_gset_protected:Npe , \cs_gset_protected:Npx |
| 1593 |
% } |
| 1594 |
% All assignment functions in \LaTeX3 should be naturally protected; |
| 1595 |
% after all, the \TeX{} primitives for assignments are and it can be |
| 1596 |
% a cause of problems if others aren't. |
| 1597 |
% \begin{macrocode} |
| 1598 |
\tex_global:D \tex_let:D \cs_gset_nopar:Npn \tex_gdef:D |
| 1599 |
\tex_global:D \tex_let:D \cs_gset_nopar:Npe \tex_xdef:D |
| 1600 |
\tex_global:D \tex_let:D \cs_gset_nopar:Npx \tex_xdef:D |
| 1601 |
\tex_protected:D \tex_long:D \tex_gdef:D \cs_gset:Npn |
| 1602 |
{ \tex_long:D \tex_gdef:D } |
| 1603 |
\tex_protected:D \tex_long:D \tex_gdef:D \cs_gset:Npe |
| 1604 |
{ \tex_long:D \tex_xdef:D } |
| 1605 |
\tex_global:D \tex_let:D \cs_gset:Npx \cs_gset:Npe |
| 1606 |
\tex_protected:D \tex_long:D \tex_gdef:D \cs_gset_protected_nopar:Npn |
| 1607 |
{ \tex_protected:D \tex_gdef:D } |
| 1608 |
\tex_protected:D \tex_long:D \tex_gdef:D \cs_gset_protected_nopar:Npe |
| 1609 |
{ \tex_protected:D \tex_xdef:D } |
| 1610 |
\tex_global:D \tex_let:D \cs_gset_protected_nopar:Npx \cs_gset_protected_nopar:Npe |
| 1611 |
\tex_protected:D \tex_long:D \tex_gdef:D \cs_gset_protected:Npn |
| 1612 |
{ \tex_protected:D \tex_long:D \tex_gdef:D } |
| 1613 |
\tex_protected:D \tex_long:D \tex_gdef:D \cs_gset_protected:Npe |
| 1614 |
{ \tex_protected:D \tex_long:D \tex_xdef:D } |
| 1615 |
\tex_global:D \tex_let:D \cs_gset_protected:Npx \cs_gset_protected:Npe |
| 1616 |
% \end{macrocode} |
| 1617 |
% \end{macro} |
| 1618 |
% |
| 1619 |
% \begin{macro} |
| 1620 |
% { |
| 1621 |
% \cs_set_nopar:Npn , \cs_set_nopar:Npe , \cs_set_nopar:Npx , |
| 1622 |
% \cs_set:Npn , \cs_set:Npe , \cs_set:Npx , |
| 1623 |
% \cs_set_protected_nopar:Npn , \cs_set_protected_nopar:Npe , \cs_set_protected_nopar:Npx , |
| 1624 |
% \cs_set_protected:Npn , \cs_set_protected:Npe , \cs_set_protected:Npx |
| 1625 |
% } |
| 1626 |
% Local versions of the above functions. |
| 1627 |
% \begin{macrocode} |
| 1628 |
\tex_global:D \tex_let:D \cs_set_nopar:Npn \tex_def:D |
| 1629 |
\tex_global:D \tex_let:D \cs_set_nopar:Npe \tex_edef:D |
| 1630 |
\tex_global:D \tex_let:D \cs_set_nopar:Npx \tex_edef:D |
| 1631 |
\cs_gset_protected:Npn \cs_set:Npn |
| 1632 |
{ \tex_long:D \tex_def:D } |
| 1633 |
\cs_gset_protected:Npn \cs_set:Npe |
| 1634 |
{ \tex_long:D \tex_edef:D } |
| 1635 |
\tex_global:D \tex_let:D \cs_set:Npx \cs_set:Npe |
| 1636 |
\cs_gset_protected:Npn \cs_set_protected_nopar:Npn |
| 1637 |
{ \tex_protected:D \tex_def:D } |
| 1638 |
\cs_gset_protected:Npn \cs_set_protected_nopar:Npe |
| 1639 |
{ \tex_protected:D \tex_edef:D } |
| 1640 |
\tex_global:D \tex_let:D \cs_set_protected_nopar:Npx \cs_set_protected_nopar:Npe |
| 1641 |
\cs_gset_protected:Npn \cs_set_protected:Npn |
| 1642 |
{ \tex_protected:D \tex_long:D \tex_def:D } |
| 1643 |
\cs_gset_protected:Npn \cs_set_protected:Npe |
| 1644 |
{ \tex_protected:D \tex_long:D \tex_edef:D } |
| 1645 |
\tex_global:D \tex_let:D \cs_set_protected:Npx \cs_set_protected:Npe |
| 1646 |
% \end{macrocode} |
| 1647 |
% \end{macro} |
| 1648 |
% |
| 1649 |
% \subsection{Selecting tokens} |
| 1650 |
% |
| 1651 |
% \begin{macrocode} |
| 1652 |
%<@@=exp> |
| 1653 |
% \end{macrocode} |
| 1654 |
% |
| 1655 |
% \begin{variable}{\l_@@_tmp_tl} |
| 1656 |
% Scratch token list variable for \pkg{l3expan}, used by \cs{use:x}, |
| 1657 |
% used in defining conditionals. We don't use |tl| methods because |
| 1658 |
% \pkg{l3basics} is loaded earlier. |
| 1659 |
% \begin{macrocode} |
| 1660 |
\cs_gset_nopar:Npn \l_@@_tmp_tl { } |
| 1661 |
% \end{macrocode} |
| 1662 |
% \end{variable} |
| 1663 |
% |
| 1664 |
% \begin{macro}[EXP]{\use:c} |
| 1665 |
% This macro grabs its argument and returns a csname from it. |
| 1666 |
% \begin{macrocode} |
| 1667 |
\cs_gset:Npn \use:c #1 { \cs:w #1 \cs_end: } |
| 1668 |
% \end{macrocode} |
| 1669 |
% \end{macro} |
| 1670 |
% |
| 1671 |
% \begin{macro}[deprecated]{\use:x} |
| 1672 |
% Fully expands its argument and passes it to the input stream. Uses |
| 1673 |
% the reserved \cs{l_@@_tmp_tl} which we've set up above. |
| 1674 |
% \begin{macrocode} |
| 1675 |
\cs_gset_protected:Npn \use:x #1 |
| 1676 |
{ |
| 1677 |
\cs_set_nopar:Npx \l_@@_tmp_tl {#1} |
| 1678 |
\l_@@_tmp_tl |
| 1679 |
} |
| 1680 |
% \end{macrocode} |
| 1681 |
% \end{macro} |
| 1682 |
% |
| 1683 |
% \begin{macrocode} |
| 1684 |
%<@@=use> |
| 1685 |
% \end{macrocode} |
| 1686 |
% |
| 1687 |
% \begin{macro}[EXP]{\use:e} |
| 1688 |
% \begin{macrocode} |
| 1689 |
\cs_gset:Npn \use:e #1 { \tex_expanded:D {#1} } |
| 1690 |
% \end{macrocode} |
| 1691 |
% \end{macro} |
| 1692 |
% |
| 1693 |
% \begin{macrocode} |
| 1694 |
%<@@=exp> |
| 1695 |
% \end{macrocode} |
| 1696 |
% |
| 1697 |
% \begin{macro}[EXP]{\use:n, \use:nn, \use:nnn, \use:nnnn} |
| 1698 |
% These macros grab their arguments and return them back to the input |
| 1699 |
% (with outer braces removed). |
| 1700 |
% \begin{macrocode} |
| 1701 |
\cs_gset:Npn \use:n #1 {#1} |
| 1702 |
\cs_gset:Npn \use:nn #1#2 {#1#2} |
| 1703 |
\cs_gset:Npn \use:nnn #1#2#3 {#1#2#3} |
| 1704 |
\cs_gset:Npn \use:nnnn #1#2#3#4 {#1#2#3#4} |
| 1705 |
% \end{macrocode} |
| 1706 |
% \end{macro} |
| 1707 |
% |
| 1708 |
% \begin{macro}[EXP]{\use_i:nn, \use_ii:nn} |
| 1709 |
% The equivalent to \LaTeXe{}'s \tn{@firstoftwo} and \tn{@secondoftwo}. |
| 1710 |
% \begin{macrocode} |
| 1711 |
\cs_gset:Npn \use_i:nn #1#2 {#1} |
| 1712 |
\cs_gset:Npn \use_ii:nn #1#2 {#2} |
| 1713 |
% \end{macrocode} |
| 1714 |
% \end{macro} |
| 1715 |
% |
| 1716 |
% \begin{macro}[EXP] |
| 1717 |
% { |
| 1718 |
% \use_i:nnn , \use_ii:nnn , \use_iii:nnn , |
| 1719 |
% \use_i:nnnn, \use_ii:nnnn, \use_iii:nnnn, \use_iv:nnnn , |
| 1720 |
% \use_i:nnnnn, \use_ii:nnnnn, \use_iii:nnnnn, \use_iv:nnnnn , |
| 1721 |
% \use_v:nnnnn , |
| 1722 |
% \use_i:nnnnnn, \use_ii:nnnnnn, \use_iii:nnnnnn, \use_iv:nnnnnn , |
| 1723 |
% \use_v:nnnnnn , \use_vi:nnnnnn , |
| 1724 |
% \use_i:nnnnnnn, \use_ii:nnnnnnn, \use_iii:nnnnnnn, \use_iv:nnnnnnn , |
| 1725 |
% \use_v:nnnnnnn , \use_vi:nnnnnnn , \use_vii:nnnnnnn , |
| 1726 |
% \use_i:nnnnnnnn, \use_ii:nnnnnnnn, \use_iii:nnnnnnnn, \use_iv:nnnnnnnn , |
| 1727 |
% \use_v:nnnnnnnn , \use_vi:nnnnnnnn , \use_vii:nnnnnnnn , \use_viii:nnnnnnnn , |
| 1728 |
% \use_i:nnnnnnnnn, \use_ii:nnnnnnnnn, \use_iii:nnnnnnnnn, \use_iv:nnnnnnnnn , |
| 1729 |
% \use_v:nnnnnnnnn , \use_vi:nnnnnnnnn , \use_vii:nnnnnnnnn , \use_viii:nnnnnnnnn , |
| 1730 |
% \use_ix:nnnnnnnnn |
| 1731 |
% } |
| 1732 |
% We also need something for picking up arguments from a longer list. |
| 1733 |
% \begin{macrocode} |
| 1734 |
\cs_gset:Npn \use_i:nnn #1#2#3 {#1} |
| 1735 |
\cs_gset:Npn \use_ii:nnn #1#2#3 {#2} |
| 1736 |
\cs_gset:Npn \use_iii:nnn #1#2#3 {#3} |
| 1737 |
\cs_gset:Npn \use_i:nnnn #1#2#3#4 {#1} |
| 1738 |
\cs_gset:Npn \use_ii:nnnn #1#2#3#4 {#2} |
| 1739 |
\cs_gset:Npn \use_iii:nnnn #1#2#3#4 {#3} |
| 1740 |
\cs_gset:Npn \use_iv:nnnn #1#2#3#4 {#4} |
| 1741 |
\cs_gset:Npn \use_i:nnnnn #1#2#3#4#5 {#1} |
| 1742 |
\cs_gset:Npn \use_ii:nnnnn #1#2#3#4#5 {#2} |
| 1743 |
\cs_gset:Npn \use_iii:nnnnn #1#2#3#4#5 {#3} |
| 1744 |
\cs_gset:Npn \use_iv:nnnnn #1#2#3#4#5 {#4} |
| 1745 |
\cs_gset:Npn \use_v:nnnnn #1#2#3#4#5 {#5} |
| 1746 |
\cs_gset:Npn \use_i:nnnnnn #1#2#3#4#5#6 {#1} |
| 1747 |
\cs_gset:Npn \use_ii:nnnnnn #1#2#3#4#5#6 {#2} |
| 1748 |
\cs_gset:Npn \use_iii:nnnnnn #1#2#3#4#5#6 {#3} |
| 1749 |
\cs_gset:Npn \use_iv:nnnnnn #1#2#3#4#5#6 {#4} |
| 1750 |
\cs_gset:Npn \use_v:nnnnnn #1#2#3#4#5#6 {#5} |
| 1751 |
\cs_gset:Npn \use_vi:nnnnnn #1#2#3#4#5#6 {#6} |
| 1752 |
\cs_gset:Npn \use_i:nnnnnnn #1#2#3#4#5#6#7 {#1} |
| 1753 |
\cs_gset:Npn \use_ii:nnnnnnn #1#2#3#4#5#6#7 {#2} |
| 1754 |
\cs_gset:Npn \use_iii:nnnnnnn #1#2#3#4#5#6#7 {#3} |
| 1755 |
\cs_gset:Npn \use_iv:nnnnnnn #1#2#3#4#5#6#7 {#4} |
| 1756 |
\cs_gset:Npn \use_v:nnnnnnn #1#2#3#4#5#6#7 {#5} |
| 1757 |
\cs_gset:Npn \use_vi:nnnnnnn #1#2#3#4#5#6#7 {#6} |
| 1758 |
\cs_gset:Npn \use_vii:nnnnnnn #1#2#3#4#5#6#7 {#7} |
| 1759 |
\cs_gset:Npn \use_i:nnnnnnnn #1#2#3#4#5#6#7#8 {#1} |
| 1760 |
\cs_gset:Npn \use_ii:nnnnnnnn #1#2#3#4#5#6#7#8 {#2} |
| 1761 |
\cs_gset:Npn \use_iii:nnnnnnnn #1#2#3#4#5#6#7#8 {#3} |
| 1762 |
\cs_gset:Npn \use_iv:nnnnnnnn #1#2#3#4#5#6#7#8 {#4} |
| 1763 |
\cs_gset:Npn \use_v:nnnnnnnn #1#2#3#4#5#6#7#8 {#5} |
| 1764 |
\cs_gset:Npn \use_vi:nnnnnnnn #1#2#3#4#5#6#7#8 {#6} |
| 1765 |
\cs_gset:Npn \use_vii:nnnnnnnn #1#2#3#4#5#6#7#8 {#7} |
| 1766 |
\cs_gset:Npn \use_viii:nnnnnnnn #1#2#3#4#5#6#7#8 {#8} |
| 1767 |
\cs_gset:Npn \use_i:nnnnnnnnn #1#2#3#4#5#6#7#8#9 {#1} |
| 1768 |
\cs_gset:Npn \use_ii:nnnnnnnnn #1#2#3#4#5#6#7#8#9 {#2} |
| 1769 |
\cs_gset:Npn \use_iii:nnnnnnnnn #1#2#3#4#5#6#7#8#9 {#3} |
| 1770 |
\cs_gset:Npn \use_iv:nnnnnnnnn #1#2#3#4#5#6#7#8#9 {#4} |
| 1771 |
\cs_gset:Npn \use_v:nnnnnnnnn #1#2#3#4#5#6#7#8#9 {#5} |
| 1772 |
\cs_gset:Npn \use_vi:nnnnnnnnn #1#2#3#4#5#6#7#8#9 {#6} |
| 1773 |
\cs_gset:Npn \use_vii:nnnnnnnnn #1#2#3#4#5#6#7#8#9 {#7} |
| 1774 |
\cs_gset:Npn \use_viii:nnnnnnnnn #1#2#3#4#5#6#7#8#9 {#8} |
| 1775 |
\cs_gset:Npn \use_ix:nnnnnnnnn #1#2#3#4#5#6#7#8#9 {#9} |
| 1776 |
% \end{macrocode} |
| 1777 |
% \end{macro} |
| 1778 |
% |
| 1779 |
% \begin{macro}[EXP]{\use_i_ii:nnn} |
| 1780 |
% \begin{macrocode} |
| 1781 |
\cs_gset:Npn \use_i_ii:nnn #1#2#3 {#1#2} |
| 1782 |
% \end{macrocode} |
| 1783 |
% \end{macro} |
| 1784 |
% |
| 1785 |
% \begin{macro}[EXP]{\use_ii_i:nn} |
| 1786 |
% \begin{macrocode} |
| 1787 |
\cs_gset:Npn \use_ii_i:nn #1#2 { #2 #1 } |
| 1788 |
% \end{macrocode} |
| 1789 |
% \end{macro} |
| 1790 |
% |
| 1791 |
% |
| 1792 |
% \begin{macro}[EXP] |
| 1793 |
% { |
| 1794 |
% \use_none_delimit_by_q_nil:w , |
| 1795 |
% \use_none_delimit_by_q_stop:w , |
| 1796 |
% \use_none_delimit_by_q_recursion_stop:w |
| 1797 |
% } |
| 1798 |
% Functions that gobble everything until they see either \cs{q_nil}, |
| 1799 |
% \cs{q_stop}, or \cs{q_recursion_stop}, respectively. |
| 1800 |
% \begin{macrocode} |
| 1801 |
\cs_gset:Npn \use_none_delimit_by_q_nil:w #1 \q_nil { } |
| 1802 |
\cs_gset:Npn \use_none_delimit_by_q_stop:w #1 \q_stop { } |
| 1803 |
\cs_gset:Npn \use_none_delimit_by_q_recursion_stop:w #1 \q_recursion_stop { } |
| 1804 |
% \end{macrocode} |
| 1805 |
% \end{macro} |
| 1806 |
% |
| 1807 |
% \begin{macro}[EXP] |
| 1808 |
% { |
| 1809 |
% \use_i_delimit_by_q_nil:nw , |
| 1810 |
% \use_i_delimit_by_q_stop:nw , |
| 1811 |
% \use_i_delimit_by_q_recursion_stop:nw |
| 1812 |
% } |
| 1813 |
% Same as above but execute first argument after gobbling. Very useful |
| 1814 |
% when you need to skip the rest of a mapping sequence but want an |
| 1815 |
% easy way to control what should be expanded next. |
| 1816 |
% \begin{macrocode} |
| 1817 |
\cs_gset:Npn \use_i_delimit_by_q_nil:nw #1#2 \q_nil {#1} |
| 1818 |
\cs_gset:Npn \use_i_delimit_by_q_stop:nw #1#2 \q_stop {#1} |
| 1819 |
\cs_gset:Npn \use_i_delimit_by_q_recursion_stop:nw |
| 1820 |
#1#2 \q_recursion_stop {#1} |
| 1821 |
% \end{macrocode} |
| 1822 |
% \end{macro} |
| 1823 |
% |
| 1824 |
% \subsection{Gobbling tokens from input} |
| 1825 |
% |
| 1826 |
% \begin{macro}[EXP] |
| 1827 |
% { |
| 1828 |
% \use_none:n, |
| 1829 |
% \use_none:nn, |
| 1830 |
% \use_none:nnn, |
| 1831 |
% \use_none:nnnn, |
| 1832 |
% \use_none:nnnnn, |
| 1833 |
% \use_none:nnnnnn, |
| 1834 |
% \use_none:nnnnnnn, |
| 1835 |
% \use_none:nnnnnnnn, |
| 1836 |
% \use_none:nnnnnnnnn |
| 1837 |
% } |
| 1838 |
% To gobble tokens from the input we use a standard naming convention: |
| 1839 |
% the number of tokens gobbled is given by the number of |n|'s |
| 1840 |
% following the |:| in the name. Although we could define functions to |
| 1841 |
% remove ten arguments or more using separate calls of |
| 1842 |
% \cs{use_none:nnnnn}, this is very non-intuitive to the programmer |
| 1843 |
% who will assume that expanding such a function once takes care |
| 1844 |
% of gobbling all the tokens in one go. |
| 1845 |
% \begin{macrocode} |
| 1846 |
\cs_gset:Npn \use_none:n #1 { } |
| 1847 |
\cs_gset:Npn \use_none:nn #1#2 { } |
| 1848 |
\cs_gset:Npn \use_none:nnn #1#2#3 { } |
| 1849 |
\cs_gset:Npn \use_none:nnnn #1#2#3#4 { } |
| 1850 |
\cs_gset:Npn \use_none:nnnnn #1#2#3#4#5 { } |
| 1851 |
\cs_gset:Npn \use_none:nnnnnn #1#2#3#4#5#6 { } |
| 1852 |
\cs_gset:Npn \use_none:nnnnnnn #1#2#3#4#5#6#7 { } |
| 1853 |
\cs_gset:Npn \use_none:nnnnnnnn #1#2#3#4#5#6#7#8 { } |
| 1854 |
\cs_gset:Npn \use_none:nnnnnnnnn #1#2#3#4#5#6#7#8#9 { } |
| 1855 |
% \end{macrocode} |
| 1856 |
% \end{macro} |
| 1857 |
% |
| 1858 |
% \subsection{Debugging and patching later definitions} |
| 1859 |
% |
| 1860 |
% \begin{macrocode} |
| 1861 |
%<@@=debug> |
| 1862 |
% \end{macrocode} |
| 1863 |
% |
| 1864 |
% \begin{macro}{\__kernel_if_debug:TF} |
| 1865 |
% A more meaningful test of whether debugging is enabled than messing |
| 1866 |
% up with guards. We can also more easily change the logic in one |
| 1867 |
% place then. This is needed primarily for deprecations. |
| 1868 |
% \begin{macrocode} |
| 1869 |
\cs_gset_protected:Npn \__kernel_if_debug:TF #1#2 {#2} |
| 1870 |
% \end{macrocode} |
| 1871 |
% \end{macro} |
| 1872 |
% |
| 1873 |
% \begin{macro}{\debug_on:n, \debug_off:n} |
| 1874 |
% Stubs. |
| 1875 |
% \begin{macrocode} |
| 1876 |
\cs_gset_protected:Npn \debug_on:n #1 |
| 1877 |
{ |
| 1878 |
\sys_load_debug: |
| 1879 |
\cs_if_exist:NT \@@_all_on: |
| 1880 |
{ \debug_on:n {#1} } |
| 1881 |
} |
| 1882 |
\cs_gset_protected:Npn \debug_off:n #1 |
| 1883 |
{ |
| 1884 |
\sys_load_debug: |
| 1885 |
\cs_if_exist:NT \@@_all_on: |
| 1886 |
{ \debug_off:n {#1} } |
| 1887 |
} |
| 1888 |
% \end{macrocode} |
| 1889 |
% \end{macro} |
| 1890 |
% |
| 1891 |
% \begin{macro}{\debug_suspend:, \debug_resume:} |
| 1892 |
% \begin{macrocode} |
| 1893 |
\cs_gset_protected:Npn \debug_suspend: { } |
| 1894 |
\cs_gset_protected:Npn \debug_resume: { } |
| 1895 |
% \end{macrocode} |
| 1896 |
% \end{macro} |
| 1897 |
% |
| 1898 |
% \begin{macro}[EXP] |
| 1899 |
% { |
| 1900 |
% \debug_assert:nN, |
| 1901 |
% \debug_assert:nn, |
| 1902 |
% \debug_assert:nNn, |
| 1903 |
% \debug_assert:nnn |
| 1904 |
% } |
| 1905 |
% \begin{macrocode} |
| 1906 |
\cs_gset:Npn \debug_assert:nN #1#2 { } |
| 1907 |
\cs_gset:Npn \debug_assert:nn #1#2 { } |
| 1908 |
\cs_gset:Npn \debug_assert:nNn #1#2#3 { } |
| 1909 |
\cs_gset:Npn \debug_assert:nnn #1#2#3 { } |
| 1910 |
% \end{macrocode} |
| 1911 |
% \end{macro} |
| 1912 |
% |
| 1913 |
% \begin{macro}{\__kernel_deprecation_code:nn} |
| 1914 |
% \begin{variable}{\g_@@_deprecation_on_tl, \g_@@_deprecation_off_tl} |
| 1915 |
% Make deprecated commands throw errors if the user requests it. |
| 1916 |
% This relies on two token lists, filled up in \pkg{l3deprecation}. |
| 1917 |
% \begin{macrocode} |
| 1918 |
\cs_gset_nopar:Npn \g_@@_deprecation_on_tl { } |
| 1919 |
\cs_gset_nopar:Npn \g_@@_deprecation_off_tl { } |
| 1920 |
\cs_gset_protected:Npn \__kernel_deprecation_code:nn #1#2 |
| 1921 |
{ |
| 1922 |
\tl_gput_right:Nn \g_@@_deprecation_on_tl {#1} |
| 1923 |
\tl_gput_right:Nn \g_@@_deprecation_off_tl {#2} |
| 1924 |
} |
| 1925 |
% \end{macrocode} |
| 1926 |
% \end{variable} |
| 1927 |
% \end{macro} |
| 1928 |
% |
| 1929 |
% \subsection{Conditional processing and definitions} |
| 1930 |
% |
| 1931 |
% \begin{macrocode} |
| 1932 |
%<@@=prg> |
| 1933 |
% \end{macrocode} |
| 1934 |
% |
| 1935 |
% Underneath any predicate function (|_p|) or other conditional forms |
| 1936 |
% (|TF|, etc.) is a built-in logic saying that it after all of the |
| 1937 |
% testing and processing must return the \meta{state} this leaves |
| 1938 |
% \TeX{} in. Therefore, a simple user interface could be something like |
| 1939 |
% \begin{verbatim} |
| 1940 |
% \if_meaning:w #1#2 |
| 1941 |
% \prg_return_true: |
| 1942 |
% \else: |
| 1943 |
% \if_meaning:w #1#3 |
| 1944 |
% \prg_return_true: |
| 1945 |
% \else: |
| 1946 |
% \prg_return_false: |
| 1947 |
% \fi: |
| 1948 |
% \fi: |
| 1949 |
% \end{verbatim} |
| 1950 |
% Usually, a \TeX{} programmer would have to insert a number of |
| 1951 |
% \cs{exp_after:wN}s to ensure the state value is returned at exactly |
| 1952 |
% the point where the last conditional is finished. However, that |
| 1953 |
% obscures the code and forces the \TeX{} programmer to prove that |
| 1954 |
% he/she knows the $2^{n}-1$ table. We therefore provide the simpler |
| 1955 |
% interface. |
| 1956 |
% |
| 1957 |
% \begin{macro}[EXP]{\prg_return_true:, \prg_return_false:} |
| 1958 |
% The idea here is that \cs{exp:w} expands fully any |
| 1959 |
% \cs{else:} and \cs{fi:} that are waiting to be discarded, |
| 1960 |
% before reaching the \cs{exp_end:} which leaves an empty expansion. |
| 1961 |
% The code can then leave either the first or second argument in the |
| 1962 |
% input stream. This means that all of the branching code has to contain |
| 1963 |
% at least two tokens: see how the logical tests are actually implemented |
| 1964 |
% to see this. |
| 1965 |
% \begin{macrocode} |
| 1966 |
\cs_gset:Npn \prg_return_true: |
| 1967 |
{ \exp_after:wN \use_i:nn \exp:w } |
| 1968 |
\cs_gset:Npn \prg_return_false: |
| 1969 |
{ \exp_after:wN \use_ii:nn \exp:w} |
| 1970 |
% \end{macrocode} |
| 1971 |
% An extended state space could be implemented by including a more |
| 1972 |
% elaborate function in place of \cs{use_i:nn}/\cs{use_ii:nn}. Provided |
| 1973 |
% two arguments are absorbed then the code would work. |
| 1974 |
% \end{macro} |
| 1975 |
% |
| 1976 |
% \begin{macro}[EXP]{\@@_use_none_delimit_by_q_recursion_stop:w} |
| 1977 |
% Private version of \cs{use_none_delimit_by_q_recursion_stop:w}. |
| 1978 |
% \begin{macrocode} |
| 1979 |
\cs_gset:Npn \@@_use_none_delimit_by_q_recursion_stop:w |
| 1980 |
#1 \q_@@_recursion_stop { } |
| 1981 |
% \end{macrocode} |
| 1982 |
% \end{macro} |
| 1983 |
% |
| 1984 |
% \begin{macro} |
| 1985 |
% { |
| 1986 |
% \prg_set_conditional:Npnn , |
| 1987 |
% \prg_gset_conditional:Npnn , |
| 1988 |
% \prg_new_conditional:Npnn , |
| 1989 |
% \prg_set_protected_conditional:Npnn , |
| 1990 |
% \prg_gset_protected_conditional:Npnn, |
| 1991 |
% \prg_new_protected_conditional:Npnn |
| 1992 |
% } |
| 1993 |
% \begin{macro}{\@@_generate_conditional_parm:NNNpnn} |
| 1994 |
% The user functions for the types using parameter text from the |
| 1995 |
% programmer. The various functions only differ by which function is |
| 1996 |
% used for the assignment. For those |Npnn| type functions, we must |
| 1997 |
% grab the parameter text, reading everything up to a left brace |
| 1998 |
% before continuing. Then split the base function into name and |
| 1999 |
% signature, and feed \Arg{name} \Arg{signature} \meta{boolean} |
| 2000 |
% \Arg{set~or~new} \Arg{maybe~protected} \Arg{parameters} |{TF,...}| |
| 2001 |
% \Arg{code} to the auxiliary function responsible for defining all |
| 2002 |
% conditionals. |
| 2003 |
% Note that |e| stands for expandable and |p| for protected. |
| 2004 |
% \begin{macrocode} |
| 2005 |
\cs_gset_protected:Npn \prg_set_conditional:Npnn |
| 2006 |
{ \@@_generate_conditional_parm:NNNpnn \cs_set:Npn e } |
| 2007 |
\cs_gset_protected:Npn \prg_gset_conditional:Npnn |
| 2008 |
{ \@@_generate_conditional_parm:NNNpnn \cs_gset:Npn e } |
| 2009 |
\cs_gset_protected:Npn \prg_new_conditional:Npnn |
| 2010 |
{ \@@_generate_conditional_parm:NNNpnn \cs_new:Npn e } |
| 2011 |
\cs_gset_protected:Npn \prg_set_protected_conditional:Npnn |
| 2012 |
{ \@@_generate_conditional_parm:NNNpnn \cs_set_protected:Npn p } |
| 2013 |
\cs_gset_protected:Npn \prg_gset_protected_conditional:Npnn |
| 2014 |
{ \@@_generate_conditional_parm:NNNpnn \cs_gset_protected:Npn p } |
| 2015 |
\cs_gset_protected:Npn \prg_new_protected_conditional:Npnn |
| 2016 |
{ \@@_generate_conditional_parm:NNNpnn \cs_new_protected:Npn p } |
| 2017 |
\cs_gset_protected:Npn \@@_generate_conditional_parm:NNNpnn #1#2#3#4# |
| 2018 |
{ |
| 2019 |
\use:e |
| 2020 |
{ |
| 2021 |
\@@_generate_conditional:nnNNNnnn |
| 2022 |
\cs_split_function:N #3 |
| 2023 |
} |
| 2024 |
#1 #2 {#4} |
| 2025 |
} |
| 2026 |
% \end{macrocode} |
| 2027 |
% \end{macro} |
| 2028 |
% \end{macro} |
| 2029 |
% |
| 2030 |
% \begin{macro} |
| 2031 |
% { |
| 2032 |
% \prg_set_conditional:Nnn , |
| 2033 |
% \prg_gset_conditional:Nnn , |
| 2034 |
% \prg_new_conditional:Nnn , |
| 2035 |
% \prg_set_protected_conditional:Nnn , |
| 2036 |
% \prg_gset_protected_conditional:Nnn, |
| 2037 |
% \prg_new_protected_conditional:Nnn |
| 2038 |
% } |
| 2039 |
% \begin{macro} |
| 2040 |
% { |
| 2041 |
% \@@_generate_conditional_count:NNNnn , |
| 2042 |
% \@@_generate_conditional_count:nnNNNnn |
| 2043 |
% } |
| 2044 |
% The user functions for the types automatically inserting the correct |
| 2045 |
% parameter text based on the signature. The various functions only |
| 2046 |
% differ by which function is used for the assignment. Split the base |
| 2047 |
% function into name and signature. The second auxiliary generates |
| 2048 |
% the parameter text from the number of letters in the signature. |
| 2049 |
% Then feed \Arg{name} \Arg{signature} \meta{boolean} \Arg{set~or~new} |
| 2050 |
% \Arg{maybe~protected} \Arg{parameters} |{TF,...}| \Arg{code} to the |
| 2051 |
% auxiliary function responsible for defining all conditionals. If |
| 2052 |
% the \meta{signature} has more than $9$ letters, the definition is |
| 2053 |
% aborted since \TeX{} macros have at most $9$ arguments. The |
| 2054 |
% erroneous case where the function name contains no colon is captured |
| 2055 |
% later. |
| 2056 |
% \begin{macrocode} |
| 2057 |
\cs_gset_protected:Npn \prg_set_conditional:Nnn |
| 2058 |
{ \@@_generate_conditional_count:NNNnn \cs_set:Npn e } |
| 2059 |
\cs_gset_protected:Npn \prg_gset_conditional:Nnn |
| 2060 |
{ \@@_generate_conditional_count:NNNnn \cs_gset:Npn e } |
| 2061 |
\cs_gset_protected:Npn \prg_new_conditional:Nnn |
| 2062 |
{ \@@_generate_conditional_count:NNNnn \cs_new:Npn e } |
| 2063 |
\cs_gset_protected:Npn \prg_set_protected_conditional:Nnn |
| 2064 |
{ \@@_generate_conditional_count:NNNnn \cs_set_protected:Npn p } |
| 2065 |
\cs_gset_protected:Npn \prg_gset_protected_conditional:Nnn |
| 2066 |
{ \@@_generate_conditional_count:NNNnn \cs_gset_protected:Npn p } |
| 2067 |
\cs_gset_protected:Npn \prg_new_protected_conditional:Nnn |
| 2068 |
{ \@@_generate_conditional_count:NNNnn \cs_new_protected:Npn p } |
| 2069 |
\cs_gset_protected:Npn \@@_generate_conditional_count:NNNnn #1#2#3 |
| 2070 |
{ |
| 2071 |
\use:e |
| 2072 |
{ |
| 2073 |
\@@_generate_conditional_count:nnNNNnn |
| 2074 |
\cs_split_function:N #3 |
| 2075 |
} |
| 2076 |
#1 #2 |
| 2077 |
} |
| 2078 |
\cs_gset_protected:Npn \@@_generate_conditional_count:nnNNNnn #1#2#3#4#5 |
| 2079 |
{ |
| 2080 |
\__kernel_cs_parm_from_arg_count:nnF |
| 2081 |
{ \@@_generate_conditional:nnNNNnnn {#1} {#2} #3 #4 #5 } |
| 2082 |
{ \tl_count:n {#2} } |
| 2083 |
{ |
| 2084 |
\msg_error:nnee { kernel } { bad-number-of-arguments } |
| 2085 |
{ \token_to_str:c { #1 : #2 } } |
| 2086 |
{ \tl_count:n {#2} } |
| 2087 |
\use_none:nn |
| 2088 |
} |
| 2089 |
} |
| 2090 |
% \end{macrocode} |
| 2091 |
% \end{macro} |
| 2092 |
% \end{macro} |
| 2093 |
% |
| 2094 |
% \begin{macro} |
| 2095 |
% { |
| 2096 |
% \@@_generate_conditional:nnNNNnnn, |
| 2097 |
% \@@_generate_conditional:NNnnnnNw, |
| 2098 |
% \@@_generate_conditional_test:w, |
| 2099 |
% \@@_generate_conditional_fast:nw, |
| 2100 |
% } |
| 2101 |
% The workhorse here is going through a list of desired forms, i.e., |
| 2102 |
% |p|, |TF|, |T| and |F|. The first three arguments come from splitting up |
| 2103 |
% the base form of the conditional, which gives the name, signature |
| 2104 |
% and a boolean to signal whether or not there was a colon in the |
| 2105 |
% name. In the absence of a colon, we throw an error and don't define |
| 2106 |
% any conditional. The fourth and fifth arguments build up the |
| 2107 |
% defining function. The sixth is the parameters to use (possibly |
| 2108 |
% empty), the seventh is the list of forms to define, the eighth is the |
| 2109 |
% replacement text which we will augment when defining the forms. |
| 2110 |
% The use of \cs{tl_to_str:n} makes the later loop more robust. |
| 2111 |
% |
| 2112 |
% A large number of our low-level conditionals look like \meta{code} |
| 2113 |
% \cs{prg_return_true:} \cs{else:} \cs{prg_return_false:} \cs{fi:} so |
| 2114 |
% we optimize this special case by calling |
| 2115 |
% \cs{@@_generate_conditional_fast:nw} \Arg{code}. This passes |
| 2116 |
% \cs{use_i:nn} instead of \cs{use_i_ii:nnn} to functions such as |
| 2117 |
% \cs{@@_generate_p_form:wNNnnnnN}. |
| 2118 |
% \begin{macrocode} |
| 2119 |
\cs_gset_protected:Npn \@@_generate_conditional:nnNNNnnn #1#2#3#4#5#6#7#8 |
| 2120 |
{ |
| 2121 |
\if_meaning:w \c_false_bool #3 |
| 2122 |
\msg_error:nne { kernel } { missing-colon } |
| 2123 |
{ \token_to_str:c {#1} } |
| 2124 |
\exp_after:wN \use_none:nn |
| 2125 |
\fi: |
| 2126 |
\use:e |
| 2127 |
{ |
| 2128 |
\exp_not:N \@@_generate_conditional:NNnnnnNw |
| 2129 |
\exp_not:n { #4 #5 {#1} {#2} {#6} } |
| 2130 |
\@@_generate_conditional_test:w |
| 2131 |
#8 \s_@@_mark |
| 2132 |
\@@_generate_conditional_fast:nw |
| 2133 |
\prg_return_true: \else: \prg_return_false: \fi: \s_@@_mark |
| 2134 |
\use_none:n |
| 2135 |
\exp_not:n { {#8} \use_i_ii:nnn } |
| 2136 |
\tl_to_str:n {#7} |
| 2137 |
\exp_not:n { , \q_@@_recursion_tail , \q_@@_recursion_stop } |
| 2138 |
} |
| 2139 |
} |
| 2140 |
\cs_gset:Npn \@@_generate_conditional_test:w |
| 2141 |
#1 \prg_return_true: \else: \prg_return_false: \fi: \s_@@_mark #2 |
| 2142 |
{ #2 {#1} } |
| 2143 |
\cs_gset:Npn \@@_generate_conditional_fast:nw #1#2 \exp_not:n #3 |
| 2144 |
{ \exp_not:n { {#1} \use_i:nn } } |
| 2145 |
% \end{macrocode} |
| 2146 |
% Looping through the list of desired forms. First are six arguments |
| 2147 |
% and seventh is the form. Use the form to call the |
| 2148 |
% correct type. If the form does not exist, the \cs{use:c} |
| 2149 |
% construction results in \tn{relax}, and the error message is |
| 2150 |
% displayed (unless the form is empty, to allow for |{T, , F}|), |
| 2151 |
% then \cs{use_none:nnnnnnnn} cleans up. Otherwise, the |
| 2152 |
% error message is removed by the variant form. |
| 2153 |
% \begin{macrocode} |
| 2154 |
\cs_gset_protected:Npn \@@_generate_conditional:NNnnnnNw #1#2#3#4#5#6#7#8 , |
| 2155 |
{ |
| 2156 |
\if_meaning:w \q_@@_recursion_tail #8 |
| 2157 |
\exp_after:wN \@@_use_none_delimit_by_q_recursion_stop:w |
| 2158 |
\fi: |
| 2159 |
\use:c { @@_generate_ #8 _form:wNNnnnnN } |
| 2160 |
\tl_if_empty:nF {#8} |
| 2161 |
{ |
| 2162 |
\msg_error:nnee |
| 2163 |
{ kernel } { conditional-form-unknown } |
| 2164 |
{#8} { \token_to_str:c { #3 : #4 } } |
| 2165 |
} |
| 2166 |
\use_none:nnnnnnnn |
| 2167 |
\s_@@_stop |
| 2168 |
#1 #2 {#3} {#4} {#5} {#6} #7 |
| 2169 |
\@@_generate_conditional:NNnnnnNw #1 #2 {#3} {#4} {#5} {#6} #7 |
| 2170 |
} |
| 2171 |
% \end{macrocode} |
| 2172 |
% \end{macro} |
| 2173 |
% |
| 2174 |
% \begin{macro} |
| 2175 |
% { |
| 2176 |
% \@@_generate_p_form:wNNnnnnN, |
| 2177 |
% \@@_generate_TF_form:wNNnnnnN, |
| 2178 |
% \@@_generate_T_form:wNNnnnnN, |
| 2179 |
% \@@_generate_F_form:wNNnnnnN |
| 2180 |
% } |
| 2181 |
% \begin{macro}[EXP]{\@@_p_true:w, \@@_T_true:w, \@@_F_true:w, \@@_TF_true:w} |
| 2182 |
% How to generate the various forms. Those functions take the |
| 2183 |
% following arguments: 1: junk, 2: \cs{cs_set:Npn} or similar, 3: |p| |
| 2184 |
% (for protected conditionals) or |e|, 4: function name, 5: signature, |
| 2185 |
% 6: parameter text, 7: replacement (possibly trimmed by |
| 2186 |
% \cs{@@_generate_conditional_fast:nw}), 8: \cs{use_i_ii:nnn} or |
| 2187 |
% \cs{use_i:nn} (for \enquote{fast} conditionals). Remember that the |
| 2188 |
% logic-returning functions expect two arguments to be present after |
| 2189 |
% \cs{exp_end:}: notice the construction of the different variants |
| 2190 |
% relies on this, and that the |TF| and |F| variants will be slightly |
| 2191 |
% faster than the |T| version. The |p| form is only valid for |
| 2192 |
% expandable tests, we check for that by making sure that the second |
| 2193 |
% argument is empty. For \enquote{fast} conditionals, |#7| has an |
| 2194 |
% extra \cs[no-index]{if_\ldots{}}. To optimize a bit further we |
| 2195 |
% don't use \cs{exp_after:wN} \cs{use_ii:nnn} and similar but instead use |
| 2196 |
% \cs{@@_TF_true:w} and similar to swap out the macro after \cs{fi:}. It would |
| 2197 |
% be a tiny bit faster if we directly grabbed the |T| and |F| arguments there, |
| 2198 |
% but if those are actually missing, the recovery from the runaway argument |
| 2199 |
% would not insert \cs{fi:} back, messing up nesting of conditionals. |
| 2200 |
% \begin{macrocode} |
| 2201 |
\cs_gset_protected:Npn \@@_generate_p_form:wNNnnnnN |
| 2202 |
#1 \s_@@_stop #2#3#4#5#6#7#8 |
| 2203 |
{ |
| 2204 |
\if_meaning:w e #3 |
| 2205 |
\exp_after:wN \use_i:nn |
| 2206 |
\else: |
| 2207 |
\exp_after:wN \use_ii:nn |
| 2208 |
\fi: |
| 2209 |
{ |
| 2210 |
#8 |
| 2211 |
{ \exp_args:Nc #2 { #4 _p: #5 } #6 } |
| 2212 |
{ { #7 \exp_end: \c_true_bool \c_false_bool } } |
| 2213 |
{ #7 \@@_p_true:w \fi: \c_false_bool } |
| 2214 |
} |
| 2215 |
{ |
| 2216 |
\msg_error:nne { kernel } { protected-predicate } |
| 2217 |
{ \token_to_str:c { #4 _p: #5 } } |
| 2218 |
} |
| 2219 |
} |
| 2220 |
\cs_gset_protected:Npn \@@_generate_T_form:wNNnnnnN |
| 2221 |
#1 \s_@@_stop #2#3#4#5#6#7#8 |
| 2222 |
{ |
| 2223 |
#8 |
| 2224 |
{ \exp_args:Nc #2 { #4 : #5 T } #6 } |
| 2225 |
{ { #7 \exp_end: \use:n \use_none:n } } |
| 2226 |
{ #7 \@@_T_true:w \fi: \use_none:n } |
| 2227 |
} |
| 2228 |
\cs_gset_protected:Npn \@@_generate_F_form:wNNnnnnN |
| 2229 |
#1 \s_@@_stop #2#3#4#5#6#7#8 |
| 2230 |
{ |
| 2231 |
#8 |
| 2232 |
{ \exp_args:Nc #2 { #4 : #5 F } #6 } |
| 2233 |
{ { #7 \exp_end: { } } } |
| 2234 |
{ #7 \@@_F_true:w \fi: \use:n } |
| 2235 |
} |
| 2236 |
\cs_gset_protected:Npn \@@_generate_TF_form:wNNnnnnN |
| 2237 |
#1 \s_@@_stop #2#3#4#5#6#7#8 |
| 2238 |
{ |
| 2239 |
#8 |
| 2240 |
{ \exp_args:Nc #2 { #4 : #5 TF } #6 } |
| 2241 |
{ { #7 \exp_end: } } |
| 2242 |
{ #7 \@@_TF_true:w \fi: \use_ii:nn } |
| 2243 |
} |
| 2244 |
\cs_gset:Npn \@@_p_true:w \fi: \c_false_bool { \fi: \c_true_bool } |
| 2245 |
\cs_gset:Npn \@@_T_true:w \fi: \use_none:n { \fi: \use:n } |
| 2246 |
\cs_gset:Npn \@@_F_true:w \fi: \use:n { \fi: \use_none:n } |
| 2247 |
\cs_gset:Npn \@@_TF_true:w \fi: \use_ii:nn { \fi: \use_i:nn } |
| 2248 |
% \end{macrocode} |
| 2249 |
% \end{macro} |
| 2250 |
% \end{macro} |
| 2251 |
% |
| 2252 |
% \begin{macro} |
| 2253 |
% { |
| 2254 |
% \prg_set_eq_conditional:NNn , |
| 2255 |
% \prg_gset_eq_conditional:NNn, |
| 2256 |
% \prg_new_eq_conditional:NNn |
| 2257 |
% } |
| 2258 |
% \begin{macro}{\@@_set_eq_conditional:NNNn} |
| 2259 |
% The setting-equal functions. Split both functions and feed |
| 2260 |
% \Arg{name_1} \Arg{signature_1} \meta{boolean_1} |
| 2261 |
% \Arg{name_2} \Arg{signature_2} \meta{boolean_2} |
| 2262 |
% \meta{copying~function} \meta{conditions} |,| \cs{q_@@_recursion_tail} |
| 2263 |
% |,| \cs{q_@@_recursion_stop} |
| 2264 |
% to a first auxiliary. |
| 2265 |
% \begin{macrocode} |
| 2266 |
\cs_gset_protected:Npn \prg_set_eq_conditional:NNn |
| 2267 |
{ \@@_set_eq_conditional:NNNn \cs_set_eq:cc } |
| 2268 |
\cs_gset_protected:Npn \prg_gset_eq_conditional:NNn |
| 2269 |
{ \@@_set_eq_conditional:NNNn \cs_gset_eq:cc } |
| 2270 |
\cs_gset_protected:Npn \prg_new_eq_conditional:NNn |
| 2271 |
{ \@@_set_eq_conditional:NNNn \cs_new_eq:cc } |
| 2272 |
\cs_gset_protected:Npn \@@_set_eq_conditional:NNNn #1#2#3#4 |
| 2273 |
{ |
| 2274 |
\use:e |
| 2275 |
{ |
| 2276 |
\exp_not:N \@@_set_eq_conditional:nnNnnNNw |
| 2277 |
\cs_split_function:N #2 |
| 2278 |
\cs_split_function:N #3 |
| 2279 |
\exp_not:N #1 |
| 2280 |
\tl_to_str:n {#4} |
| 2281 |
\exp_not:n { , \q_@@_recursion_tail , \q_@@_recursion_stop } |
| 2282 |
} |
| 2283 |
} |
| 2284 |
% \end{macrocode} |
| 2285 |
% \end{macro} |
| 2286 |
% \end{macro} |
| 2287 |
% |
| 2288 |
% \begin{macro} |
| 2289 |
% { |
| 2290 |
% \@@_set_eq_conditional:nnNnnNNw , |
| 2291 |
% \@@_set_eq_conditional_loop:nnnnNw |
| 2292 |
% } |
| 2293 |
% \begin{macro}[EXP] |
| 2294 |
% { |
| 2295 |
% \@@_set_eq_conditional_p_form:nnn , |
| 2296 |
% \@@_set_eq_conditional_TF_form:nnn , |
| 2297 |
% \@@_set_eq_conditional_T_form:nnn , |
| 2298 |
% \@@_set_eq_conditional_F_form:nnn , |
| 2299 |
% } |
| 2300 |
% Split the function to be defined, and setup a manual clist loop over |
| 2301 |
% argument |#6| of the first auxiliary. The second auxiliary receives |
| 2302 |
% twice three arguments coming from splitting the function to be |
| 2303 |
% defined and the function to copy. Make sure that both functions |
| 2304 |
% contained a colon, otherwise we don't know how to build |
| 2305 |
% conditionals, hence abort. Call the looping macro, with arguments |
| 2306 |
% \Arg{name_1} \Arg{signature_1} \Arg{name_2} \Arg{signature_2} |
| 2307 |
% \meta{copying~function} and followed by the comma list. At each |
| 2308 |
% step in the loop, make sure that the conditional form we copy is |
| 2309 |
% defined, and copy it, otherwise abort. |
| 2310 |
% \begin{macrocode} |
| 2311 |
\cs_gset_protected:Npn \@@_set_eq_conditional:nnNnnNNw #1#2#3#4#5#6 |
| 2312 |
{ |
| 2313 |
\if_meaning:w \c_false_bool #3 |
| 2314 |
\msg_error:nne { kernel } { missing-colon } |
| 2315 |
{ \token_to_str:c {#1} } |
| 2316 |
\exp_after:wN \@@_use_none_delimit_by_q_recursion_stop:w |
| 2317 |
\fi: |
| 2318 |
\if_meaning:w \c_false_bool #6 |
| 2319 |
\msg_error:nne { kernel } { missing-colon } |
| 2320 |
{ \token_to_str:c {#4} } |
| 2321 |
\exp_after:wN \@@_use_none_delimit_by_q_recursion_stop:w |
| 2322 |
\fi: |
| 2323 |
\@@_set_eq_conditional_loop:nnnnNw {#1} {#2} {#4} {#5} |
| 2324 |
} |
| 2325 |
\cs_gset_protected:Npn \@@_set_eq_conditional_loop:nnnnNw #1#2#3#4#5#6 , |
| 2326 |
{ |
| 2327 |
\if_meaning:w \q_@@_recursion_tail #6 |
| 2328 |
\exp_after:wN \@@_use_none_delimit_by_q_recursion_stop:w |
| 2329 |
\fi: |
| 2330 |
\use:c { @@_set_eq_conditional_ #6 _form:wNnnnn } |
| 2331 |
\tl_if_empty:nF {#6} |
| 2332 |
{ |
| 2333 |
\msg_error:nnee |
| 2334 |
{ kernel } { conditional-form-unknown } |
| 2335 |
{#6} { \token_to_str:c { #1 : #2 } } |
| 2336 |
} |
| 2337 |
\use_none:nnnnnn |
| 2338 |
\s_@@_stop |
| 2339 |
#5 {#1} {#2} {#3} {#4} |
| 2340 |
\@@_set_eq_conditional_loop:nnnnNw {#1} {#2} {#3} {#4} #5 |
| 2341 |
} |
| 2342 |
\cs_gset:Npn \@@_set_eq_conditional_p_form:wNnnnn #1 \s_@@_stop #2#3#4#5#6 |
| 2343 |
{ #2 { #3 _p : #4 } { #5 _p : #6 } } |
| 2344 |
\cs_gset:Npn \@@_set_eq_conditional_TF_form:wNnnnn #1 \s_@@_stop #2#3#4#5#6 |
| 2345 |
{ #2 { #3 : #4 TF } { #5 : #6 TF } } |
| 2346 |
\cs_gset:Npn \@@_set_eq_conditional_T_form:wNnnnn #1 \s_@@_stop #2#3#4#5#6 |
| 2347 |
{ #2 { #3 : #4 T } { #5 : #6 T } } |
| 2348 |
\cs_gset:Npn \@@_set_eq_conditional_F_form:wNnnnn #1 \s_@@_stop #2#3#4#5#6 |
| 2349 |
{ #2 { #3 : #4 F } { #5 : #6 F } } |
| 2350 |
% \end{macrocode} |
| 2351 |
% \end{macro} |
| 2352 |
% \end{macro} |
| 2353 |
% |
| 2354 |
% All that is left is to define the canonical boolean true and false. |
| 2355 |
% I think Michael originated the idea of expandable boolean tests. At |
| 2356 |
% first these were supposed to expand into either \texttt{TT} or |
| 2357 |
% \texttt{TF} to be tested using \cs{if:w} but this was later changed to |
| 2358 |
% |00| and |01|, so they could be used in logical |
| 2359 |
% operations. Later again they were changed to being numerical |
| 2360 |
% constants with values of $1$ for true and $0$ for false. We need |
| 2361 |
% this from the get-go. |
| 2362 |
% |
| 2363 |
% \begin{variable}{\c_true_bool, \c_false_bool} |
| 2364 |
% Here are the canonical boolean values. |
| 2365 |
% \begin{macrocode} |
| 2366 |
\tex_global:D \tex_chardef:D \c_true_bool = 1 ~ |
| 2367 |
\tex_global:D \tex_chardef:D \c_false_bool = 0 ~ |
| 2368 |
% \end{macrocode} |
| 2369 |
% \end{variable} |
| 2370 |
% |
| 2371 |
% \subsection{Dissecting a control sequence} |
| 2372 |
% |
| 2373 |
% \begin{macrocode} |
| 2374 |
%<@@=cs> |
| 2375 |
% \end{macrocode} |
| 2376 |
% |
| 2377 |
% \begin{function}[EXP]{\@@_count_signature:N} |
| 2378 |
% \begin{syntax} |
| 2379 |
% \cs{@@_count_signature:N} \meta{function} |
| 2380 |
% \end{syntax} |
| 2381 |
% Splits the \meta{function} into the \meta{name} (i.e., the part |
| 2382 |
% before the colon) and the \meta{signature} (i.e., after the colon). |
| 2383 |
% The \meta{number} of tokens in the \meta{signature} is then left in |
| 2384 |
% the input stream. If there was no \meta{signature} then the result is |
| 2385 |
% the marker value $-1$. |
| 2386 |
% \end{function} |
| 2387 |
% |
| 2388 |
% \begin{function}{\@@_tmp:w} |
| 2389 |
% Function used for various short-term usages, for instance defining |
| 2390 |
% functions whose definition involves tokens which are hard to insert |
| 2391 |
% normally (spaces, characters with category other). |
| 2392 |
% \end{function} |
| 2393 |
% |
| 2394 |
% \begin{macro}[EXP]{\cs_to_str:N} |
| 2395 |
% \begin{macro}[EXP]{\@@_to_str:N, \@@_to_str:w} |
| 2396 |
% This converts a control sequence into the character string of its |
| 2397 |
% name, removing the leading escape character. This turns out to be |
| 2398 |
% a non-trivial matter as there a different cases: |
| 2399 |
% \begin{itemize} |
| 2400 |
% \item The usual case of a printable escape character; |
| 2401 |
% \item the case of a non-printable escape characters, e.g., when |
| 2402 |
% the value of the \tn{escapechar} is negative; |
| 2403 |
% \item when the escape character is a space. |
| 2404 |
% \end{itemize} |
| 2405 |
% One approach to solve this is to test how many tokens result from |
| 2406 |
% |\token_to_str:N \a|. If there are two tokens, then the escape |
| 2407 |
% character is printable, while if it is non-printable then only |
| 2408 |
% one is present. |
| 2409 |
% |
| 2410 |
% However, there is an additional complication: the control |
| 2411 |
% sequence itself may start with a space. Clearly that should \emph{not} be |
| 2412 |
% lost in the process of converting to a string. So the approach adopted is |
| 2413 |
% a little more intricate still. When the escape character is printable, |
| 2414 |
% \verb*|\token_to_str:N \ | yields the escape character itself and a space. |
| 2415 |
% The character codes are different, thus the \cs{if:w} test is false, |
| 2416 |
% and \TeX{} reads \cs{@@_to_str:N} after turning the following |
| 2417 |
% control sequence into a string; this auxiliary removes the escape |
| 2418 |
% character, and stops the expansion of the initial \cs{tex_romannumeral:D}. |
| 2419 |
% The second case is that the escape character is not printable. Then |
| 2420 |
% the \cs{if:w} test is unfinished after reading a the space from |
| 2421 |
% \verb*|\token_to_str:N \ |, and the auxiliary \cs{@@_to_str:w} |
| 2422 |
% is expanded, feeding |-| as a second character for the test; |
| 2423 |
% the test is false, and \TeX{} skips to \cs{fi:}, then performs |
| 2424 |
% \cs{token_to_str:N}, and stops the \cs{tex_romannumeral:D} with \cs{c_zero_int}. |
| 2425 |
% The last case is that the escape character is itself a space. In this |
| 2426 |
% case, the \cs{if:w} test is true, and the auxiliary \cs{@@_to_str:w} |
| 2427 |
% comes into play, inserting |-\int_value:w|, which expands \cs{c_zero_int} |
| 2428 |
% to the character |0|. The initial \cs{tex_romannumeral:D} then sees |
| 2429 |
% |0|, which is not a terminated number, followed by the escape character, |
| 2430 |
% a space, which is removed, terminating the expansion of |
| 2431 |
% \cs{tex_romannumeral:D}. |
| 2432 |
% In all three cases, \cs{cs_to_str:N} takes two expansion steps |
| 2433 |
% to be fully expanded. |
| 2434 |
% \begin{macrocode} |
| 2435 |
\cs_gset:Npn \cs_to_str:N |
| 2436 |
{ |
| 2437 |
% \end{macrocode} |
| 2438 |
% We implement the expansion scheme using \cs{tex_romannumeral:D} |
| 2439 |
% terminating it with \cs{c_zero_int} rather than using \cs{exp:w} and |
| 2440 |
% \cs{exp_end:} as we normally do. The reason is that the code |
| 2441 |
% heavily depends on terminating the expansion with \cs{c_zero_int} so |
| 2442 |
% we make this dependency explicit. |
| 2443 |
% \begin{macrocode} |
| 2444 |
\tex_romannumeral:D |
| 2445 |
\if:w \token_to_str:N \ \@@_to_str:w \fi: |
| 2446 |
\exp_after:wN \@@_to_str:N \token_to_str:N |
| 2447 |
} |
| 2448 |
\cs_gset:Npn \@@_to_str:N #1 { \c_zero_int } |
| 2449 |
\cs_gset:Npn \@@_to_str:w #1 \@@_to_str:N |
| 2450 |
{ - \int_value:w \fi: \exp_after:wN \c_zero_int } |
| 2451 |
% \end{macrocode} |
| 2452 |
% If speed is a concern we could use \tn{csstring} in \LuaTeX{}. For |
| 2453 |
% the empty csname that primitive gives an empty result while the |
| 2454 |
% current \cs{cs_to_str:N} gives incorrect results in all engines |
| 2455 |
% (this is impossible to fix without huge performance hit). |
| 2456 |
% \end{macro} |
| 2457 |
% \end{macro} |
| 2458 |
% |
| 2459 |
% \begin{macro}[EXP]{\cs_split_function:N} |
| 2460 |
% \begin{macro}[EXP] |
| 2461 |
% {\@@_split_function_auxi:w, \@@_split_function_auxii:w} |
| 2462 |
% This function takes a function name and splits it into name with |
| 2463 |
% the escape char removed and argument specification. In addition to |
| 2464 |
% this, a third argument, a boolean \meta{true} or \meta{false} is |
| 2465 |
% returned with \meta{true} for when there is a colon in the function |
| 2466 |
% and \meta{false} if there is not. |
| 2467 |
% |
| 2468 |
% First ensure that we actually get a properly evaluated string by |
| 2469 |
% expanding \cs{cs_to_str:N} twice. If the function contained a |
| 2470 |
% colon, the auxiliary takes as |#1| the function name, delimited by |
| 2471 |
% the first colon, then the signature |#2|, delimited by \cs{s_@@_mark}, |
| 2472 |
% then \cs{c_true_bool} as |#3|, and |#4| cleans up until \cs{s_@@_stop}. |
| 2473 |
% Otherwise, the |#1| contains the function name and \cs{s_@@_mark} |
| 2474 |
% \cs{c_true_bool}, |#2| is empty, |#3| is \cs{c_false_bool}, and |#4| |
| 2475 |
% cleans up. The second |
| 2476 |
% auxiliary trims the trailing \cs{s_@@_mark} from the function name if |
| 2477 |
% present (that is, if the original function had no colon). |
| 2478 |
% \begin{macrocode} |
| 2479 |
\cs_gset_protected:Npn \@@_tmp:w #1 |
| 2480 |
{ |
| 2481 |
\cs_gset:Npn \cs_split_function:N ##1 |
| 2482 |
{ |
| 2483 |
\exp_after:wN \exp_after:wN \exp_after:wN |
| 2484 |
\@@_split_function_auxi:w |
| 2485 |
\cs_to_str:N ##1 \s_@@_mark \c_true_bool |
| 2486 |
#1 \s_@@_mark \c_false_bool \s_@@_stop |
| 2487 |
} |
| 2488 |
\cs_gset:Npn \@@_split_function_auxi:w |
| 2489 |
##1 #1 ##2 \s_@@_mark ##3##4 \s_@@_stop |
| 2490 |
{ \@@_split_function_auxii:w ##1 \s_@@_mark \s_@@_stop {##2} ##3 } |
| 2491 |
\cs_gset:Npn \@@_split_function_auxii:w ##1 \s_@@_mark ##2 \s_@@_stop |
| 2492 |
{ {##1} } |
| 2493 |
} |
| 2494 |
\exp_after:wN \@@_tmp:w \token_to_str:N : |
| 2495 |
% \end{macrocode} |
| 2496 |
% \end{macro} |
| 2497 |
% \end{macro} |
| 2498 |
% |
| 2499 |
% \subsection{Exist or free} |
| 2500 |
% |
| 2501 |
% A control sequence is said to \emph{exist} (to be used) if it has an entry in |
| 2502 |
% the hash table and its meaning is different from the primitive |
| 2503 |
% \tn{relax} token. A control sequence is said to be \emph{free} |
| 2504 |
% (to be defined) if it does not already exist. |
| 2505 |
% |
| 2506 |
% \begin{macro}[pTF, EXP]{\cs_if_exist:N, \cs_if_exist:c} |
| 2507 |
% \begin{macro}{\@@_if_exist_c_aux:,\@@_if_exist_c_aux:w} |
| 2508 |
% Two versions for checking existence. For the |N| form we firstly |
| 2509 |
% check for \cs{scan_stop:} and then if it is in the hash |
| 2510 |
% table. There is no problem when inputting something like \cs{else:} |
| 2511 |
% or \cs{fi:} as \TeX{} will only ever skip input in case the token |
| 2512 |
% tested against is \cs{scan_stop:}. |
| 2513 |
% |
| 2514 |
% In both the |N| and |c| form we use the way \cs{prg_set_conditional:Npnn} |
| 2515 |
% optimizes the conditionals to negate the tests using \cs{else:} (the |
| 2516 |
% \cs{else:} in the top level functions will be removed by the optimization, |
| 2517 |
% and this usage of \cs{else:} will be fine). |
| 2518 |
% \begin{macrocode} |
| 2519 |
\prg_gset_conditional:Npnn \cs_if_exist:N #1 { p , T , F , TF } |
| 2520 |
{ |
| 2521 |
\if_meaning:w #1 \scan_stop: |
| 2522 |
\use_i:nnnn |
| 2523 |
\else: |
| 2524 |
\fi: |
| 2525 |
\if_cs_exist:N #1 |
| 2526 |
\prg_return_true: |
| 2527 |
\else: |
| 2528 |
\prg_return_false: |
| 2529 |
\fi: |
| 2530 |
} |
| 2531 |
% \end{macrocode} |
| 2532 |
% For the |c| form we firstly check if it is in the hash table and |
| 2533 |
% then for \cs{scan_stop:} so that we do not add it to the hash table |
| 2534 |
% unless it was already there. Here we have to be careful as the text |
| 2535 |
% to be skipped if the first test is false may contain tokens that |
| 2536 |
% disturb the scanner. Therefore, we ensure that the second test is |
| 2537 |
% performed after the first one has concluded completely. |
| 2538 |
% \begin{macrocode} |
| 2539 |
\cs_if_exist:NTF \tex_lastnamedcs:D |
| 2540 |
{ |
| 2541 |
\prg_gset_conditional:Npnn \cs_if_exist:c #1 { p , T , F , TF } |
| 2542 |
{ |
| 2543 |
\if_cs_exist:w #1 \cs_end: |
| 2544 |
\@@_if_exist_c_aux: |
| 2545 |
\prg_return_true: |
| 2546 |
\else: |
| 2547 |
\prg_return_false: |
| 2548 |
\fi: |
| 2549 |
} |
| 2550 |
\cs_gset:Npn \@@_if_exist_c_aux: |
| 2551 |
{ \fi: \exp_after:wN \if_meaning:w \tex_lastnamedcs:D \scan_stop: \else: } |
| 2552 |
} |
| 2553 |
{ |
| 2554 |
\prg_gset_conditional:Npnn \cs_if_exist:c #1 { p , T , F , TF } |
| 2555 |
{ |
| 2556 |
\if_cs_exist:w #1 \cs_end: |
| 2557 |
\@@_if_exist_c_aux:w |
| 2558 |
\fi: |
| 2559 |
\use_none:n {#1} |
| 2560 |
\if_false: |
| 2561 |
\prg_return_true: |
| 2562 |
\else: |
| 2563 |
\prg_return_false: |
| 2564 |
\fi: |
| 2565 |
} |
| 2566 |
\cs_gset:Npn \@@_if_exist_c_aux:w \fi: \use_none:n #1 \if_false: |
| 2567 |
{ \fi: \exp_after:wN \if_meaning:w \cs:w #1 \cs_end: \scan_stop: \else: } |
| 2568 |
} |
| 2569 |
% \end{macrocode} |
| 2570 |
% \end{macro} |
| 2571 |
% \end{macro} |
| 2572 |
% |
| 2573 |
% \begin{macro}[pTF, EXP]{\cs_if_free:N, \cs_if_free:c} |
| 2574 |
% The logical reversal of the above. |
| 2575 |
% \begin{macrocode} |
| 2576 |
\prg_gset_conditional:Npnn \cs_if_free:N #1 { p , T , F , TF } |
| 2577 |
{ |
| 2578 |
\if_cs_exist:N #1 |
| 2579 |
\else: |
| 2580 |
\use_none:nnnn |
| 2581 |
\fi: |
| 2582 |
\if_meaning:w #1 \scan_stop: |
| 2583 |
\prg_return_true: |
| 2584 |
\else: |
| 2585 |
\prg_return_false: |
| 2586 |
\fi: |
| 2587 |
} |
| 2588 |
\cs_if_exist:NTF \tex_lastnamedcs:D |
| 2589 |
{ |
| 2590 |
\prg_gset_conditional:Npnn \cs_if_free:c #1 { p , T , F , TF } |
| 2591 |
{ |
| 2592 |
\if_cs_exist:w #1 \cs_end: |
| 2593 |
\@@_if_free_c_aux:w |
| 2594 |
\fi: |
| 2595 |
\if_true: |
| 2596 |
\prg_return_true: |
| 2597 |
\else: |
| 2598 |
\prg_return_false: |
| 2599 |
\fi: |
| 2600 |
} |
| 2601 |
\cs_gset:Npn \@@_if_free_c_aux:w \fi: \if_true: |
| 2602 |
{ \fi: \exp_after:wN \if_meaning:w \tex_lastnamedcs:D \scan_stop: } |
| 2603 |
} |
| 2604 |
{ |
| 2605 |
\prg_gset_conditional:Npnn \cs_if_free:c #1 { p , T , F , TF } |
| 2606 |
{ |
| 2607 |
\if_cs_exist:w #1 \cs_end: |
| 2608 |
\@@_if_free_c_aux:w |
| 2609 |
\fi: |
| 2610 |
\use_none:n {#1} |
| 2611 |
\if_true: |
| 2612 |
\prg_return_true: |
| 2613 |
\else: |
| 2614 |
\prg_return_false: |
| 2615 |
\fi: |
| 2616 |
} |
| 2617 |
\cs_gset:Npn \@@_if_free_c_aux:w \fi: \use_none:n #1 \if_true: |
| 2618 |
{ \fi: \exp_after:wN \if_meaning:w \cs:w #1 \cs_end: \scan_stop: } |
| 2619 |
} |
| 2620 |
% \end{macrocode} |
| 2621 |
% \end{macro} |
| 2622 |
% |
| 2623 |
% \begin{macro}[EXP,noTF] |
| 2624 |
% {\cs_if_exist_use:N, \cs_if_exist_use:c} |
| 2625 |
% \begin{macro}{\@@_if_exist_use_aux:w, \@@_if_exist_use_aux:Nnn} |
| 2626 |
% The \cs[index=cs_if_exist_use:N]{cs_if_exist_use:\ldots{}} |
| 2627 |
% functions cannot be implemented |
| 2628 |
% as conditionals because the true branch must leave both the control |
| 2629 |
% sequence itself and the true code in the input stream. |
| 2630 |
% For the \texttt{c} variants, we are careful not to put the control |
| 2631 |
% sequence in the hash table if it does not exist. |
| 2632 |
% If available we use the \tn{lastnamedcs} primitive. |
| 2633 |
% \begin{macrocode} |
| 2634 |
\cs_gset:Npn \cs_if_exist_use:NTF #1#2 |
| 2635 |
{ \cs_if_exist:NTF #1 { #1 #2 } } |
| 2636 |
\cs_gset:Npn \cs_if_exist_use:NF #1 |
| 2637 |
{ \cs_if_exist:NTF #1 #1 } |
| 2638 |
\cs_gset:Npn \cs_if_exist_use:NT #1 #2 |
| 2639 |
{ \cs_if_exist:NT #1 { #1 #2 } } |
| 2640 |
\cs_gset:Npn \cs_if_exist_use:N #1 |
| 2641 |
{ \cs_if_exist:NT #1 #1 } |
| 2642 |
\cs_if_exist:NTF \tex_lastnamedcs:D |
| 2643 |
{ |
| 2644 |
\cs_gset:Npn \cs_if_exist_use:cTF #1 |
| 2645 |
{ |
| 2646 |
\if_cs_exist:w #1 \cs_end: |
| 2647 |
\@@_if_exist_use_aux:w |
| 2648 |
\fi: |
| 2649 |
\use_ii:nn |
| 2650 |
} |
| 2651 |
\cs_gset:Npn \@@_if_exist_use_aux:w \fi: \use_ii:nn |
| 2652 |
{ \fi: \exp_after:wN \@@_if_exist_use_aux:Nnn \tex_lastnamedcs:D } |
| 2653 |
} |
| 2654 |
{ |
| 2655 |
\cs_gset:Npn \cs_if_exist_use:cTF #1 |
| 2656 |
{ |
| 2657 |
\if_cs_exist:w #1 \cs_end: |
| 2658 |
\@@_if_exist_use_aux:w |
| 2659 |
\fi: |
| 2660 |
\use_iii:nnn {#1} |
| 2661 |
} |
| 2662 |
\cs_gset:Npn \@@_if_exist_use_aux:w \fi: \use_iii:nnn #1 |
| 2663 |
{ \fi: \exp_after:wN \@@_if_exist_use_aux:Nnn \cs:w #1 \cs_end: } |
| 2664 |
} |
| 2665 |
\cs_gset:Npn \@@_if_exist_use_aux:Nnn #1#2 |
| 2666 |
{ |
| 2667 |
\if_meaning:w #1 \scan_stop: |
| 2668 |
\exp_after:wN \use_iii:nnn |
| 2669 |
\fi: |
| 2670 |
\use_i:nn { #1 #2 } |
| 2671 |
} |
| 2672 |
\cs_gset:Npn \cs_if_exist_use:cF #1 |
| 2673 |
{ \cs_if_exist_use:cTF {#1} {} } |
| 2674 |
\cs_gset:Npn \cs_if_exist_use:cT #1#2 |
| 2675 |
{ \cs_if_exist_use:cTF {#1} {#2} {} } |
| 2676 |
\cs_gset:Npn \cs_if_exist_use:c #1 |
| 2677 |
{ \cs_if_exist_use:cTF {#1} {} {} } |
| 2678 |
% \end{macrocode} |
| 2679 |
% \end{macro} |
| 2680 |
% \end{macro} |
| 2681 |
% |
| 2682 |
% \subsection{Preliminaries for new functions} |
| 2683 |
% |
| 2684 |
% We provide two kinds of functions that can be used to define |
| 2685 |
% control sequences. On the one hand we have functions that check |
| 2686 |
% if their argument doesn't already exist, they are called |
| 2687 |
% |\..._new|. The second type of defining functions doesn't check |
| 2688 |
% if the argument is already defined. |
| 2689 |
% |
| 2690 |
% Before we can define them, we need some auxiliary macros that allow |
| 2691 |
% us to generate error messages. The next few definitions here are |
| 2692 |
% only temporary, they will be redefined later on. |
| 2693 |
% |
| 2694 |
% \begin{macro}[documented-as = \msg_error:nnnn] |
| 2695 |
% {\msg_error:nnee, \msg_error:nne, \msg_error:nn} |
| 2696 |
% If an internal error occurs before \LaTeX3 has loaded \pkg{l3msg} then |
| 2697 |
% the code should issue a usable if terse error message and halt. This |
| 2698 |
% can only happen if a coding error is made by the team, so this is |
| 2699 |
% a reasonable response. Setting the \tn{newlinechar} is needed, to |
| 2700 |
% turn |^^J| into a proper line break in plain \TeX{}. |
| 2701 |
% \begin{macrocode} |
| 2702 |
\cs_gset_protected:Npn \msg_error:nnee #1#2#3#4 |
| 2703 |
{ |
| 2704 |
\tex_newlinechar:D = `\^^J \scan_stop: |
| 2705 |
\tex_errmessage:D |
| 2706 |
{ |
| 2707 |
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!~! ^^J |
| 2708 |
Argh,~internal~LaTeX3~error! ^^J ^^J |
| 2709 |
Module ~ #1 , ~ message~name~"#2": ^^J |
| 2710 |
Arguments~'#3'~and~'#4' ^^J ^^J |
| 2711 |
This~is~one~for~The~LaTeX3~Project:~bailing~out |
| 2712 |
} |
| 2713 |
\tex_end:D |
| 2714 |
} |
| 2715 |
\cs_gset_protected:Npn \msg_error:nne #1#2#3 |
| 2716 |
{ \msg_error:nnee {#1} {#2} {#3} { } } |
| 2717 |
\cs_gset_protected:Npn \msg_error:nn #1#2 |
| 2718 |
{ \msg_error:nnee {#1} {#2} { } { } } |
| 2719 |
% \end{macrocode} |
| 2720 |
% \end{macro} |
| 2721 |
% |
| 2722 |
% \begin{macro}[rEXP]{\msg_line_context:} |
| 2723 |
% Another one from \pkg{l3msg} which will be altered later. |
| 2724 |
% \begin{macrocode} |
| 2725 |
\cs_gset:Npn \msg_line_context: |
| 2726 |
{ on~line~ \tex_the:D \tex_inputlineno:D } |
| 2727 |
% \end{macrocode} |
| 2728 |
% \end{macro} |
| 2729 |
% |
| 2730 |
% \begin{macro}{\__kernel_chk_if_free_cs:N, \__kernel_chk_if_free_cs:c} |
| 2731 |
% This command is called by \cs{cs_new_nopar:Npn} and \cs{cs_new_eq:NN} |
| 2732 |
% etc.\ |
| 2733 |
% to make sure that the argument sequence is not already in use. If |
| 2734 |
% it is, an error is signaled. It checks if \meta{csname} is |
| 2735 |
% undefined or \cs{scan_stop:}. Otherwise an error message is |
| 2736 |
% issued. We have to make sure we don't put the argument into the |
| 2737 |
% conditional processing since it may be an |\if...| type function! |
| 2738 |
% \begin{macrocode} |
| 2739 |
\cs_gset_protected:Npn \__kernel_chk_if_free_cs:N #1 |
| 2740 |
{ |
| 2741 |
\cs_if_free:NF #1 |
| 2742 |
{ |
| 2743 |
\msg_error:nnee { kernel } { command-already-defined } |
| 2744 |
{ \token_to_str:N #1 } { \token_to_meaning:N #1 } |
| 2745 |
} |
| 2746 |
} |
| 2747 |
\cs_gset_protected:Npn \__kernel_chk_if_free_cs:c |
| 2748 |
{ \exp_args:Nc \__kernel_chk_if_free_cs:N } |
| 2749 |
% \end{macrocode} |
| 2750 |
% \end{macro} |
| 2751 |
% |
| 2752 |
% \subsection{Defining new functions} |
| 2753 |
% |
| 2754 |
% \begin{macrocode} |
| 2755 |
%<@@=cs> |
| 2756 |
% \end{macrocode} |
| 2757 |
% |
| 2758 |
% \begin{macro} |
| 2759 |
% { |
| 2760 |
% \cs_new_nopar:Npn , \cs_new_nopar:Npe , \cs_new_nopar:Npx , |
| 2761 |
% \cs_new:Npn , \cs_new:Npe , \cs_new:Npx , |
| 2762 |
% \cs_new_protected_nopar:Npn , \cs_new_protected_nopar:Npe , \cs_new_protected_nopar:Npx , |
| 2763 |
% \cs_new_protected:Npn , \cs_new_protected:Npe , \cs_new_protected:Npx |
| 2764 |
% } |
| 2765 |
% \begin{macro}{\@@_tmp:w} |
| 2766 |
% Function which check that the control sequence is free before |
| 2767 |
% defining it. |
| 2768 |
% \begin{macrocode} |
| 2769 |
\cs_set:Npn \@@_tmp:w #1#2 |
| 2770 |
{ |
| 2771 |
\cs_gset_protected:Npn #1 ##1 |
| 2772 |
{ |
| 2773 |
\__kernel_chk_if_free_cs:N ##1 |
| 2774 |
#2 ##1 |
| 2775 |
} |
| 2776 |
} |
| 2777 |
\@@_tmp:w \cs_new_nopar:Npn \cs_gset_nopar:Npn |
| 2778 |
\@@_tmp:w \cs_new_nopar:Npe \cs_gset_nopar:Npe |
| 2779 |
\@@_tmp:w \cs_new_nopar:Npx \cs_gset_nopar:Npx |
| 2780 |
\@@_tmp:w \cs_new:Npn \cs_gset:Npn |
| 2781 |
\@@_tmp:w \cs_new:Npe \cs_gset:Npe |
| 2782 |
\@@_tmp:w \cs_new:Npx \cs_gset:Npx |
| 2783 |
\@@_tmp:w \cs_new_protected_nopar:Npn \cs_gset_protected_nopar:Npn |
| 2784 |
\@@_tmp:w \cs_new_protected_nopar:Npe \cs_gset_protected_nopar:Npe |
| 2785 |
\@@_tmp:w \cs_new_protected_nopar:Npx \cs_gset_protected_nopar:Npx |
| 2786 |
\@@_tmp:w \cs_new_protected:Npn \cs_gset_protected:Npn |
| 2787 |
\@@_tmp:w \cs_new_protected:Npe \cs_gset_protected:Npe |
| 2788 |
\@@_tmp:w \cs_new_protected:Npx \cs_gset_protected:Npx |
| 2789 |
% \end{macrocode} |
| 2790 |
% \end{macro} |
| 2791 |
% \end{macro} |
| 2792 |
% |
| 2793 |
% \begin{macro}[documented-as=\cs_set_nopar:Npn] |
| 2794 |
% { |
| 2795 |
% \cs_set_nopar:cpn , \cs_set_nopar:cpe , \cs_set_nopar:cpx , |
| 2796 |
% \cs_gset_nopar:cpn , \cs_gset_nopar:cpe , \cs_gset_nopar:cpx , |
| 2797 |
% \cs_new_nopar:cpn , \cs_new_nopar:cpe , \cs_new_nopar:cpx |
| 2798 |
% } |
| 2799 |
% Like \cs{cs_set_nopar:Npn} and \cs{cs_new_nopar:Npn}, except that the |
| 2800 |
% first argument consists of the sequence of characters that should |
| 2801 |
% be used to form the name of the desired control sequence (the |c| |
| 2802 |
% stands for csname argument, see the expansion module). Global |
| 2803 |
% versions are also provided. |
| 2804 |
% |
| 2805 |
% \cs{cs_set_nopar:cpn}\meta{string}\meta{rep-text} turns \meta{string} |
| 2806 |
% into a csname and then assigns \meta{rep-text} to it by using |
| 2807 |
% \cs{cs_set_nopar:Npn}. This means that there might be a parameter |
| 2808 |
% string between the two arguments. |
| 2809 |
% \begin{macrocode} |
| 2810 |
\cs_set:Npn \@@_tmp:w #1#2 |
| 2811 |
{ \cs_new_protected_nopar:Npn #1 { \exp_args:Nc #2 } } |
| 2812 |
\@@_tmp:w \cs_set_nopar:cpn \cs_set_nopar:Npn |
| 2813 |
\@@_tmp:w \cs_set_nopar:cpe \cs_set_nopar:Npe |
| 2814 |
\@@_tmp:w \cs_set_nopar:cpx \cs_set_nopar:Npx |
| 2815 |
\@@_tmp:w \cs_gset_nopar:cpn \cs_gset_nopar:Npn |
| 2816 |
\@@_tmp:w \cs_gset_nopar:cpe \cs_gset_nopar:Npe |
| 2817 |
\@@_tmp:w \cs_gset_nopar:cpx \cs_gset_nopar:Npx |
| 2818 |
\@@_tmp:w \cs_new_nopar:cpn \cs_new_nopar:Npn |
| 2819 |
\@@_tmp:w \cs_new_nopar:cpe \cs_new_nopar:Npe |
| 2820 |
\@@_tmp:w \cs_new_nopar:cpx \cs_new_nopar:Npx |
| 2821 |
% \end{macrocode} |
| 2822 |
% \end{macro} |
| 2823 |
% |
| 2824 |
% \begin{macro}[documented-as=\cs_set:Npn] |
| 2825 |
% { |
| 2826 |
% \cs_set:cpn , \cs_set:cpe , \cs_set:cpx , |
| 2827 |
% \cs_gset:cpn , \cs_gset:cpe , \cs_gset:cpx , |
| 2828 |
% \cs_new:cpn , \cs_new:cpe , \cs_new:cpx |
| 2829 |
% } |
| 2830 |
% Variants of the \cs{cs_set:Npn} versions which make a csname out |
| 2831 |
% of the first arguments. We may also do this globally. |
| 2832 |
% \begin{macrocode} |
| 2833 |
\@@_tmp:w \cs_set:cpn \cs_set:Npn |
| 2834 |
\@@_tmp:w \cs_set:cpe \cs_set:Npe |
| 2835 |
\@@_tmp:w \cs_set:cpx \cs_set:Npx |
| 2836 |
\@@_tmp:w \cs_gset:cpn \cs_gset:Npn |
| 2837 |
\@@_tmp:w \cs_gset:cpe \cs_gset:Npe |
| 2838 |
\@@_tmp:w \cs_gset:cpx \cs_gset:Npx |
| 2839 |
\@@_tmp:w \cs_new:cpn \cs_new:Npn |
| 2840 |
\@@_tmp:w \cs_new:cpe \cs_new:Npe |
| 2841 |
\@@_tmp:w \cs_new:cpx \cs_new:Npx |
| 2842 |
% \end{macrocode} |
| 2843 |
% \end{macro} |
| 2844 |
% |
| 2845 |
% \begin{macro}[documented-as=\cs_set_protected_nopar:Npn] |
| 2846 |
% { |
| 2847 |
% \cs_set_protected_nopar:cpn , \cs_set_protected_nopar:cpe , \cs_set_protected_nopar:cpx , |
| 2848 |
% \cs_gset_protected_nopar:cpn , \cs_gset_protected_nopar:cpe , \cs_gset_protected_nopar:cpx , |
| 2849 |
% \cs_new_protected_nopar:cpn , \cs_new_protected_nopar:cpe , \cs_new_protected_nopar:cpx |
| 2850 |
% } |
| 2851 |
% Variants of the \cs{cs_set_protected_nopar:Npn} versions which make |
| 2852 |
% a csname out of the first arguments. We may also do this globally. |
| 2853 |
% \begin{macrocode} |
| 2854 |
\@@_tmp:w \cs_set_protected_nopar:cpn \cs_set_protected_nopar:Npn |
| 2855 |
\@@_tmp:w \cs_set_protected_nopar:cpe \cs_set_protected_nopar:Npe |
| 2856 |
\@@_tmp:w \cs_set_protected_nopar:cpx \cs_set_protected_nopar:Npx |
| 2857 |
\@@_tmp:w \cs_gset_protected_nopar:cpn \cs_gset_protected_nopar:Npn |
| 2858 |
\@@_tmp:w \cs_gset_protected_nopar:cpe \cs_gset_protected_nopar:Npe |
| 2859 |
\@@_tmp:w \cs_gset_protected_nopar:cpx \cs_gset_protected_nopar:Npx |
| 2860 |
\@@_tmp:w \cs_new_protected_nopar:cpn \cs_new_protected_nopar:Npn |
| 2861 |
\@@_tmp:w \cs_new_protected_nopar:cpe \cs_new_protected_nopar:Npe |
| 2862 |
\@@_tmp:w \cs_new_protected_nopar:cpx \cs_new_protected_nopar:Npx |
| 2863 |
% \end{macrocode} |
| 2864 |
% \end{macro} |
| 2865 |
% |
| 2866 |
% \begin{macro}[documented-as=\cs_set_protected:Npn] |
| 2867 |
% { |
| 2868 |
% \cs_set_protected:cpn , \cs_set_protected:cpe , \cs_set_protected:cpx , |
| 2869 |
% \cs_gset_protected:cpn , \cs_gset_protected:cpe , \cs_gset_protected:cpx , |
| 2870 |
% \cs_new_protected:cpn , \cs_new_protected:cpe , \cs_new_protected:cpx |
| 2871 |
% } |
| 2872 |
% Variants of the \cs{cs_set_protected:Npn} versions which make a csname |
| 2873 |
% out of the first arguments. We may also do this globally. |
| 2874 |
% \begin{macrocode} |
| 2875 |
\@@_tmp:w \cs_set_protected:cpn \cs_set_protected:Npn |
| 2876 |
\@@_tmp:w \cs_set_protected:cpe \cs_set_protected:Npe |
| 2877 |
\@@_tmp:w \cs_set_protected:cpx \cs_set_protected:Npx |
| 2878 |
\@@_tmp:w \cs_gset_protected:cpn \cs_gset_protected:Npn |
| 2879 |
\@@_tmp:w \cs_gset_protected:cpe \cs_gset_protected:Npe |
| 2880 |
\@@_tmp:w \cs_gset_protected:cpx \cs_gset_protected:Npx |
| 2881 |
\@@_tmp:w \cs_new_protected:cpn \cs_new_protected:Npn |
| 2882 |
\@@_tmp:w \cs_new_protected:cpe \cs_new_protected:Npe |
| 2883 |
\@@_tmp:w \cs_new_protected:cpx \cs_new_protected:Npx |
| 2884 |
% \end{macrocode} |
| 2885 |
% \end{macro} |
| 2886 |
% |
| 2887 |
% \subsection{Copying definitions} |
| 2888 |
% |
| 2889 |
% \begin{macro} |
| 2890 |
% { |
| 2891 |
% \cs_set_eq:NN , \cs_set_eq:cN , \cs_set_eq:Nc , \cs_set_eq:cc , |
| 2892 |
% \cs_gset_eq:NN , \cs_gset_eq:cN , \cs_gset_eq:Nc , \cs_gset_eq:cc , |
| 2893 |
% \cs_new_eq:NN , \cs_new_eq:cN , \cs_new_eq:Nc , \cs_new_eq:cc |
| 2894 |
% } |
| 2895 |
% These macros allow us to copy the definition of a control sequence |
| 2896 |
% to another control sequence. |
| 2897 |
% |
| 2898 |
% The |=| sign allows us to define funny char tokens like |=| itself |
| 2899 |
% or \verb*| | with this function. For the definition of |
| 2900 |
% |\c_space_char{~}| to work we need the |~| after the |=|. |
| 2901 |
% |
| 2902 |
% \cs{cs_set_eq:NN} is long to avoid problems with a literal argument |
| 2903 |
% of \cs{par}. While \cs{cs_new_eq:NN} will probably never be correct |
| 2904 |
% with a first argument of \cs{par}, define it long in order to throw |
| 2905 |
% an \enquote{already defined} error rather than |
| 2906 |
% \enquote{runaway argument}. |
| 2907 |
% \begin{macrocode} |
| 2908 |
\cs_new_protected:Npn \cs_set_eq:NN #1 { \tex_let:D #1 =~ } |
| 2909 |
\cs_new_protected:Npn \cs_set_eq:cN { \exp_args:Nc \cs_set_eq:NN } |
| 2910 |
\cs_new_protected:Npn \cs_set_eq:Nc { \exp_args:NNc \cs_set_eq:NN } |
| 2911 |
\cs_new_protected:Npn \cs_set_eq:cc { \exp_args:Ncc \cs_set_eq:NN } |
| 2912 |
\cs_new_protected:Npn \cs_gset_eq:NN { \tex_global:D \cs_set_eq:NN } |
| 2913 |
\cs_new_protected:Npn \cs_gset_eq:Nc { \exp_args:NNc \cs_gset_eq:NN } |
| 2914 |
\cs_new_protected:Npn \cs_gset_eq:cN { \exp_args:Nc \cs_gset_eq:NN } |
| 2915 |
\cs_new_protected:Npn \cs_gset_eq:cc { \exp_args:Ncc \cs_gset_eq:NN } |
| 2916 |
\cs_new_protected:Npn \cs_new_eq:NN #1 |
| 2917 |
{ |
| 2918 |
\__kernel_chk_if_free_cs:N #1 |
| 2919 |
\tex_global:D \cs_set_eq:NN #1 |
| 2920 |
} |
| 2921 |
\cs_new_protected:Npn \cs_new_eq:cN { \exp_args:Nc \cs_new_eq:NN } |
| 2922 |
\cs_new_protected:Npn \cs_new_eq:Nc { \exp_args:NNc \cs_new_eq:NN } |
| 2923 |
\cs_new_protected:Npn \cs_new_eq:cc { \exp_args:Ncc \cs_new_eq:NN } |
| 2924 |
% \end{macrocode} |
| 2925 |
% \end{macro} |
| 2926 |
% |
| 2927 |
% \subsection{Undefining functions} |
| 2928 |
% |
| 2929 |
% \begin{macro}{\cs_undefine:N, \cs_undefine:c} |
| 2930 |
% The following function is used to free the main memory from the |
| 2931 |
% definition of some function that isn't in use any longer. |
| 2932 |
% The \texttt{c} variant is careful not to add the control sequence |
| 2933 |
% to the hash table if it isn't there yet, and it also avoids nesting |
| 2934 |
% \TeX{} conditionals in case |#1| is unbalanced in this matter. |
| 2935 |
% We optimize the case where the command exists by reducing as much as |
| 2936 |
% possible the tokens in the conditional. |
| 2937 |
% \begin{macrocode} |
| 2938 |
\cs_new_protected:Npn \cs_undefine:N #1 |
| 2939 |
{ \cs_gset_eq:NN #1 \tex_undefined:D } |
| 2940 |
\cs_new_protected:Npn \cs_undefine:c #1 |
| 2941 |
{ |
| 2942 |
\if_cs_exist:w #1 \cs_end: |
| 2943 |
\else: |
| 2944 |
\use_i:nnnn |
| 2945 |
\fi: |
| 2946 |
\exp_args:Nc \cs_undefine:N {#1} |
| 2947 |
} |
| 2948 |
% \end{macrocode} |
| 2949 |
% \end{macro} |
| 2950 |
% |
| 2951 |
% \subsection{Generating parameter text from argument count} |
| 2952 |
% |
| 2953 |
% \begin{macrocode} |
| 2954 |
%<@@=cs> |
| 2955 |
% \end{macrocode} |
| 2956 |
% |
| 2957 |
% \begin{macro}{\__kernel_cs_parm_from_arg_count:nnF} |
| 2958 |
% \begin{macro}{\@@_parm_from_arg_count_test:nnF} |
| 2959 |
% \LaTeX3 provides shorthands to define control sequences and |
| 2960 |
% conditionals with a simple parameter text, derived directly from the |
| 2961 |
% signature, or more generally from knowing the number of arguments, |
| 2962 |
% between~$0$ and~$9$. This function expands to its first argument, |
| 2963 |
% untouched, followed by a brace group containing the parameter text |
| 2964 |
% |{#|$1$\ldots{}|#|$n$|}|, where $n$ is the result of evaluating the |
| 2965 |
% second argument (as described in \cs{int_eval:n}). If the second |
| 2966 |
% argument gives a result outside the range $[0,9]$, the third |
| 2967 |
% argument is returned instead, normally an error message. Some of |
| 2968 |
% the functions use here are not defined yet, but will be defined |
| 2969 |
% before this function is called. |
| 2970 |
% \begin{macrocode} |
| 2971 |
\cs_new_protected:Npn \__kernel_cs_parm_from_arg_count:nnF #1#2 |
| 2972 |
{ |
| 2973 |
\exp_args:Ne \@@_parm_from_arg_count_test:nnF |
| 2974 |
{ |
| 2975 |
\exp_after:wN \exp_not:n |
| 2976 |
\if_case:w \int_eval:n {#2} |
| 2977 |
{ } |
| 2978 |
\or: { ##1 } |
| 2979 |
\or: { ##1##2 } |
| 2980 |
\or: { ##1##2##3 } |
| 2981 |
\or: { ##1##2##3##4 } |
| 2982 |
\or: { ##1##2##3##4##5 } |
| 2983 |
\or: { ##1##2##3##4##5##6 } |
| 2984 |
\or: { ##1##2##3##4##5##6##7 } |
| 2985 |
\or: { ##1##2##3##4##5##6##7##8 } |
| 2986 |
\or: { ##1##2##3##4##5##6##7##8##9 } |
| 2987 |
\else: { \c_false_bool } |
| 2988 |
\fi: |
| 2989 |
} |
| 2990 |
{#1} |
| 2991 |
} |
| 2992 |
\cs_new_protected:Npn \@@_parm_from_arg_count_test:nnF #1#2 |
| 2993 |
{ |
| 2994 |
\if_meaning:w \c_false_bool #1 |
| 2995 |
\exp_after:wN \use_ii:nn |
| 2996 |
\else: |
| 2997 |
\exp_after:wN \use_i:nn |
| 2998 |
\fi: |
| 2999 |
{ #2 {#1} } |
| 3000 |
} |
| 3001 |
% \end{macrocode} |
| 3002 |
% \end{macro} |
| 3003 |
% \end{macro} |
| 3004 |
% |
| 3005 |
% \subsection{Defining functions from a given number of arguments} |
| 3006 |
% |
| 3007 |
% \begin{macrocode} |
| 3008 |
%<@@=cs> |
| 3009 |
% \end{macrocode} |
| 3010 |
% |
| 3011 |
% \begin{macro}[EXP]{\@@_count_signature:N, \@@_count_signature:c} |
| 3012 |
% \begin{macro}[EXP]{\@@_count_signature:n} |
| 3013 |
% \begin{macro}[EXP]{\@@_count_signature:nnN} |
| 3014 |
% Counting the number of tokens in the signature, i.e., the |
| 3015 |
% number of arguments the function should take. Since this is not |
| 3016 |
% used in any time-critical function, we simply use \cs{tl_count:n} if |
| 3017 |
% there is a signature, otherwise $-1$ arguments to signal an error. |
| 3018 |
% We need a variant form right away. |
| 3019 |
% \begin{macrocode} |
| 3020 |
\cs_new:Npn \@@_count_signature:N #1 |
| 3021 |
{ \exp_args:Nf \@@_count_signature:n { \cs_split_function:N #1 } } |
| 3022 |
\cs_new:Npn \@@_count_signature:n #1 |
| 3023 |
{ \int_eval:n { \@@_count_signature:nnN #1 } } |
| 3024 |
\cs_new:Npn \@@_count_signature:nnN #1#2#3 |
| 3025 |
{ |
| 3026 |
\if_meaning:w \c_true_bool #3 |
| 3027 |
\tl_count:n {#2} |
| 3028 |
\else: |
| 3029 |
-1 |
| 3030 |
\fi: |
| 3031 |
} |
| 3032 |
\cs_new:Npn \@@_count_signature:c |
| 3033 |
{ \exp_args:Nc \@@_count_signature:N } |
| 3034 |
% \end{macrocode} |
| 3035 |
% \end{macro} |
| 3036 |
% \end{macro} |
| 3037 |
% \end{macro} |
| 3038 |
% |
| 3039 |
% \begin{macro} |
| 3040 |
% { |
| 3041 |
% \cs_generate_from_arg_count:NNnn, |
| 3042 |
% \cs_generate_from_arg_count:cNnn, |
| 3043 |
% \cs_generate_from_arg_count:Ncnn |
| 3044 |
% } |
| 3045 |
% We provide a constructor function for defining functions with a |
| 3046 |
% given number of arguments. For this we need to choose the correct |
| 3047 |
% parameter text and then use that when defining. Since \TeX{} |
| 3048 |
% supports from zero to nine arguments, we use a simple switch to |
| 3049 |
% choose the correct parameter text, ensuring the result is returned |
| 3050 |
% after finishing the conditional. If it is not between zero and |
| 3051 |
% nine, we throw an error. |
| 3052 |
% |
| 3053 |
% 1: function to define, 2: with what to define it, 3: the number of |
| 3054 |
% args it requires and 4: the replacement text |
| 3055 |
% \begin{macrocode} |
| 3056 |
\cs_new_protected:Npn \cs_generate_from_arg_count:NNnn #1#2#3#4 |
| 3057 |
{ |
| 3058 |
\__kernel_cs_parm_from_arg_count:nnF { \use:nnn #2 #1 } {#3} |
| 3059 |
{ |
| 3060 |
\msg_error:nnee { kernel } { bad-number-of-arguments } |
| 3061 |
{ \token_to_str:N #1 } { \int_eval:n {#3} } |
| 3062 |
\use_none:n |
| 3063 |
} |
| 3064 |
{#4} |
| 3065 |
} |
| 3066 |
% \end{macrocode} |
| 3067 |
% A variant form we need right away, plus one which is used elsewhere but |
| 3068 |
% which is most logically created here. |
| 3069 |
% \begin{macrocode} |
| 3070 |
\cs_new_protected:Npn \cs_generate_from_arg_count:cNnn |
| 3071 |
{ \exp_args:Nc \cs_generate_from_arg_count:NNnn } |
| 3072 |
\cs_new_protected:Npn \cs_generate_from_arg_count:Ncnn |
| 3073 |
{ \exp_args:NNc \cs_generate_from_arg_count:NNnn } |
| 3074 |
% \end{macrocode} |
| 3075 |
% \end{macro} |
| 3076 |
% |
| 3077 |
% \subsection{Using the signature to define functions} |
| 3078 |
% |
| 3079 |
% \begin{macrocode} |
| 3080 |
%<@@=cs> |
| 3081 |
% \end{macrocode} |
| 3082 |
% |
| 3083 |
% We can now combine some of the tools we have to provide a simple |
| 3084 |
% interface for defining functions, where the number of arguments is |
| 3085 |
% read from the signature. For instance, |
| 3086 |
% |\cs_set:Nn \foo_bar:nn {#1,#2}|. |
| 3087 |
% |
| 3088 |
% \begin{macro} |
| 3089 |
% { |
| 3090 |
% \cs_set:Nn , \cs_set:Ne , \cs_set:Nx , |
| 3091 |
% \cs_set_nopar:Nn , \cs_set_nopar:Ne , \cs_set_nopar:Nx , |
| 3092 |
% \cs_set_protected:Nn , \cs_set_protected:Ne , \cs_set_protected:Nx , |
| 3093 |
% \cs_set_protected_nopar:Nn , \cs_set_protected_nopar:Ne , \cs_set_protected_nopar:Nx , |
| 3094 |
% \cs_gset:Nn , \cs_gset:Ne , \cs_gset:Nx , |
| 3095 |
% \cs_gset_nopar:Nn , \cs_gset_nopar:Ne , \cs_gset_nopar:Nx , |
| 3096 |
% \cs_gset_protected:Nn , \cs_gset_protected:Ne , \cs_gset_protected:Nx , |
| 3097 |
% \cs_gset_protected_nopar:Nn , \cs_gset_protected_nopar:Ne , \cs_gset_protected_nopar:Nx , |
| 3098 |
% \cs_new:Nn , \cs_new:Ne , \cs_new:Nx , |
| 3099 |
% \cs_new_nopar:Nn , \cs_new_nopar:Ne , \cs_new_nopar:Nx , |
| 3100 |
% \cs_new_protected:Nn , \cs_new_protected:Ne , \cs_new_protected:Nx , |
| 3101 |
% \cs_new_protected_nopar:Nn , \cs_new_protected_nopar:Ne , \cs_new_protected_nopar:Nx , |
| 3102 |
% } |
| 3103 |
% We want to define \cs{cs_set:Nn} as |
| 3104 |
% \begin{verbatim} |
| 3105 |
% \cs_set_protected:Npn \cs_set:Nn #1#2 |
| 3106 |
% { |
| 3107 |
% \cs_generate_from_arg_count:NNnn #1 \cs_set:Npn |
| 3108 |
% { \@@_count_signature:N #1 } {#2} |
| 3109 |
% } |
| 3110 |
% \end{verbatim} |
| 3111 |
% In short, to define \cs{cs_set:Nn} we need just use \cs{cs_set:Npn}, |
| 3112 |
% everything else is the same for each variant. Therefore, we can |
| 3113 |
% make it simpler by temporarily defining a function to do this for |
| 3114 |
% us. |
| 3115 |
% \begin{macrocode} |
| 3116 |
\cs_set:Npn \@@_tmp:w #1#2#3 |
| 3117 |
{ |
| 3118 |
\cs_new_protected:cpx { cs_ #1 : #2 } |
| 3119 |
{ |
| 3120 |
\exp_not:N \@@_generate_from_signature:NNn |
| 3121 |
\exp_after:wN \exp_not:N \cs:w cs_ #1 : #3 \cs_end: |
| 3122 |
} |
| 3123 |
} |
| 3124 |
\cs_new_protected:Npn \@@_generate_from_signature:NNn #1#2 |
| 3125 |
{ |
| 3126 |
\use:e |
| 3127 |
{ |
| 3128 |
\@@_generate_from_signature:nnNNNn |
| 3129 |
\cs_split_function:N #2 |
| 3130 |
} |
| 3131 |
#1 #2 |
| 3132 |
} |
| 3133 |
\cs_new_protected:Npn \@@_generate_from_signature:nnNNNn #1#2#3#4#5#6 |
| 3134 |
{ |
| 3135 |
\bool_if:NTF #3 |
| 3136 |
{ |
| 3137 |
\cs_set_nopar:Npx \@@_tmp:w |
| 3138 |
{ \tl_map_function:nN {#2} \@@_generate_from_signature:n } |
| 3139 |
\tl_if_empty:oF \@@_tmp:w |
| 3140 |
{ |
| 3141 |
\msg_error:nneee { kernel } { non-base-function } |
| 3142 |
{ \token_to_str:N #5 } {#2} { \@@_tmp:w } |
| 3143 |
} |
| 3144 |
\cs_generate_from_arg_count:NNnn |
| 3145 |
#5 #4 { \tl_count:n {#2} } {#6} |
| 3146 |
} |
| 3147 |
{ |
| 3148 |
\msg_error:nne { kernel } { missing-colon } |
| 3149 |
{ \token_to_str:N #5 } |
| 3150 |
} |
| 3151 |
} |
| 3152 |
\cs_new:Npn \@@_generate_from_signature:n #1 |
| 3153 |
{ |
| 3154 |
\if:w n #1 \else: \if:w N #1 \else: |
| 3155 |
\if:w T #1 \else: \if:w F #1 \else: #1 \fi: \fi: \fi: \fi: |
| 3156 |
} |
| 3157 |
% \end{macrocode} |
| 3158 |
% Then we define the 24 variants beginning with |N|. |
| 3159 |
% \begin{macrocode} |
| 3160 |
\@@_tmp:w { set } { Nn } { Npn } |
| 3161 |
\@@_tmp:w { set } { Ne } { Npe } |
| 3162 |
\@@_tmp:w { set } { Nx } { Npx } |
| 3163 |
\@@_tmp:w { set_nopar } { Nn } { Npn } |
| 3164 |
\@@_tmp:w { set_nopar } { Ne } { Npe } |
| 3165 |
\@@_tmp:w { set_nopar } { Nx } { Npx } |
| 3166 |
\@@_tmp:w { set_protected } { Nn } { Npn } |
| 3167 |
\@@_tmp:w { set_protected } { Ne } { Npe } |
| 3168 |
\@@_tmp:w { set_protected } { Nx } { Npx } |
| 3169 |
\@@_tmp:w { set_protected_nopar } { Nn } { Npn } |
| 3170 |
\@@_tmp:w { set_protected_nopar } { Ne } { Npe } |
| 3171 |
\@@_tmp:w { set_protected_nopar } { Nx } { Npx } |
| 3172 |
\@@_tmp:w { gset } { Nn } { Npn } |
| 3173 |
\@@_tmp:w { gset } { Ne } { Npe } |
| 3174 |
\@@_tmp:w { gset } { Nx } { Npx } |
| 3175 |
\@@_tmp:w { gset_nopar } { Nn } { Npn } |
| 3176 |
\@@_tmp:w { gset_nopar } { Ne } { Npe } |
| 3177 |
\@@_tmp:w { gset_nopar } { Nx } { Npx } |
| 3178 |
\@@_tmp:w { gset_protected } { Nn } { Npn } |
| 3179 |
\@@_tmp:w { gset_protected } { Ne } { Npe } |
| 3180 |
\@@_tmp:w { gset_protected } { Nx } { Npx } |
| 3181 |
\@@_tmp:w { gset_protected_nopar } { Nn } { Npn } |
| 3182 |
\@@_tmp:w { gset_protected_nopar } { Ne } { Npe } |
| 3183 |
\@@_tmp:w { gset_protected_nopar } { Nx } { Npx } |
| 3184 |
\@@_tmp:w { new } { Nn } { Npn } |
| 3185 |
\@@_tmp:w { new } { Ne } { Npe } |
| 3186 |
\@@_tmp:w { new } { Nx } { Npx } |
| 3187 |
\@@_tmp:w { new_nopar } { Nn } { Npn } |
| 3188 |
\@@_tmp:w { new_nopar } { Ne } { Npe } |
| 3189 |
\@@_tmp:w { new_nopar } { Nx } { Npx } |
| 3190 |
\@@_tmp:w { new_protected } { Nn } { Npn } |
| 3191 |
\@@_tmp:w { new_protected } { Ne } { Npe } |
| 3192 |
\@@_tmp:w { new_protected } { Nx } { Npx } |
| 3193 |
\@@_tmp:w { new_protected_nopar } { Nn } { Npn } |
| 3194 |
\@@_tmp:w { new_protected_nopar } { Ne } { Npe } |
| 3195 |
\@@_tmp:w { new_protected_nopar } { Nx } { Npx } |
| 3196 |
% \end{macrocode} |
| 3197 |
% \end{macro} |
| 3198 |
% |
| 3199 |
% \begin{macro}[documented-as=\cs_set:Nn] |
| 3200 |
% { |
| 3201 |
% \cs_set:cn , \cs_set:ce , \cs_set:cx , |
| 3202 |
% \cs_set_nopar:cn , \cs_set_nopar:ce , \cs_set_nopar:cx , |
| 3203 |
% \cs_set_protected:cn , \cs_set_protected:ce , \cs_set_protected:cx , |
| 3204 |
% \cs_set_protected_nopar:cn , \cs_set_protected_nopar:ce , \cs_set_protected_nopar:cx , |
| 3205 |
% \cs_gset:cn , \cs_gset:ce , \cs_gset:cx , |
| 3206 |
% \cs_gset_nopar:cn , \cs_gset_nopar:ce , \cs_gset_nopar:cx , |
| 3207 |
% \cs_gset_protected:cn , \cs_gset_protected:ce , \cs_gset_protected:cx , |
| 3208 |
% \cs_gset_protected_nopar:cn , \cs_gset_protected_nopar:ce , \cs_gset_protected_nopar:cx , |
| 3209 |
% \cs_new:cn , \cs_new:ce , \cs_new:cx , |
| 3210 |
% \cs_new_nopar:cn , \cs_new_nopar:ce , \cs_new_nopar:cx , |
| 3211 |
% \cs_new_protected:cn , \cs_new_protected:ce , \cs_new_protected:cx , |
| 3212 |
% \cs_new_protected_nopar:cn , \cs_new_protected_nopar:ce , \cs_new_protected_nopar:cx , |
| 3213 |
% } |
| 3214 |
% The 24 |c| variants simply use \cs{exp_args:Nc}. |
| 3215 |
% \begin{macrocode} |
| 3216 |
\cs_set:Npn \@@_tmp:w #1#2 |
| 3217 |
{ |
| 3218 |
\cs_new_protected:cpx { cs_ #1 : c #2 } |
| 3219 |
{ |
| 3220 |
\exp_not:N \exp_args:Nc |
| 3221 |
\exp_after:wN \exp_not:N \cs:w cs_ #1 : N #2 \cs_end: |
| 3222 |
} |
| 3223 |
} |
| 3224 |
\@@_tmp:w { set } { n } |
| 3225 |
\@@_tmp:w { set } { e } |
| 3226 |
\@@_tmp:w { set } { x } |
| 3227 |
\@@_tmp:w { set_nopar } { n } |
| 3228 |
\@@_tmp:w { set_nopar } { e } |
| 3229 |
\@@_tmp:w { set_nopar } { x } |
| 3230 |
\@@_tmp:w { set_protected } { n } |
| 3231 |
\@@_tmp:w { set_protected } { e } |
| 3232 |
\@@_tmp:w { set_protected } { x } |
| 3233 |
\@@_tmp:w { set_protected_nopar } { n } |
| 3234 |
\@@_tmp:w { set_protected_nopar } { e } |
| 3235 |
\@@_tmp:w { set_protected_nopar } { x } |
| 3236 |
\@@_tmp:w { gset } { n } |
| 3237 |
\@@_tmp:w { gset } { e } |
| 3238 |
\@@_tmp:w { gset } { x } |
| 3239 |
\@@_tmp:w { gset_nopar } { n } |
| 3240 |
\@@_tmp:w { gset_nopar } { e } |
| 3241 |
\@@_tmp:w { gset_nopar } { x } |
| 3242 |
\@@_tmp:w { gset_protected } { n } |
| 3243 |
\@@_tmp:w { gset_protected } { e } |
| 3244 |
\@@_tmp:w { gset_protected } { x } |
| 3245 |
\@@_tmp:w { gset_protected_nopar } { n } |
| 3246 |
\@@_tmp:w { gset_protected_nopar } { e } |
| 3247 |
\@@_tmp:w { gset_protected_nopar } { x } |
| 3248 |
\@@_tmp:w { new } { n } |
| 3249 |
\@@_tmp:w { new } { e } |
| 3250 |
\@@_tmp:w { new } { x } |
| 3251 |
\@@_tmp:w { new_nopar } { n } |
| 3252 |
\@@_tmp:w { new_nopar } { e } |
| 3253 |
\@@_tmp:w { new_nopar } { x } |
| 3254 |
\@@_tmp:w { new_protected } { n } |
| 3255 |
\@@_tmp:w { new_protected } { e } |
| 3256 |
\@@_tmp:w { new_protected } { x } |
| 3257 |
\@@_tmp:w { new_protected_nopar } { n } |
| 3258 |
\@@_tmp:w { new_protected_nopar } { e } |
| 3259 |
\@@_tmp:w { new_protected_nopar } { x } |
| 3260 |
% \end{macrocode} |
| 3261 |
% \end{macro} |
| 3262 |
% |
| 3263 |
% \subsection{Checking control sequence equality} |
| 3264 |
% |
| 3265 |
% \begin{macro}[pTF, EXP] |
| 3266 |
% {\cs_if_eq:NN, \cs_if_eq:cN, \cs_if_eq:Nc, \cs_if_eq:cc} |
| 3267 |
% Check if two control sequences are identical. |
| 3268 |
% \begin{macrocode} |
| 3269 |
\prg_new_conditional:Npnn \cs_if_eq:NN #1#2 { p , T , F , TF } |
| 3270 |
{ |
| 3271 |
\if_meaning:w #1#2 |
| 3272 |
\prg_return_true: \else: \prg_return_false: \fi: |
| 3273 |
} |
| 3274 |
\cs_new:Npn \cs_if_eq_p:cN { \exp_args:Nc \cs_if_eq_p:NN } |
| 3275 |
\cs_new:Npn \cs_if_eq:cNTF { \exp_args:Nc \cs_if_eq:NNTF } |
| 3276 |
\cs_new:Npn \cs_if_eq:cNT { \exp_args:Nc \cs_if_eq:NNT } |
| 3277 |
\cs_new:Npn \cs_if_eq:cNF { \exp_args:Nc \cs_if_eq:NNF } |
| 3278 |
\cs_new:Npn \cs_if_eq_p:Nc { \exp_args:NNc \cs_if_eq_p:NN } |
| 3279 |
\cs_new:Npn \cs_if_eq:NcTF { \exp_args:NNc \cs_if_eq:NNTF } |
| 3280 |
\cs_new:Npn \cs_if_eq:NcT { \exp_args:NNc \cs_if_eq:NNT } |
| 3281 |
\cs_new:Npn \cs_if_eq:NcF { \exp_args:NNc \cs_if_eq:NNF } |
| 3282 |
\cs_new:Npn \cs_if_eq_p:cc { \exp_args:Ncc \cs_if_eq_p:NN } |
| 3283 |
\cs_new:Npn \cs_if_eq:ccTF { \exp_args:Ncc \cs_if_eq:NNTF } |
| 3284 |
\cs_new:Npn \cs_if_eq:ccT { \exp_args:Ncc \cs_if_eq:NNT } |
| 3285 |
\cs_new:Npn \cs_if_eq:ccF { \exp_args:Ncc \cs_if_eq:NNF } |
| 3286 |
% \end{macrocode} |
| 3287 |
% \end{macro} |
| 3288 |
% |
| 3289 |
% \subsection{Diagnostic functions} |
| 3290 |
% |
| 3291 |
% \begin{macrocode} |
| 3292 |
%<@@=kernel> |
| 3293 |
% \end{macrocode} |
| 3294 |
% |
| 3295 |
% \begin{macro}{\@@_chk_defined:NT} |
| 3296 |
% Error if the variable |#1| is not defined. |
| 3297 |
% \begin{macrocode} |
| 3298 |
\cs_new_protected:Npn \@@_chk_defined:NT #1#2 |
| 3299 |
{ |
| 3300 |
\cs_if_exist:NTF #1 |
| 3301 |
{#2} |
| 3302 |
{ |
| 3303 |
\msg_error:nne { kernel } { variable-not-defined } |
| 3304 |
{ \token_to_str:N #1 } |
| 3305 |
} |
| 3306 |
} |
| 3307 |
% \end{macrocode} |
| 3308 |
% \end{macro} |
| 3309 |
% |
| 3310 |
% \begin{macro} |
| 3311 |
% {\@@_register_show:N, \@@_register_show:c, \@@_register_log:N, \@@_register_log:c} |
| 3312 |
% \begin{macro}{\@@_register_show_aux:NN, \@@_register_show_aux:nNN} |
| 3313 |
% Simply using the \tn{showthe} primitive does not allow for |
| 3314 |
% line-wrapping, so instead use \cs{tl_show:n} and \cs{tl_log:n} (defined |
| 3315 |
% in \pkg{l3tl} and that performs line-wrapping). This displays |
| 3316 |
% |>~|\meta{variable}|=|\meta{value}. We expand the value before-hand |
| 3317 |
% as otherwise some integers (such as \tn{currentgrouplevel} or |
| 3318 |
% \tn{currentgrouptype}) altered by the line-wrapping code would show |
| 3319 |
% wrong values. |
| 3320 |
% \begin{macrocode} |
| 3321 |
\cs_new_protected:Npn \@@_register_show:N |
| 3322 |
{ \@@_register_show_aux:NN \tl_show:n } |
| 3323 |
\cs_new_protected:Npn \@@_register_show:c |
| 3324 |
{ \exp_args:Nc \@@_register_show:N } |
| 3325 |
\cs_new_protected:Npn \@@_register_log:N |
| 3326 |
{ \@@_register_show_aux:NN \tl_log:n } |
| 3327 |
\cs_new_protected:Npn \@@_register_log:c |
| 3328 |
{ \exp_args:Nc \@@_register_log:N } |
| 3329 |
\cs_new_protected:Npn \@@_register_show_aux:NN #1#2 |
| 3330 |
{ |
| 3331 |
\@@_chk_defined:NT #2 |
| 3332 |
{ |
| 3333 |
\exp_args:No \@@_register_show_aux:nNN |
| 3334 |
{ \tex_the:D #2 } #2 #1 |
| 3335 |
} |
| 3336 |
} |
| 3337 |
\cs_new_protected:Npn \@@_register_show_aux:nNN #1#2#3 |
| 3338 |
{ \exp_args:No #3 { \token_to_str:N #2 = #1 } } |
| 3339 |
% \end{macrocode} |
| 3340 |
% \end{macro} |
| 3341 |
% \end{macro} |
| 3342 |
% |
| 3343 |
% \begin{macro}{\cs_show:N, \cs_show:c, \cs_log:N, \cs_log:c, \@@_show:NN} |
| 3344 |
% Some control sequences have a very long name or meaning. Thus, |
| 3345 |
% simply using \TeX{}'s primitive \tn{show} could lead to overlong |
| 3346 |
% lines. The output of this primitive is mimicked to some extent, |
| 3347 |
% then the re-built string is given to \cs{tl_show:n} or \cs{tl_log:n} for |
| 3348 |
% line-wrapping. We must expand the meaning before passing it to the |
| 3349 |
% wrapping code as otherwise we would wrongly see the definitions that |
| 3350 |
% are in place there. To get correct escape characters, set the |
| 3351 |
% \tn{escapechar} in a group; this also localizes the assignment |
| 3352 |
% performed by \texttt{e}-expansion. The \cs{cs_show:c} and \cs{cs_log:c} commands |
| 3353 |
% convert their argument to a control sequence within a group to avoid |
| 3354 |
% showing \tn{relax} for undefined control sequences. |
| 3355 |
% \begin{macrocode} |
| 3356 |
\cs_new_protected:Npn \cs_show:N { \@@_show:NN \tl_show:n } |
| 3357 |
\cs_new_protected:Npn \cs_show:c |
| 3358 |
{ \group_begin: \exp_args:NNc \group_end: \cs_show:N } |
| 3359 |
\cs_new_protected:Npn \cs_log:N { \@@_show:NN \tl_log:n } |
| 3360 |
\cs_new_protected:Npn \cs_log:c |
| 3361 |
{ \group_begin: \exp_args:NNc \group_end: \cs_log:N } |
| 3362 |
\cs_new_protected:Npn \@@_show:NN #1#2 |
| 3363 |
{ |
| 3364 |
\group_begin: |
| 3365 |
\int_set:Nn \tex_escapechar:D { `\\ } |
| 3366 |
\exp_args:NNe |
| 3367 |
\group_end: |
| 3368 |
#1 { \token_to_str:N #2 = \cs_meaning:N #2 } |
| 3369 |
} |
| 3370 |
% \end{macrocode} |
| 3371 |
% \end{macro} |
| 3372 |
% |
| 3373 |
% \begin{macro}{\group_show_list:, \group_log_list:, \@@_group_show:NN} |
| 3374 |
% Wrapper around \tn{showgroups}. Getting \TeX{} to write to the log |
| 3375 |
% without interruption the run is done by altering the interaction |
| 3376 |
% mode. |
| 3377 |
% \begin{macrocode} |
| 3378 |
\cs_new_protected:Npn \group_show_list: |
| 3379 |
{ \@@_group_show:NN \use_none:n 1 } |
| 3380 |
\cs_new_protected:Npn \group_log_list: |
| 3381 |
{ \@@_group_show:NN \int_gzero:N 0 } |
| 3382 |
\cs_new_protected:Npn \@@_group_show:NN #1#2 |
| 3383 |
{ |
| 3384 |
\use:e |
| 3385 |
{ |
| 3386 |
#1 \tex_interactionmode:D |
| 3387 |
\int_set:Nn \tex_tracingonline:D {#2} |
| 3388 |
\int_set:Nn \tex_errorcontextlines:D { -1 } |
| 3389 |
\exp_not:N \exp_after:wN \scan_stop: |
| 3390 |
\tex_showgroups:D |
| 3391 |
\int_gset:Nn \tex_interactionmode:D |
| 3392 |
{ \int_use:N \tex_interactionmode:D } |
| 3393 |
\int_set:Nn \tex_tracingonline:D |
| 3394 |
{ \int_use:N \tex_tracingonline:D } |
| 3395 |
\int_set:Nn \tex_errorcontextlines:D |
| 3396 |
{ \int_use:N \tex_errorcontextlines:D } |
| 3397 |
} |
| 3398 |
} |
| 3399 |
% \end{macrocode} |
| 3400 |
% \end{macro} |
| 3401 |
% |
| 3402 |
% \subsection{Decomposing a macro definition} |
| 3403 |
% |
| 3404 |
% \begin{macrocode} |
| 3405 |
%<@@=cs> |
| 3406 |
% \end{macrocode} |
| 3407 |
% |
| 3408 |
% \begin{macro}{\cs_prefix_spec:N} |
| 3409 |
% \begin{macro}{\cs_parameter_spec:N} |
| 3410 |
% \begin{macro}{\cs_replacement_spec:N} |
| 3411 |
% \begin{macro}{\@@_prefix_arg_replacement:wN} |
| 3412 |
% \begin{macro}{\@@_macro_prefix_spec:N} |
| 3413 |
% \begin{macro}{\@@_macro_parameter_spec:N} |
| 3414 |
% \begin{macro}{\@@_macro_replacement_spec:N} |
| 3415 |
% We sometimes want to test if a control sequence can be expanded to |
| 3416 |
% reveal a hidden value. However, we cannot just expand the macro |
| 3417 |
% blindly as it may have arguments and none might be |
| 3418 |
% present. Therefore we define these functions to pick either the |
| 3419 |
% prefix(es), the parameter specification, or the replacement text from |
| 3420 |
% a macro. All of this information is returned as characters with |
| 3421 |
% catcode~$12$. If the token in question isn't a macro, the token |
| 3422 |
% \cs{scan_stop:} is returned instead. |
| 3423 |
% |
| 3424 |
% Since LuaMeta\TeX{}'s version of \tn{meaning} doesn't give the same |
| 3425 |
% output as the classical one, we are implementing the core of these |
| 3426 |
% macros in Lua instead. |
| 3427 |
% \begin{macrocode} |
| 3428 |
\use:e |
| 3429 |
{ |
| 3430 |
\exp_not:n { \cs_new:Npn \@@_prefix_arg_replacement:wN #1 } |
| 3431 |
\tl_to_str:n { macro : } \exp_not:n { #2 -> #3 \s_@@_stop #4 } |
| 3432 |
} |
| 3433 |
{ #4 {#1} {#2} {#3} } |
| 3434 |
|
| 3435 |
\cs_if_exist:NTF \@@_macro_prefix_spec:N |
| 3436 |
{ |
| 3437 |
\cs_new:Npn \cs_prefix_spec:N #1 |
| 3438 |
{ |
| 3439 |
\token_if_macro:NTF #1 |
| 3440 |
{ \@@_macro_prefix_spec:N #1 } |
| 3441 |
{ \scan_stop: } |
| 3442 |
} |
| 3443 |
} |
| 3444 |
{ |
| 3445 |
\cs_new:Npn \cs_prefix_spec:N #1 |
| 3446 |
{ |
| 3447 |
\token_if_macro:NTF #1 |
| 3448 |
{ |
| 3449 |
\exp_after:wN \@@_prefix_arg_replacement:wN |
| 3450 |
\token_to_meaning:N #1 \s_@@_stop \use_i:nnn |
| 3451 |
} |
| 3452 |
{ \scan_stop: } |
| 3453 |
} |
| 3454 |
} |
| 3455 |
\cs_if_exist:NTF \@@_macro_parameter_spec:N |
| 3456 |
{ |
| 3457 |
\cs_new:Npn \cs_parameter_spec:N #1 |
| 3458 |
{ |
| 3459 |
\token_if_macro:NTF #1 |
| 3460 |
{ \@@_macro_parameter_spec:N #1 } |
| 3461 |
{ \scan_stop: } |
| 3462 |
} |
| 3463 |
} |
| 3464 |
{ |
| 3465 |
\cs_new:Npn \cs_parameter_spec:N #1 |
| 3466 |
{ |
| 3467 |
\token_if_macro:NTF #1 |
| 3468 |
{ |
| 3469 |
\exp_after:wN \@@_prefix_arg_replacement:wN |
| 3470 |
\token_to_meaning:N #1 \s_@@_stop \use_ii:nnn |
| 3471 |
} |
| 3472 |
{ \scan_stop: } |
| 3473 |
} |
| 3474 |
} |
| 3475 |
\cs_if_exist:NTF \@@_macro_replacement_spec:N |
| 3476 |
{ |
| 3477 |
\cs_new:Npn \cs_replacement_spec:N #1 |
| 3478 |
{ |
| 3479 |
\token_if_macro:NTF #1 |
| 3480 |
{ \@@_macro_replacement_spec:N #1 } |
| 3481 |
{ \scan_stop: } |
| 3482 |
} |
| 3483 |
} |
| 3484 |
{ |
| 3485 |
\cs_new:Npn \cs_replacement_spec:N #1 |
| 3486 |
{ |
| 3487 |
\token_if_macro:NTF #1 |
| 3488 |
{ |
| 3489 |
\exp_after:wN \@@_prefix_arg_replacement:wN |
| 3490 |
\token_to_meaning:N #1 \s_@@_stop \use_iii:nnn |
| 3491 |
} |
| 3492 |
{ \scan_stop: } |
| 3493 |
} |
| 3494 |
} |
| 3495 |
%</code> |
| 3496 |
% \end{macrocode} |
| 3497 |
% This is a modified version of code suggested by Max Chernoff |
| 3498 |
% (\url{https://chat.stackexchange.com/transcript/message/67947633#67947633}). |
| 3499 |
% We aim to provide the classical \TeX{}82 appearance but covering \eTeX{}: |
| 3500 |
% due to changes in the engine, the only useful prefix here is |\protected| |
| 3501 |
% at present. (This may need to be revisited once the engine is more stable.) |
| 3502 |
% This does not cover tokens other than control sequences, so we only use |
| 3503 |
% it for the internal needed here. |
| 3504 |
% \begin{macrocode} |
| 3505 |
%<*lua> |
| 3506 |
if status.luatex_engine == 'luametatex' then |
| 3507 |
local function scan_full_csname() |
| 3508 |
local t = get_next() |
| 3509 |
local csname = get_csname(t) |
| 3510 |
return t.active and active_prefix .. csname or csname, t |
| 3511 |
end |
| 3512 |
luacmd('@@_macro_prefix_spec:N', function() |
| 3513 |
local token = get_next() |
| 3514 |
if get_protected(token) then |
| 3515 |
sprint(-2, "\\protected ") |
| 3516 |
end |
| 3517 |
end, 'global') |
| 3518 |
luacmd('@@_macro_parameter_spec:N', function() |
| 3519 |
local csname, token = scan_full_csname(true) |
| 3520 |
if token.parameters == 0 then return end |
| 3521 |
sprint(-2, get_macro(csname, false, true)) |
| 3522 |
end, 'global') |
| 3523 |
luacmd('@@_macro_replacement_spec:N', function() |
| 3524 |
local csname = scan_full_csname(true) |
| 3525 |
sprint(-2, get_macro(csname, false, false)) |
| 3526 |
end, 'global') |
| 3527 |
end |
| 3528 |
%</lua> |
| 3529 |
%<*code> |
| 3530 |
% \end{macrocode} |
| 3531 |
% \end{macro} |
| 3532 |
% \end{macro} |
| 3533 |
% \end{macro} |
| 3534 |
% \end{macro} |
| 3535 |
% \end{macro} |
| 3536 |
% \end{macro} |
| 3537 |
% \end{macro} |
| 3538 |
% |
| 3539 |
% \subsection{Doing nothing functions} |
| 3540 |
% |
| 3541 |
% \begin{macro}[EXP]{\prg_do_nothing:} |
| 3542 |
% This does not fit anywhere else! |
| 3543 |
% \begin{macrocode} |
| 3544 |
\cs_new:Npn \prg_do_nothing: { } |
| 3545 |
% \end{macrocode} |
| 3546 |
% \end{macro} |
| 3547 |
% |
| 3548 |
% \subsection{Breaking out of mapping functions} |
| 3549 |
% |
| 3550 |
% \begin{macrocode} |
| 3551 |
%<@@=prg> |
| 3552 |
% \end{macrocode} |
| 3553 |
% |
| 3554 |
% \begin{macro}[EXP]{\prg_break_point:Nn, \prg_map_break:Nn} |
| 3555 |
% In inline mappings, the nesting level must be reset |
| 3556 |
% at the end of the mapping, even when the user decides |
| 3557 |
% to break out. This is done by putting the code that |
| 3558 |
% must be performed as an argument of \cs{@@_break_point:Nn}. |
| 3559 |
% The breaking functions are then defined to jump to |
| 3560 |
% that point and perform the argument of \cs{@@_break_point:Nn}, |
| 3561 |
% before the user's code (if any). There is a check that we close the |
| 3562 |
% correct loop, otherwise we continue breaking. |
| 3563 |
% \begin{macrocode} |
| 3564 |
\cs_new_eq:NN \prg_break_point:Nn \use_ii:nn |
| 3565 |
\cs_new:Npn \prg_map_break:Nn #1#2#3 \prg_break_point:Nn #4#5 |
| 3566 |
{ |
| 3567 |
#5 |
| 3568 |
\if_meaning:w #1 #4 |
| 3569 |
\exp_after:wN \use_iii:nnn |
| 3570 |
\fi: |
| 3571 |
\prg_map_break:Nn #1 {#2} |
| 3572 |
} |
| 3573 |
% \end{macrocode} |
| 3574 |
% \end{macro} |
| 3575 |
% |
| 3576 |
% \begin{macro}{\prg_break_point:} |
| 3577 |
% \begin{macro}{\prg_break:, \prg_break:n} |
| 3578 |
% Very simple analogues of \cs{prg_break_point:Nn} and |
| 3579 |
% \cs{prg_map_break:Nn}, for use in fast short-term recursions which |
| 3580 |
% are not mappings, do not need to support nesting, and in which |
| 3581 |
% nothing has to be done at the end of the loop. |
| 3582 |
% \begin{macrocode} |
| 3583 |
\cs_new_eq:NN \prg_break_point: \prg_do_nothing: |
| 3584 |
\cs_new:Npn \prg_break: #1 \prg_break_point: { } |
| 3585 |
\cs_new:Npn \prg_break:n #1#2 \prg_break_point: {#1} |
| 3586 |
% \end{macrocode} |
| 3587 |
% \end{macro} |
| 3588 |
% \end{macro} |
| 3589 |
% |
| 3590 |
% \subsection{Starting a paragraph} |
| 3591 |
% |
| 3592 |
% \begin{macro}{\mode_leave_vertical:} |
| 3593 |
% The approach here is different to that used by \LaTeXe{} or plain \TeX{}, |
| 3594 |
% which unbox a void box to force horizontal mode. That inserts the |
| 3595 |
% \tn{everypar} tokens \emph{before} the re-inserted unboxing tokens. The |
| 3596 |
% approach here uses a protected macro, equivalent to the \tn{quitvmode} |
| 3597 |
% primitive. In vertical mode, the \tn{indent} primitive is inserted: |
| 3598 |
% this will switch to horizontal mode and insert \tn{everypar} tokens and |
| 3599 |
% nothing else. Unlike the \LaTeXe{} version, the availability of \eTeX{} |
| 3600 |
% means using a mode test can be done at for example the start of an |
| 3601 |
% \tn{halign}. |
| 3602 |
% \begin{macrocode} |
| 3603 |
\cs_new_protected:Npn \mode_leave_vertical: |
| 3604 |
{ |
| 3605 |
\if_mode_vertical: |
| 3606 |
\exp_after:wN \tex_indent:D |
| 3607 |
\fi: |
| 3608 |
} |
| 3609 |
% \end{macrocode} |
| 3610 |
% \end{macro} |
| 3611 |
% |
| 3612 |
% \begin{macrocode} |
| 3613 |
%</code> |
| 3614 |
% \end{macrocode} |
| 3615 |
% |
| 3616 |
% \end{implementation} |
| 3617 |
% |
| 3618 |
% \PrintIndex |