diff options
author | Karl Berry <karl@freefriends.org> | 2018-04-30 22:39:09 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2018-04-30 22:39:09 +0000 |
commit | a28e1bfccd6fe522fcd296426e4d89c7fb4f19b6 (patch) | |
tree | b72347e08575b56fcfed87c4d837b48dcfd1e02a /Master/texmf-dist/source/latex/l3kernel/l3token.dtx | |
parent | b40c37a9e22b8235ff9c0bc256d00f7af94304c3 (diff) |
l3 (30apr18)
git-svn-id: svn://tug.org/texlive/trunk@47516 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3token.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/l3kernel/l3token.dtx | 189 |
1 files changed, 94 insertions, 95 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3token.dtx b/Master/texmf-dist/source/latex/l3kernel/l3token.dtx index 5bf97da8f8a..cc091b65559 100644 --- a/Master/texmf-dist/source/latex/l3kernel/l3token.dtx +++ b/Master/texmf-dist/source/latex/l3kernel/l3token.dtx @@ -12,7 +12,6 @@ % This file is part of the "l3kernel bundle" (The Work in LPPL) % and all files in that bundle must be distributed together. % -%=[] % ----------------------------------------------------------------------- % % The development version of the bundle can be found at @@ -42,7 +41,7 @@ % }^^A % } % -% \date{Released 2018/03/05} +% \date{Released 2018-04-30} % % \maketitle % @@ -122,7 +121,8 @@ % be an active character. % \end{function} % -% \begin{function}[EXP, added = 2015-09-09]{\char_generate:nn} +% \begin{function}[EXP, added = 2015-09-09, updated = 2018-04-19] +% {\char_generate:nn} % \begin{syntax} % \cs{char_generate:nn} \Arg{charcode} \Arg{catcode} % \end{syntax} @@ -139,12 +139,14 @@ % \item $8$ (math subscript) % \item $11$ (letter) % \item $12$ (other) +% \item $13$ (active) (not \XeTeX{}) % \end{itemize} % and other values raise an error. % % The \meta{charcode} may be any one valid for the engine in use. Note % however that for \XeTeX{} releases prior to 0.99992 only the 8-bit -% range ($0$ to $255$) is accepted due to engine limitations. +% range ($0$ to $255$) is accepted due to engine limitations. Note also +% that \XeTeX{} cannot currently generate active character tokens. % \end{function} % % \begin{variable}[added = 2011-09-05]{\c_catcode_other_space_tl} @@ -443,6 +445,10 @@ % as |macro|s. % \begin{texnote} % This is the \TeX{} primitive \tn{meaning}. +% The \meta{token} can thus be an explicit space tokens or an +% explicit begin-group or end-group character token (|{|~or~|}| when +% normal \TeX{} category codes apply) even though these are not +% valid \texttt{N}-type arguments. % \end{texnote} % \end{function} % @@ -457,6 +463,10 @@ % \meta{token}). This function requires only a single expansion. % \begin{texnote} % \cs{token_to_str:N} is the \TeX{} primitive \tn{string} renamed. +% The \meta{token} can thus be an explicit space tokens or an +% explicit begin-group or end-group character token (|{|~or~|}| when +% normal \TeX{} category codes apply) even though these are not +% valid \texttt{N}-type arguments. % \end{texnote} % \end{function} % @@ -1019,9 +1029,9 @@ % expandable) results in an internal token, displayed (temporarily) % as \cs{notexpanded: \meta{token}}, whose shape coincides with the % \meta{token} and whose meaning differs from \tn{relax}. -% \item An |\outer endtemplate:| (expanding to another internal token, -% |end of alignment template|) can be encountered when peeking ahead -% at the next token. +% \item An |\outer endtemplate:| can be encountered when peeking ahead +% at the next token; this expands to another internal token, +% |end of alignment template|. % \item Tricky programming might access a frozen |\endwrite|. % \item Some frozen tokens can only be accessed in interactive % sessions: |\cr|, |\right|, |\endgroup|, |\fi|, |\inaccessible|. @@ -1095,19 +1105,6 @@ % single tokens \enquote{N-type}, as they are suitable to be used as an % argument for a function with the signature~\texttt{:N}. % -% \section{Internal functions} -% -% \begin{function}[EXP, added = 2016-03-25]{\__char_generate:nn} -% \begin{syntax} -% \cs{__char_generate:nn} \Arg{charcode} \Arg{catcode} -% \end{syntax} -% This function is identical in operation to the public -% \cs{char_generate:nn} but omits various sanity tests. In particular, this -% means it is used in certain places where engine variations need to be -% accounted for by the kernel. The \meta{catcode} must give an explicit -% integer when expanded (and must not absorb a space for instance). -% \end{function} -% % \end{documentation} % % \begin{implementation} @@ -1130,9 +1127,9 @@ % Simple wrappers around the primitives. % \begin{macrocode} \cs_new_protected:Npn \char_set_catcode:nn #1#2 - { \tex_catcode:D \__int_eval:n {#1} = \__int_eval:n {#2} } + { \tex_catcode:D \int_eval:n {#1} = \int_eval:n {#2} \exp_stop_f: } \cs_new:Npn \char_value_catcode:n #1 - { \tex_the:D \tex_catcode:D \__int_eval:n {#1} } + { \tex_the:D \tex_catcode:D \int_eval:n {#1} \exp_stop_f: } \cs_new_protected:Npn \char_show_value_catcode:n #1 { \exp_args:Nf \tl_show:n { \char_value_catcode:n {#1} } } % \end{macrocode} @@ -1265,27 +1262,27 @@ % Pretty repetitive, but necessary! % \begin{macrocode} \cs_new_protected:Npn \char_set_mathcode:nn #1#2 - { \tex_mathcode:D \__int_eval:n {#1} = \__int_eval:n {#2} } + { \tex_mathcode:D \int_eval:n {#1} = \int_eval:n {#2} \exp_stop_f: } \cs_new:Npn \char_value_mathcode:n #1 - { \tex_the:D \tex_mathcode:D \__int_eval:n {#1} } + { \tex_the:D \tex_mathcode:D \int_eval:n {#1} \exp_stop_f: } \cs_new_protected:Npn \char_show_value_mathcode:n #1 { \exp_args:Nf \tl_show:n { \char_value_mathcode:n {#1} } } \cs_new_protected:Npn \char_set_lccode:nn #1#2 - { \tex_lccode:D \__int_eval:n {#1} = \__int_eval:n {#2} } + { \tex_lccode:D \int_eval:n {#1} = \int_eval:n {#2} \exp_stop_f: } \cs_new:Npn \char_value_lccode:n #1 - { \tex_the:D \tex_lccode:D \__int_eval:n {#1} } + { \tex_the:D \tex_lccode:D \int_eval:n {#1} \exp_stop_f: } \cs_new_protected:Npn \char_show_value_lccode:n #1 { \exp_args:Nf \tl_show:n { \char_value_lccode:n {#1} } } \cs_new_protected:Npn \char_set_uccode:nn #1#2 - { \tex_uccode:D \__int_eval:n {#1} = \__int_eval:n {#2} } + { \tex_uccode:D \int_eval:n {#1} = \int_eval:n {#2} \exp_stop_f: } \cs_new:Npn \char_value_uccode:n #1 - { \tex_the:D \tex_uccode:D \__int_eval:n {#1} } + { \tex_the:D \tex_uccode:D \int_eval:n {#1} \exp_stop_f: } \cs_new_protected:Npn \char_show_value_uccode:n #1 { \exp_args:Nf \tl_show:n { \char_value_uccode:n {#1} } } \cs_new_protected:Npn \char_set_sfcode:nn #1#2 - { \tex_sfcode:D \__int_eval:n {#1} = \__int_eval:n {#2} } + { \tex_sfcode:D \int_eval:n {#1} = \int_eval:n {#2} \exp_stop_f: } \cs_new:Npn \char_value_sfcode:n #1 - { \tex_the:D \tex_sfcode:D \__int_eval:n {#1} } + { \tex_the:D \tex_sfcode:D \int_eval:n {#1} \exp_stop_f: } \cs_new_protected:Npn \char_show_value_sfcode:n #1 { \exp_args:Nf \tl_show:n { \char_value_sfcode:n {#1} } } % \end{macrocode} @@ -1355,12 +1352,18 @@ % \end{macrocode} % \end{macro} % +% \begin{macro}{\@@_int_to_roman:w} +% For efficiency in 8-bit engines, we use the faster primitive approach +% to making roman numerals. +% \begin{macrocode} +\cs_new_eq:NN \@@_int_to_roman:w \tex_romannumeral:D +% \end{macrocode} +% \end{macro} +% % \begin{macro}[EXP]{\char_generate:nn} -% \begin{macro}[EXP]{\__char_generate:nn} % \begin{macro}[EXP]{\@@_generate_aux:nn} -% \begin{macro}[EXP]{\@@_generate_aux:nnw} +% \begin{macro}[EXP]{\@@_generate_aux:nnw, \@@_generate_auxii:nnw} % \begin{variable}{\l_@@_tmp_tl} -% \begin{variable}{\c_@@_max_int} % \begin{macro}[EXP]{\@@_generate_invalid_catcode:} % The aim here is to generate characters of (broadly) arbitrary category % code. Where possible, that is done using engine support (\XeTeX{}, @@ -1368,57 +1371,43 @@ % the interface layer, turn the two arguments into integers up-front so % this is only done once. % \begin{macrocode} -\__kernel_patch_args:nNNpn { { \__int_eval:n {#1} } { \__int_eval:n {#2} } } \cs_new:Npn \char_generate:nn #1#2 { \exp:w \exp_after:wN \@@_generate_aux:w - \__int_value:w \__int_eval:w #1 \exp_after:wN ; - \__int_value:w \__int_eval:w #2 ; - } -\cs_new:Npn \__char_generate:nn #1#2 - { - \exp:w \exp_after:wN - \@@_generate_aux:nnw \exp_after:wN - { \__int_value:w \__int_eval:w #1 } {#2} \exp_end: + \int_value:w \int_eval:n {#1} \exp_after:wN ; + \int_value:w \int_eval:n {#2} ; } % \end{macrocode} % Before doing any actual conversion, first some special case filtering. -% The \tn{Ucharcat} primitive cannot make active chars, so that is turned -% off here: if the primitive gets altered then the code is already in -% place for 8-bit engines and will kick in for \LuaTeX{} too. Spaces -% are also banned here as \LuaTeX{} emulation only makes normal (charcode -% $32$ spaces. However, |^^@| is filtered out separately as that can't be +% Spaces are out here as \LuaTeX{} emulation only makes normal (charcode +% $32$ spaces). However, |^^@| is filtered out separately as that can't be % done with macro emulation either, so is flagged up separately. That % done, hand off to the engine-dependent part. % \begin{macrocode} \cs_new:Npn \@@_generate_aux:w #1 ; #2 ; { - \if_int_compare:w #2 = 13 \exp_stop_f: - \__kernel_msg_expandable_error:nn { kernel } { char-active } + \if_int_compare:w #2 = 10 \exp_stop_f: + \if_int_compare:w #1 = 0 \exp_stop_f: + \__kernel_msg_expandable_error:nn { kernel } { char-null-space } + \else: + \__kernel_msg_expandable_error:nn { kernel } { char-space } + \fi: \else: - \if_int_compare:w #2 = 10 \exp_stop_f: - \if_int_compare:w #1 = 0 \exp_stop_f: - \__kernel_msg_expandable_error:nn { kernel } { char-null-space } - \else: - \__kernel_msg_expandable_error:nn { kernel } { char-space } - \fi: + \if_int_odd:w 0 + \if_int_compare:w #2 < 1 \exp_stop_f: 1 \fi: + \if_int_compare:w #2 = 5 \exp_stop_f: 1 \fi: + \if_int_compare:w #2 = 9 \exp_stop_f: 1 \fi: + \if_int_compare:w #2 > 13 \exp_stop_f: 1 \fi: \exp_stop_f: + \__kernel_msg_expandable_error:nn { kernel } + { char-invalid-catcode } \else: \if_int_odd:w 0 - \if_int_compare:w #2 < 1 \exp_stop_f: 1 \fi: - \if_int_compare:w #2 = 5 \exp_stop_f: 1 \fi: - \if_int_compare:w #2 = 9 \exp_stop_f: 1 \fi: - \if_int_compare:w #2 > 13 \exp_stop_f: 1 \fi: \exp_stop_f: + \if_int_compare:w #1 < 0 \exp_stop_f: 1 \fi: + \if_int_compare:w #1 > \c_max_char_int 1 \fi: \exp_stop_f: \__kernel_msg_expandable_error:nn { kernel } - { char-invalid-catcode } + { char-out-of-range } \else: - \if_int_odd:w 0 - \if_int_compare:w #1 < 0 \exp_stop_f: 1 \fi: - \if_int_compare:w #1 > \c_@@_max_int 1 \fi: \exp_stop_f: - \__kernel_msg_expandable_error:nn { kernel } - { char-out-of-range } - \else: - \@@_generate_aux:nnw {#1} {#2} - \fi: + \@@_generate_aux:nnw {#1} {#2} \fi: \fi: \fi: @@ -1432,6 +1421,9 @@ % out here using a primitive-based boolean expression for speed. % The final level is the basic definition at the engine level: the arguments % here are integers so there is no need to worry about them too much. +% At present \XeTeX{} cannot generate active characters so we filter that: +% at some future stage that may change: the slightly odd ordering of +% auxiliaries reflects that. % \begin{macrocode} \group_begin: %<*package> @@ -1440,16 +1432,15 @@ %</package> \char_set_catcode_other:n { 0 } \if_int_odd:w 0 - \cs_if_exist:NT \luatex_directlua:D { 1 } - \cs_if_exist:NT \utex_charcat:D { 1 } \exp_stop_f: - \int_const:Nn \c_@@_max_int { 1114111 } - \cs_if_exist:NTF \luatex_directlua:D + \sys_if_engine_luatex:T { 1 } + \sys_if_engine_xetex:T { 1 } \exp_stop_f: + \sys_if_engine_luatex:TF { \cs_new:Npn \@@_generate_aux:nnw #1#2#3 \exp_end: { #3 - \exp_after:wN \exp_end: - \luatex_directlua:D { l3kernel.charcat(#1, #2) } + \exp_after:wN \exp_after:wN \exp_after:wN \exp_end: + \lua_now_x:n { l3kernel.charcat(#1, #2) } } } { @@ -1457,7 +1448,18 @@ { #3 \exp_after:wN \exp_end: - \utex_charcat:D #1 ~ #2 ~ + \utex_charcat:D #1 \exp_stop_f: #2 \exp_stop_f: + } + \cs_new_eq:NN \@@_generate_auxii:nnw \@@_generate_aux:nnw + \cs_gset:Npn \@@_generate_aux:nnw #1#2#3 \exp_end: + { + #3 + \if_int_compare:w #2 = 13 \exp_stop_f: + \__kernel_msg_expandable_error:nn { kernel } { char-active } + \else: + \@@_generate_auxii:nnw {#1} {#2} + \fi: + \exp_end: } } \else: @@ -1472,7 +1474,6 @@ % To get open/close braces into the list, they are set up using |\if_false:| % pairing and are then |x|-type expanded together into the desired form. % \begin{macrocode} - \int_const:Nn \c_@@_max_int { 255 } \tl_set:Nn \l_@@_tmp_tl { \exp_not:N \or: } \char_set_catcode_group_begin:n { 0 } % { \tl_put_right:Nn \l_@@_tmp_tl { ^^@ \if_false: } } @@ -1493,7 +1494,7 @@ \tl_put_right:Nn \l_@@_tmp_tl { \or: - \etex_unexpanded:D \exp_after:wN + \__kernel_exp_not:w \exp_after:wN { \exp_after:wN ^^@ \exp_after:wN } } \tl_put_right:Nn \l_@@_tmp_tl { \or: } @@ -1533,20 +1534,20 @@ \exp_args:Nx \tex_lowercase:D { \tl_const:Nn - \exp_not:c { c_@@_ \__int_to_roman:w #1 _tl } + \exp_not:c { c_@@_ \@@_int_to_roman:w #1 _tl } { \exp_not:o \l_@@_tmp_tl } } } %<*package> - \int_step_function:nnnN { 0 } { 1 } { 11 } \@@_tmp:n + \int_step_function:nnN { 0 } { 11 } \@@_tmp:n \group_begin: \tl_replace_once:Nnn \l_@@_tmp_tl { ^^@ } { \ERROR } \@@_tmp:n { 12 } \group_end: - \int_step_function:nnnN { 13 } { 1 } { 255 } \@@_tmp:n + \int_step_function:nnN { 13 } { 255 } \@@_tmp:n %</package> %<*initex> - \int_step_function:nnnN { 0 } { 1 } { 255 } \@@_tmp:n + \int_step_function:nnN { 0 } { 255 } \@@_tmp:n %</initex> \cs_new:Npn \@@_generate_aux:nnw #1#2#3 \exp_end: { @@ -1556,7 +1557,7 @@ \exp_after:wN \exp_after:wN \if_case:w #2 \exp_last_unbraced:Nv \exp_stop_f: - { c_@@_ \__int_to_roman:w #1 _tl } + { c_@@_ \@@_int_to_roman:w #1 _tl } \fi: } \fi: @@ -1564,8 +1565,6 @@ % \end{macrocode} % \end{macro} % \end{variable} -% \end{variable} -% \end{macro} % \end{macro} % \end{macro} % \end{macro} @@ -1609,12 +1608,12 @@ % \emph{work} with \cs{cs_new_eq:NN} but that's not really a great idea to % show off: we want people to stick to the defined interfaces and that % includes us.) So that these few odd names go into the log when appropriate -% there is a need to hand-apply the \cs{__chk_if_free_cs:N} check. +% there is a need to hand-apply the \cs{__kernel_chk_if_free_cs:N} check. % \begin{macrocode} \group_begin: - \__chk_if_free_cs:N \c_group_begin_token + \__kernel_chk_if_free_cs:N \c_group_begin_token \tex_global:D \tex_let:D \c_group_begin_token { - \__chk_if_free_cs:N \c_group_end_token + \__kernel_chk_if_free_cs:N \c_group_end_token \tex_global:D \tex_let:D \c_group_end_token } \char_set_catcode_math_toggle:N \* \cs_new_eq:NN \c_math_toggle_token * @@ -1624,7 +1623,7 @@ \cs_new_eq:NN \c_math_superscript_token ^ \char_set_catcode_math_subscript:N \* \cs_new_eq:NN \c_math_subscript_token * - \__chk_if_free_cs:N \c_space_token + \__kernel_chk_if_free_cs:N \c_space_token \use:n { \tex_global:D \tex_let:D \c_space_token = ~ } ~ \cs_new_eq:NN \c_catcode_letter_token a \cs_new_eq:NN \c_catcode_other_token 1 @@ -1860,11 +1859,9 @@ ##1 \tl_to_str:n { ma } ##2 \c_colon_str ##3 \exp_not:N \q_stop } { - \if_int_compare:w \__str_if_eq_x:nn { #2 } { cro } = 0 \exp_stop_f: - \prg_return_true: - \else: - \prg_return_false: - \fi: + \str_if_eq_x:nnTF { #2 } { cro } + { \prg_return_true: } + { \prg_return_false: } } % \end{macrocode} % \end{macro} @@ -1964,7 +1961,7 @@ % function cannot be defined on the fly because tests must remain % expandable): instead the first argument of the auxiliary (plus the % delimiter to avoid complications with trailing spaces) is compared -% using \cs{__str_if_eq_x_return:nn} to the result of applying +% using \cs{str_if_eq_x:nnTF} to the result of applying % \cs{token_to_str:N} to a control sequence. Second, the % \tn{meaning} of primitives such as \tn{dimen} or \tn{dimendef} % starts in the same way as registers such as @@ -2012,7 +2009,7 @@ \exp_not:N \prg_return_false: \exp_not:N \else: } - \exp_not:N \__str_if_eq_x_return:nn + \exp_not:N \str_if_eq_x:nnTF { \exp_not:N \exp_after:wN \exp_not:c { @@_delimit_by_ #2 :w } @@ -2020,6 +2017,8 @@ ? \tl_to_str:n {#2} \exp_not:N \q_stop } { \exp_not:n {#3} } + { \exp_not:N \prg_return_true: } + { \exp_not:N \prg_return_false: } \cs_if_exist:cT { tex_ #2 :D } { \exp_not:N \fi: |