diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/l3packages/xparse/xparse.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/l3packages/xparse/xparse.sty | 447 |
1 files changed, 266 insertions, 181 deletions
diff --git a/Master/texmf-dist/tex/latex/l3packages/xparse/xparse.sty b/Master/texmf-dist/tex/latex/l3packages/xparse/xparse.sty index df25d3823f7..91b35fd7c7b 100644 --- a/Master/texmf-dist/tex/latex/l3packages/xparse/xparse.sty +++ b/Master/texmf-dist/tex/latex/l3packages/xparse/xparse.sty @@ -6,7 +6,7 @@ %% %% xparse.dtx (with options: `package') %% -%% Copyright (C) 2009-2017 The LaTeX3 Project +%% Copyright (C) 2009-2019 The LaTeX3 Project %% %% It may be distributed and/or modified under the conditions of %% the LaTeX Project Public License (LPPL), either version 1.3c of @@ -18,11 +18,7 @@ %% This file is part of the "l3packages bundle" (The Work in LPPL) %% and all files in that bundle must be distributed together. %% -%% File: xparse.dtx (C) Copyright 1999 Frank Mittelbach, Chris Rowley, -%% David Carlisle -%% (C) Copyright 2004-2008 Frank Mittelbach, -%% The LaTeX3 Project -%% (C) Copyright 2009-2018 The LaTeX3 Project +%% File: xparse.dtx \RequirePackage{expl3}[2018-04-12] \@ifpackagelater{expl3}{2018-04-12} {} @@ -36,7 +32,7 @@ }% \endinput } -\ProvidesExplPackage{xparse}{2018-10-17}{} +\ProvidesExplPackage{xparse}{2019-03-05}{} {L3 Experimental document command parser} \tl_new:N \l__xparse_arg_spec_tl \tl_new:N \l__xparse_args_tl @@ -46,6 +42,7 @@ \bool_new:N \l__xparse_defaults_bool \tl_new:N \l__xparse_defaults_tl \bool_new:N \l__xparse_environment_bool +\str_new:N \l__xparse_environment_str \bool_new:N \l__xparse_expandable_bool \tl_new:N \l__xparse_expandable_aux_name_tl \tl_set:Nn \l__xparse_expandable_aux_name_tl @@ -62,11 +59,11 @@ \tl_new:N \l__xparse_last_delimiters_tl \bool_new:N \l__xparse_long_bool \int_new:N \l__xparse_m_args_int -\int_new:N \l__xparse_mandatory_args_int \bool_new:N \l__xparse_prefixed_bool \tl_new:N \l__xparse_process_all_tl \tl_new:N \l__xparse_process_one_tl \bool_new:N \l__xparse_process_some_bool +\tl_new:N \l__xparse_saved_args_tl \tl_new:N \l__xparse_signature_tl \bool_new:N \l__xparse_some_obey_spaces_bool \bool_new:N \l__xparse_some_long_bool @@ -85,7 +82,7 @@ \bool_set_true:N \l__xparse_expandable_bool \__xparse_declare_cmd_aux:Nnn } -\cs_new_protected:Npn \__xparse_declare_cmd_aux:Nnn #1#2 +\cs_new_protected:Npn \__xparse_declare_cmd_aux:Nnn #1#2#3 { \cs_if_exist:NTF #1 { @@ -104,17 +101,20 @@ { \token_to_str:N #1 } { \tl_to_str:n {#2} } } \bool_set_false:N \l__xparse_environment_bool - \__xparse_declare_cmd_internal:Nnn #1 {#2} + \__xparse_declare_cmd_internal:Nnnn #1 {#2} {#3} { } } -\cs_new_protected:Npn \__xparse_declare_cmd_internal:Nnn #1#2#3 +\cs_new_protected:Npn \__xparse_declare_cmd_internal:Nnnn #1#2#3#4 { \tl_set:Nx \l__xparse_function_tl { \cs_to_str:N #1 } + \tl_set:Nx \l__xparse_fn_tl + { \exp_not:c { \l__xparse_function_tl \c_space_tl } } \__xparse_normalize_arg_spec:n {#2} \exp_args:No \__xparse_prepare_signature:n \l__xparse_arg_spec_tl \__xparse_declare_cmd_code:Nnn #1 {#2} {#3} + #4 \__xparse_break_point:n {#2} } -\cs_generate_variant:Nn \__xparse_declare_cmd_internal:Nnn { cnx } +\cs_generate_variant:Nn \__xparse_declare_cmd_internal:Nnnn { cnx } \cs_new_eq:NN \__xparse_break_point:n \use_none:n \cs_new_protected:Npn \__xparse_declare_cmd_code:Nnn { @@ -129,10 +129,16 @@ \cs_set_protected:Npn \l__xparse_current_arg_int {#3} \cs_set_protected_nopar:Npx #1 { - \__xparse_start:nNNnnn - { \exp_not:n {#2} } - \exp_not:c { \l__xparse_function_tl \c_space_tl } - \exp_not:c { \l__xparse_function_tl \c_space_tl code } + \bool_if:NTF \l__xparse_environment_bool + { + \__xparse_start_env:nnnnn { \exp_not:n {#2} } + { \l__xparse_environment_str } + } + { + \__xparse_start:nNNnnn { \exp_not:n {#2} } + \exp_not:c { \l__xparse_function_tl \c_space_tl } + \exp_not:c { \l__xparse_function_tl \c_space_tl code } + } { \exp_not:o \l__xparse_signature_tl } { \bool_if:NT \l__xparse_defaults_bool @@ -192,22 +198,26 @@ } \cs_new_protected:Npn \__xparse_declare_env:nnnn #1#2 { - \cs_if_exist:cTF {#1} + \str_set:Nx \l__xparse_environment_str {#1} + \str_set:Nx \l__xparse_environment_str + { \tl_trim_spaces:o { \l__xparse_environment_str } } + \cs_if_exist:cTF { \l__xparse_environment_str } { \__kernel_msg_info:nnxx { xparse } { redefine-environment } - {#1} { \tl_to_str:n {#2} } + { \l__xparse_environment_str } { \tl_to_str:n {#2} } } { \__kernel_msg_info:nnxx { xparse } { define-environment } - {#1} { \tl_to_str:n {#2} } + { \l__xparse_environment_str } { \tl_to_str:n {#2} } } \bool_set_false:N \l__xparse_expandable_bool \bool_set_true:N \l__xparse_environment_bool - \__xparse_declare_env_internal:nnnn {#1} {#2} + \exp_args:NV \__xparse_declare_env_internal:nnnn + \l__xparse_environment_str {#2} } \cs_new_protected:Npn \__xparse_declare_env_internal:nnnn #1#2#3#4 { - \__xparse_declare_cmd_internal:cnx { environment~ #1 } {#2} + \__xparse_declare_cmd_internal:cnxn { environment~ #1 } {#2} { \cs_set_nopar:Npx \exp_not:c { environment~ #1 ~end~aux } { @@ -216,28 +226,42 @@ } \exp_not:n {#3} } - \cs_set_nopar:cpx { environment~ #1 ~end } - { \exp_not:c { environment~ #1 ~end~aux } } - \cs_generate_from_arg_count:cNnn - { environment~ #1 ~end~aux~ } \cs_set:Npn - \l__xparse_current_arg_int {#4} - \cs_set_eq:cc {#1} { environment~ #1 } - \cs_set_eq:cc { end #1 } { environment~ #1 ~end } + { + \cs_set_nopar:cpx { environment~ #1 ~end } + { \exp_not:c { environment~ #1 ~end~aux } } + \cs_generate_from_arg_count:cNnn + { environment~ #1 ~end~aux~ } \cs_set:Npn + \l__xparse_current_arg_int {#4} + \cs_set_eq:cc {#1} { environment~ #1 } + \cs_set_eq:cc { end #1 } { environment~ #1 ~end } + } + } +\cs_new_protected:Npn \__xparse_start_env:nnnnn #1#2 + { + \str_set:Nn \l__xparse_environment_str {#2} + \bool_set_true:N \l__xparse_environment_bool + \__xparse_start_aux:ccnnnn + { environment~ \l__xparse_environment_str \c_space_tl } + { environment~ \l__xparse_environment_str \c_space_tl code } + {#1} } -\cs_new_protected:Npx \__xparse_start:nNNnnn +\cs_new_protected:Npx \__xparse_start:nNNnnn #1#2#3 { \exp_not:c { xparse~function~is~not~expandable } - \exp_not:N \__xparse_start_aux:nNNnnn + \exp_not:n { \bool_set_false:N \l__xparse_environment_bool } + \exp_not:N \__xparse_start_aux:NNnnnn + #2 #3 {#1} } -\cs_new_protected:Npn \__xparse_start_aux:nNNnnn #1#2#3#4#5#6 +\cs_new_protected:Npn \__xparse_start_aux:NNnnnn #1#2#3#4#5#6 { \tl_clear:N \l__xparse_args_tl - \tl_set:Nn \l__xparse_fn_tl {#2} - \tl_set:Nn \l__xparse_fn_code_tl {#3} + \tl_set:Nn \l__xparse_fn_tl {#1} + \tl_set:Nn \l__xparse_fn_code_tl {#2} \tl_set:Nn \l__xparse_defaults_tl {#5} \tl_set:Nn \l__xparse_process_all_tl {#6} #4 \__xparse_run_code: } +\cs_generate_variant:Nn \__xparse_start_aux:NNnnnn { cc } \cs_new_protected:Npn \__xparse_run_code: { \tl_if_empty:NF \l__xparse_defaults_tl { \__xparse_defaults: } @@ -266,7 +290,7 @@ \cs_new_protected:Npn \__xparse_defaults_error:w \q_recursion_stop { \__kernel_msg_error:nnx { xparse } { loop-in-defaults } - { \exp_after:wN \token_to_str:N \l__xparse_fn_tl } + { \__xparse_environment_or_command: } } \cs_new_protected:Npn \__xparse_defaults_def: { @@ -329,8 +353,9 @@ \__xparse_end_expandable_defaults:nnnNNn {#1} { } {#1} #2#3 { } { } { } { } { } { } { } { } { } { } { - \__kernel_msg_expandable_error:nnn - { xparse } { loop-in-defaults } {#4} + \__kernel_msg_expandable_error:nnf + { xparse } { loop-in-defaults } + { \exp_args:Nf \tl_trim_spaces:n { \token_to_str:N #4 } } \use_iv:nnnn } \q_stop @@ -358,7 +383,6 @@ { #2 \__xparse_end_expandable_defaults:nnnNNn { #3 {#1} } } \cs_new_protected:Npn \__xparse_normalize_arg_spec:n #1 { - \int_zero:N \l__xparse_mandatory_args_int \int_zero:N \l__xparse_current_arg_int \tl_clear:N \l__xparse_last_delimiters_tl \tl_clear:N \l__xparse_arg_spec_tl @@ -373,7 +397,7 @@ \int_compare:nNnT \l__xparse_current_arg_int > 9 { \__kernel_msg_error:nnxx { xparse } { too-many-arguments } - { \iow_char:N \\ \l__xparse_function_tl } { \tl_to_str:n {#1} } + { \__xparse_environment_or_command: } { \tl_to_str:n {#1} } \__xparse_bad_def:wn } \bool_if:NT \l__xparse_expandable_bool @@ -397,7 +421,7 @@ \cs_if_exist_use:cF { __xparse_normalize_type_ \tl_to_str:n {#1} :w } { \__kernel_msg_error:nnxx { xparse } { unknown-argument-type } - { \iow_char:N \\ \l__xparse_function_tl } { \tl_to_str:n {#1} } + { \__xparse_environment_or_command: } { \tl_to_str:n {#1} } \__xparse_bad_def:wn } } @@ -448,7 +472,7 @@ \bool_if:NT \l__xparse_long_bool { \__kernel_msg_error:nnxx { xparse } { two-markers } - { \iow_char:N \\ \l__xparse_function_tl } { + } + { \__xparse_environment_or_command: } { + } \__xparse_bad_def:wn } \bool_set_true:N \l__xparse_long_bool @@ -461,7 +485,7 @@ \bool_if:NT \l__xparse_obey_spaces_bool { \__kernel_msg_error:nnxx { xparse } { two-markers } - { \iow_char:N \\ \l__xparse_function_tl } { ! } + { \__xparse_environment_or_command: } { ! } \__xparse_bad_def:wn } \bool_set_true:N \l__xparse_obey_spaces_bool @@ -559,6 +583,23 @@ \__xparse_add_arg_spec_mandatory:n { v } \__xparse_normalize_arg_spec_loop:n } +\cs_new_protected:Npn \__xparse_normalize_type_b:w #1 + { + \bool_if:NF \l__xparse_environment_bool + { + \__kernel_msg_error:nnxx + { xparse } { invalid-command-arg } + { \__xparse_environment_or_command: } { b } + \__xparse_bad_def:wn + } + \tl_clear:N \l__xparse_last_delimiters_tl + \__xparse_add_arg_spec:n { b } + \quark_if_recursion_tail_stop:n {#1} + \__kernel_msg_error:nnxx { xparse } { arg-after-body } + { \__xparse_environment_or_command: } + { \tl_to_str:n {#1} } + \__xparse_bad_def:wn + } \cs_new_protected:Npn \__xparse_single_char_check:n #1 { \tl_trim_spaces_apply:nN {#1} \tl_if_single_token:nTF @@ -569,13 +610,13 @@ { \exp_args:No \tl_to_str:n { \use:nn #1 { } } } { \__kernel_msg_warning:nnxx { xparse } { not-single-char } - { \iow_char:N \\ \l__xparse_function_tl } { \tl_to_str:n {#1} } + { \__xparse_environment_or_command: } { \tl_to_str:n {#1} } } \group_end: } { \__kernel_msg_error:nnxx { xparse } { not-single-char } - { \iow_char:N \\ \l__xparse_function_tl } { \tl_to_str:n {#1} } + { \__xparse_environment_or_command: } { \tl_to_str:n {#1} } \__xparse_bad_def:wn } } @@ -617,7 +658,7 @@ \cs_new_protected:Npn \__xparse_bad_arg_spec:wn #1 \__xparse_break_point:n #2 { \__kernel_msg_error:nnxx { xparse } { bad-arg-spec } - { \iow_char:N \\ \l__xparse_function_tl } { \tl_to_str:n {#2} } + { \__xparse_environment_or_command: } { \tl_to_str:n {#2} } } \cs_new_protected:Npn \__xparse_bad_def:wn #1 \__xparse_break_point:n #2 { } \cs_new_protected:Npn \__xparse_add_arg_spec:n #1 @@ -651,10 +692,9 @@ \bool_if:NT \l__xparse_some_obey_spaces_bool { \__kernel_msg_error:nnxx { xparse } { non-trailing-obey-spaces } - { \iow_char:N \\ \l__xparse_function_tl } { \tl_to_str:n {#1} } + { \__xparse_environment_or_command: } { \tl_to_str:n {#1} } \__xparse_bad_def:wn } - \int_incr:N \l__xparse_mandatory_args_int \tl_clear:N \l__xparse_last_delimiters_tl \__xparse_add_arg_spec:n {#1} } @@ -710,11 +750,18 @@ \tl_put_left:Nn \l__xparse_process_one_tl { {#1} } \__xparse_prepare_signature_bypass:N } +\cs_new_protected:Npn \__xparse_add_type_b:w + { + \__xparse_flush_m_args: + \__xparse_add_default: + \__xparse_add_grabber:N b + \__xparse_prepare_signature:N + } \cs_new_protected:Npn \__xparse_add_type_D:w #1#2#3 { \__xparse_flush_m_args: \__xparse_add_default:n {#3} - \__xparse_add_grabber_optional:N D + \__xparse_add_grabber:N D \tl_put_right:Nn \l__xparse_signature_tl { #1 #2 } \__xparse_prepare_signature:N } @@ -722,7 +769,7 @@ { \__xparse_flush_m_args: \__xparse_add_default_E:nn {#1} {#2} - \__xparse_add_grabber_optional:N E + \__xparse_add_grabber:N E \tl_put_right:Nn \l__xparse_signature_tl { {#1} } \__xparse_prepare_signature:N } @@ -730,21 +777,21 @@ { \__xparse_flush_m_args: \__xparse_add_default:n {#1} - \__xparse_add_grabber_optional:N G + \__xparse_add_grabber:N G \__xparse_prepare_signature:N } \cs_new_protected:Npn \__xparse_add_type_l:w { \__xparse_flush_m_args: \__xparse_add_default: - \__xparse_add_grabber_mandatory:N l + \__xparse_add_grabber:N l \__xparse_prepare_signature:N } \cs_new_protected:Npn \__xparse_add_type_m:w { \__xparse_add_default: \bool_if:NTF \l__xparse_prefixed_bool - { \__xparse_add_grabber_mandatory:N m } + { \__xparse_add_grabber:N m } { \int_incr:N \l__xparse_m_args_int } \__xparse_prepare_signature:N } @@ -752,7 +799,7 @@ { \__xparse_flush_m_args: \__xparse_add_default:n {#3} - \__xparse_add_grabber_mandatory:N R + \__xparse_add_grabber:N R \tl_put_right:Nn \l__xparse_signature_tl { #1 #2 } \__xparse_prepare_signature:N } @@ -760,7 +807,7 @@ { \__xparse_flush_m_args: \__xparse_add_default: - \__xparse_add_grabber_optional:N t + \__xparse_add_grabber:N t \tl_put_right:Nn \l__xparse_signature_tl {#1} \__xparse_prepare_signature:N } @@ -768,7 +815,7 @@ { \__xparse_flush_m_args: \__xparse_add_default: - \__xparse_add_grabber_mandatory:N u + \__xparse_add_grabber:N u \tl_put_right:Nn \l__xparse_signature_tl { {#1} } \__xparse_prepare_signature:N } @@ -776,7 +823,7 @@ { \__xparse_flush_m_args: \exp_args:No \__xparse_add_default:n \c_novalue_tl - \__xparse_add_grabber_mandatory:N v + \__xparse_add_grabber:N v \__xparse_prepare_signature:N } \cs_new_protected:Npn \__xparse_flush_m_args: @@ -785,18 +832,12 @@ { \tl_put_right:Nx \l__xparse_signature_tl { \exp_not:c { __xparse_grab_m_ \int_use:N \l__xparse_m_args_int :w } } - \int_sub:Nn \l__xparse_mandatory_args_int { \l__xparse_m_args_int } \tl_put_right:Nx \l__xparse_process_all_tl { \prg_replicate:nn { \l__xparse_m_args_int } { { } } } } \int_zero:N \l__xparse_m_args_int } -\cs_new_protected:Npn \__xparse_add_grabber_mandatory:N #1 - { - \__xparse_add_grabber_optional:N #1 - \int_decr:N \l__xparse_mandatory_args_int - } -\cs_new_protected:Npn \__xparse_add_grabber_optional:N #1 +\cs_new_protected:Npn \__xparse_add_grabber:N #1 { \tl_put_right:Nx \l__xparse_signature_tl { @@ -967,6 +1008,33 @@ \cs_set_eq:NN #1 \__xparse_tmp:w \tl_set:Nn #2 {#1} } +\cs_new_protected:Npn \__xparse_grab_b:w + { \__xparse_grab_b_aux:NNw \cs_set_protected_nopar:Npn \tl_trim_spaces:n } +\cs_new_protected:Npn \__xparse_grab_b_long:w + { \__xparse_grab_b_aux:NNw \cs_set_protected:Npn \tl_trim_spaces:n } +\cs_new_protected:Npn \__xparse_grab_b_obey_spaces:w + { \__xparse_grab_b_aux:NNw \cs_set_protected_nopar:Npn \exp_not:n } +\cs_new_protected:Npn \__xparse_grab_b_long_obey_spaces:w + { \__xparse_grab_b_aux:NNw \cs_set_protected:Npn \exp_not:n } +\cs_new_protected:Npn \__xparse_grab_b_aux:NNw #1#2#3 \__xparse_run_code: + { + \__xparse_grab_D_aux:NNnN \begin \end {#3} #1 + \tl_put_left:Nn \l__xparse_signature_tl { \__xparse_grab_b_end:Nw #2 } + \tl_set_eq:NN \l__xparse_saved_args_tl \l__xparse_args_tl + \tl_clear:N \l__xparse_args_tl + \exp_args:Nc \l__xparse_fn_tl { begin ~ } + } +\cs_new_protected:Npn \__xparse_grab_b_end:Nw #1#2 \__xparse_run_code: + { + \tl_set:Nx \l__xparse_args_tl + { + \exp_not:V \l__xparse_saved_args_tl + { \exp_after:wN #1 \l__xparse_args_tl } + } + #2 + \__xparse_run_code: + \end + } \cs_new_protected:Npn \__xparse_grab_D:w #1#2#3 \__xparse_run_code: { \__xparse_grab_D_aux:NNnNN #1 #2 {#3} \cs_set_protected_nopar:Npn @@ -1244,7 +1312,7 @@ { \__xparse_grab_D_call:Nw #1 } { \__kernel_msg_error:nnxx { xparse } { missing-required } - { \exp_after:wN \token_to_str:N \l__xparse_fn_tl } + { \__xparse_environment_or_command: } { \token_to_str:N #1 } \__xparse_add_arg:o \c_novalue_tl } @@ -1401,14 +1469,14 @@ \peek_meaning_remove:NTF \char_generate:nn { \tex_endlinechar:D } { 6 } { \__kernel_msg_error:nnxxx { xparse } { verbatim-newline } - { \exp_after:wN \token_to_str:N \l__xparse_fn_tl } + { \__xparse_environment_or_command: } { \tl_to_str:N \l__xparse_v_arg_tl } { \tl_to_str:n {#1} } \__xparse_add_arg:o \c_novalue_tl } { \__kernel_msg_error:nnxxx { xparse } { verbatim-tokenized } - { \exp_after:wN \token_to_str:N \l__xparse_fn_tl } + { \__xparse_environment_or_command: } { \tl_to_str:N \l__xparse_v_arg_tl } { \tl_to_str:n {#1} } \__xparse_add_arg:o \c_novalue_tl @@ -1577,8 +1645,10 @@ \q_nil { } ##2 \ERROR \q__xparse \ERROR } { - \__kernel_msg_expandable_error:nnnn - { xparse } { missing-required } {##5} {##2} + \__kernel_msg_expandable_error:nnff + { xparse } { missing-required } + { \exp_args:Nf \tl_trim_spaces:n { \token_to_str:N ##5 } } + { \tl_to_str:n {##2} } ##4 {#1} \q__xparse ##5 ##6 {##7} } } @@ -1603,8 +1673,10 @@ ##6 \ERROR } { - \__kernel_msg_expandable_error:nnnn - { xparse } { missing-required } {##4} {##2} + \__kernel_msg_expandable_error:nnff + { xparse } { missing-required } + { \exp_args:Nf \tl_trim_spaces:n { \token_to_str:N ##4 } } + { \tl_to_str:n {##2} } ##3 {#1} \q__xparse ##4 ##5 {##6} } } @@ -1709,26 +1781,27 @@ { \tl_set:Nx \ProcessedArgument { \tl_trim_spaces:n {#1} } } \cs_new_protected:Npn \__xparse_get_arg_spec_error:N #1 { - \cs_if_exist:NTF #1 - { - \__kernel_msg_error:nnx { xparse } { non-xparse-command } - { \token_to_str:N #1 } - } - { - \__kernel_msg_error:nnx { xparse } { unknown-command } - { \token_to_str:N #1 } - } + \bool_set_false:N \l__xparse_environment_bool + \tl_set:Nn \l__xparse_fn_tl {#1} + \__xparse_get_arg_spec_error_aux:n { \cs_if_exist:NTF #1 } } \cs_new_protected:Npn \__xparse_get_arg_spec_error:n #1 { - \cs_if_exist:cTF {#1} + \bool_set_true:N \l__xparse_environment_bool + \str_set:Nx \l__xparse_environment_str {#1} + \__xparse_get_arg_spec_error_aux:n + { \cs_if_exist:cTF { \l__xparse_environment_str } } + } +\cs_new_protected:Npn \__xparse_get_arg_spec_error_aux:n #1 + { + #1 { - \__kernel_msg_error:nnx { xparse } { non-xparse-environment } - { \tl_to_str:n {#1} } + \__kernel_msg_error:nnx { xparse } { non-xparse } + { \__xparse_environment_or_command: } } { - \__kernel_msg_error:nnx { xparse } { unknown-environment } - { \tl_to_str:n {#1} } + \__kernel_msg_error:nnx { xparse } { unknown } + { \__xparse_environment_or_command: } } } \cs_new_protected:Npn \__xparse_get_arg_spec:NTF #1#2#3 @@ -1828,15 +1901,16 @@ { \exp_args:Nf \str_case_e:nnTF { - \exp_args:Nf \tl_if_empty:nT { \token_get_arg_spec:N #1 } + \exp_args:Nf \tl_if_empty:nT { \cs_argument_spec:N #1 } { \exp_last_unbraced:Nf \__xparse_cmd_if_xparse_aux:w - { \token_get_replacement_spec:N #1 } ~ \q_stop + { \cs_replacement_spec:N #1 } ~ \q_stop } } { { \token_to_str:N \__xparse_start:nNNnnn } { } { \token_to_str:N \__xparse_start_expandable:nNNNNn } { } + { \token_to_str:N \__xparse_start_env:nnnnn } { } } } \cs_new:Npn \__xparse_cmd_if_xparse_aux:w #1 ~ #2 \q_stop {#1} @@ -1850,40 +1924,60 @@ { \__xparse_peek_nonspace_aux:nNNTF { #1 ~ } #2 #3 {#4} {#5} } { #2 #3 { #4 } { #5 #1 } } } +\cs_new:Npn \__xparse_environment_or_command: + { + \bool_if:NTF \l__xparse_environment_bool + { environment ~ ' \l__xparse_environment_str ' } + { + command ~ ' + \exp_args:Nf \tl_trim_spaces:n + { \exp_after:wN \token_to_str:N \l__xparse_fn_tl } + ' + } + } +\tl_const:Nn \c__xparse_ignore_def_tl + { \\ \\ LaTeX~will~ignore~this~entire~definition. } +\__kernel_msg_new:nnnn { xparse } { arg-after-body } + { In~the~definition~of~#1,~b~(body)~argument~must~be~last. } + { + The~'body'~argument~type~is~followed~by~'#2'~in~the~argument~ + specification~of~the~#1.~This~is~not~allowed. + \c__xparse_ignore_def_tl + } \__kernel_msg_new:nnnn { xparse } { bad-arg-spec } - { Bad~argument~specification~'#2'~for~command~'#1'. } + { Bad~argument~specification~'#2'~for~#1. } { The~argument~specification~provided~was~not~valid:~ - one~or~more~mandatory~pieces~of~information~were~missing. \\ \\ - LaTeX~will~ignore~this~entire~definition. + one~or~more~mandatory~pieces~of~information~were~missing. + \c__xparse_ignore_def_tl } \__kernel_msg_new:nnnn { xparse } { command-already-defined } { Command~'#1'~already~defined! } { You~have~used~#2~ - with~a~command~that~already~has~a~definition. \\ + with~a~command~that~already~has~a~definition. \\ \\ The~existing~definition~of~'#1'~will~not~be~altered. } \__kernel_msg_new:nnnn { xparse } { command-not-yet-defined } { Command ~'#1'~not~yet~defined! } { You~have~used~#2~ - with~a~command~that~was~never~defined. \\ - LaTeX~will~ignore~this~entire~definition. + with~a~command~that~was~never~defined. + \c__xparse_ignore_def_tl } \__kernel_msg_new:nnnn { xparse } { environment-already-defined } { Environment~'#1'~already~defined! } { You~have~used~\NewDocumentEnvironment - with~an~environment~that~already~has~a~definition. \\ - The~existing~definition~of~'#1'~will~be~overwritten. + with~an~environment~that~already~has~a~definition. \\ \\ + The~existing~definition~of~'#1'~will~not~be~altered. } \__kernel_msg_new:nnnn { xparse } { environment-not-yet-defined } { Environment~'#1'~not~yet~defined! } { You~have~used~\RenewDocumentEnvironment - with~an~environment~that~was~never~defined. \\ - LaTeX~will~ignore~this~entire~definition. + with~an~environment~that~was~never~defined. + \c__xparse_ignore_def_tl } \__kernel_msg_new:nnnn { xparse } { expandable-ending-optional } { @@ -1895,25 +1989,26 @@ (or~no~arguments~at~all).~You~cannot~have~a~terminal~optional~ argument~with~expandable~commands. } -\__kernel_msg_new:nnnn { xparse } { if-boolean } - { Invalid~use~\iow_char:N\\IfBooleanTF~{#1} } - { - The~first~argument~of~\iow_char:N\\IfBoolean(TF/T/F)~must~be~ - a~boolean~argument~obtained~from~parsing~'s'~or~'t'~arguments. - } \__kernel_msg_new:nnnn { xparse } { inconsistent-long } { Inconsistent~long~arguments~for~expandable~command~'#1'. } { The~arguments~for~an~expandable~command~must~not~involve~short~ arguments~after~long~arguments.~You~have~tried~to~mix~the~two~types. } +\__kernel_msg_new:nnnn { xparse } { invalid-command-arg } + { Argument~type~'#2'~not~available~for~#1. } + { + The~letter~'#2'~can~only~be~used~in~environment~argument~ + specifications,~not~for~commands. + \\ \\ + LaTeX~will~ignore~this~entire~definition. + } \__kernel_msg_new:nnnn { xparse } { invalid-expandable-argument-type } { Argument~type~'#2'~not~available~for~expandable~command~'#1'. } { - The~letter~'#2'~does~not~specify~an~argument~type~which~can~be~used~ + The~letter~'#2'~specifies~an~argument~type~which~cannot~be~used~ in~an~expandable~command. - \\ \\ - LaTeX~will~ignore~this~entire~definition. + \c__xparse_ignore_def_tl } \__kernel_msg_new:nnnn { xparse } { invalid-after-optional-expandably } { @@ -1921,41 +2016,15 @@ for~expandable~command~'#1'. } { - The~letter~'#2'~does~not~specify~an~argument~type~which~can~be~used~ + The~letter~'#2'~specifies~an~argument~type~which~cannot~be~used~ in~an~expandable~command~after~an~optional~argument. - \\ \\ - LaTeX~will~ignore~this~entire~definition. - } -\__kernel_msg_new:nnnn { xparse } { loop-in-defaults } - { Circular~dependency~in~defaults~of~'#1'. } - { - The~default~values~of~two~or~more~arguments~of~'#1'~depend~on~each~ - other~in~a~way~that~cannot~be~resolved. - } -\__kernel_msg_new:nnnn { xparse } { missing-required } - { Failed~to~find~required~argument~starting~with~'#2'~for~command~'#1'. } - { - The~current~command~'#1'~expects~an~argument~starting~with~'#2'.~ - LaTeX~did~not~find~it,~and~will~insert~a~default~value~to~be~processed. + \c__xparse_ignore_def_tl } \__kernel_msg_new:nnnn { xparse } { non-trailing-obey-spaces } - { Prefix~'!'~used~before~mandatory~argument~'#2'~of~command~'#1'. } + { Prefix~'!'~used~before~mandatory~argument~'#2'~of~#1. } { The~prefix~'!'~can~only~apply~to~trailing~optional~arguments. - \\ \\ - LaTeX~will~ignore~this~entire~definition. - } -\__kernel_msg_new:nnnn { xparse } { non-xparse-command } - { Command~'#1'~not~defined~using~xparse. } - { - You~have~asked~for~the~argument~specification~for~a~command~'#1',~ - but~this~is~not~a~command~defined~using~xparse. - } -\__kernel_msg_new:nnnn { xparse } { non-xparse-environment } - { Environment~'#1'~not~defined~using~xparse. } - { - You~have~asked~for~the~argument~specification~for~an~environment~'#1',~ - but~this~is~not~an~environment~defined~using~xparse. + \c__xparse_ignore_def_tl } \__kernel_msg_new:nnnn { xparse } { not-definable } { First~argument~of~'#2'~must~be~a~command. } @@ -1963,89 +2032,99 @@ The~first~argument~of~'#2'~should~be~the~document~command~that~will~ be~defined.~The~provided~argument~'#1'~is~a~character.~Perhaps~a~ backslash~is~missing? - \\ \\ - LaTeX~will~ignore~this~entire~definition. + \c__xparse_ignore_def_tl } \__kernel_msg_new:nnnn { xparse } { not-one-token } { First~argument~of~'#2'~must~be~a~command. } { The~first~argument~of~'#2'~should~be~the~document~command~that~will~ be~defined.~The~provided~argument~'#1'~contains~more~than~one~ - token. - \\ \\ - LaTeX~will~ignore~this~entire~definition. + token.~Perhaps~a~backslash~is~missing? + \c__xparse_ignore_def_tl } \__kernel_msg_new:nnnn { xparse } { not-single-char } { - Argument~delimiter~'#2'~for~the~command~'#1'~should~be~ + Argument~delimiter~'#2'~for~the~#1~should~be~ a~single~character. } { The~argument~specification~provided~was~not~valid:~in~a~place~ - where~a~single~character~is~required,~LaTeX~found~'#2'. \\ \\ - LaTeX~will~ignore~this~entire~definition. + where~a~single~character~is~required,~LaTeX~found~'#2'. + \c__xparse_ignore_def_tl } \__kernel_msg_new:nnnn { xparse } { processor-in-expandable } { Argument~processor~'>{#2}'~cannot~be~used~for~the~expandable~command~'#1'. } { The~argument~specification~for~#1~contains~a~processor~function:~ - this~is~only~supported~for~standard~robust~commands. \\ \\ - LaTeX~will~ignore~this~entire~definition. - } -\__kernel_msg_new:nnnn { xparse } { split-excess-tokens } - { Too~many~'#1'~tokens~when~trying~to~split~argument. } - { - LaTeX~was~asked~to~split~the~input~'#3'~ - at~each~occurrence~of~the~token~'#1',~up~to~a~maximum~of~#2~parts.~ - There~were~too~many~'#1'~tokens. + this~is~only~supported~for~standard~robust~commands. + \c__xparse_ignore_def_tl } \__kernel_msg_new:nnnn { xparse } { too-many-arguments } - { Too~many~arguments~in~argument~specification~'#2'~of~command~'#1'. } + { Too~many~arguments~in~argument~specification~'#2'~of~#1. } { The~argument~specification~provided~has~more~than~9~arguments.~ - This~cannot~be~implemented. \\ \\ - LaTeX~will~ignore~this~entire~definition. + This~cannot~be~implemented. + \c__xparse_ignore_def_tl } \__kernel_msg_new:nnnn { xparse } { two-markers } - { Two~'#2'~apply~to~the~same~argument~in~argument~specification~of~command~'#1'. } + { Two~'#2'~apply~to~the~same~argument~in~argument~specification~of~#1. } { The~argument~specification~provided~has~two~markers~'#2'~applying~ to~the~same~argument;~these~are~redundant. } \__kernel_msg_new:nnnn { xparse } { unknown-argument-type } - { Unknown~argument~type~'#2'~for~the~command~'#1'. } + { Unknown~argument~type~'#2'~for~the~#1. } { - The~letter~'#2'~does~not~specify~a~known~argument~type.~ - LaTeX~will~ignore~this~entire~definition. + The~letter~'#2'~does~not~specify~a~known~argument~type. + \c__xparse_ignore_def_tl } -\__kernel_msg_new:nnnn { xparse } { unknown-command } - { Unknown~document~command~'#1'. } +\__kernel_msg_new:nnn { xparse } { if-boolean } + { Invalid~use~\iow_char:N\\IfBooleanTF~{#1} } +\__kernel_msg_new:nnnn { xparse } { loop-in-defaults } + { Defaults~of~#1~have~circular~dependency. } { - You~have~asked~for~the~argument~specification~for~a~command~'#1',~ - but~it~is~not~defined. + The~default~values~of~two~or~more~arguments~of~the~#1~ + depend~on~each~other~in~a~way~that~cannot~be~resolved. + } +\__kernel_msg_new:nnnn { xparse } { missing-required } + { Missing~required~argument~for~#1. } + { + The~current~#1~expects~an~argument~starting~with~'#2'.~ + LaTeX~did~not~find~it,~and~will~insert~a~default~value~to~be~processed. } -\__kernel_msg_new:nnnn { xparse } { unknown-environment } - { Unknown~document~environment~'#1'. } +\__kernel_msg_new:nnnn { xparse } { non-xparse } + { \str_upper_case:n #1~not~defined~using~xparse. } { - You~have~asked~for~the~argument~specification~for~an~environment~'#1',~ + You~have~asked~for~the~argument~specification~for~the~#1,~ + but~this~was~not~defined~using~xparse. + } +\__kernel_msg_new:nnnn { xparse } { split-excess-tokens } + { Too~many~'#1'~tokens~when~trying~to~split~argument. } + { + LaTeX~was~asked~to~split~the~input~'#3'~ + at~each~occurrence~of~the~token~'#1',~up~to~a~maximum~of~#2~parts.~ + There~were~too~many~'#1'~tokens. + } +\__kernel_msg_new:nnnn { xparse } { unknown } + { Unknown~document~#1. } + { + You~have~asked~for~the~argument~specification~for~the~#1,~ but~it~is~not~defined. } \__kernel_msg_new:nnnn { xparse } { verbatim-newline } - { Verbatim~argument~of~'#1'~ended~by~end~of~line. } + { Verbatim~argument~of~#1~ended~by~end~of~line. } { - The~verbatim~argument~of~'#1'~cannot~contain~more~than~one~line,~ + The~verbatim~argument~of~the~#1~cannot~contain~more~than~one~line,~ but~the~end~ - of~the~current~line~has~been~reached.~You~have~probably~forgotten~the~ + of~the~current~line~has~been~reached.~You~may~have~forgotten~the~ closing~delimiter. \\ \\ LaTeX~will~ignore~'#2'. } \__kernel_msg_new:nnnn { xparse } { verbatim-tokenized } + { The~verbatim~#1~cannot~be~used~inside~an~argument. } { - The~verbatim~command~'#1'~cannot~be~used~inside~an~argument.~ - } - { - The~command~'#1'~takes~a~verbatim~argument.~ + The~#1~takes~a~verbatim~argument.~ It~may~not~appear~within~the~argument~of~another~function.~ It~received~an~illegal~token \tl_if_empty:nF {#3} { ~'#3' } . \\ \\ @@ -2126,7 +2205,7 @@ \cs_if_exist:cTF {#1} { \__kernel_msg_error:nnx { xparse } { environment-already-defined } {#1} } { \__xparse_declare_env:nnnn {#1} {#2} {#3} {#4} } -} + } \cs_new_protected:Npn \RenewDocumentEnvironment #1#2#3#4 { \cs_if_exist:cTF {#1} @@ -2178,14 +2257,20 @@ } \cs_new:Npn \IfBooleanTF #1 { - \bool_lazy_and:nnTF - { \tl_if_single_p:n {#1} } - { \tl_if_single_token_p:n #1 } - { \bool_if:NTF #1 } - { - \__kernel_msg_error:nnn { xparse } { if-boolean } {#1} - \use_ii:nn - } + \tl_if_single:nF {#1} + { \prg_break:n { \use:n } } + \tl_if_single_token:nF #1 + { \prg_break:n { \use:n } } + \token_if_eq_meaning:NNT #1 \c_true_bool + { \prg_break:n { \use_ii:nnn } } + \token_if_eq_meaning:NNT #1 \c_false_bool + { \prg_break:n { \use_iii:nnn } } + \prg_break:n { \use:n } + \prg_break_point: + { + \__kernel_msg_expandable_error:nnn { xparse } { if-boolean } {#1} + \use_ii:nn + } } \cs_new:Npn \IfBooleanT #1#2 { \IfBooleanTF {#1} {#2} { } } \cs_new:Npn \IfBooleanF #1 { \IfBooleanTF {#1} { } } |