[latex3-commits] [l3svn] r6939 - Make \NewDocumentCommand etc themselves be document commands
noreply at latex-project.org
noreply at latex-project.org
Fri Feb 17 05:27:24 CET 2017
Author: bruno
Date: 2017-02-17 05:27:24 +0100 (Fri, 17 Feb 2017)
New Revision: 6939
Modified:
trunk/l3packages/xparse/xparse.dtx
Log:
Make \NewDocumentCommand etc themselves be document commands
The previous commit (or a variant thereof) was needed to make it possible
to define the processors as document commands: indeed, these commands have
signatures such as { +m +m } which are now grabbed expandably hence do not
alter xparse internal token lists that should not be touched in a processor.
Modified: trunk/l3packages/xparse/xparse.dtx
===================================================================
--- trunk/l3packages/xparse/xparse.dtx 2017-02-17 04:22:23 UTC (rev 6938)
+++ trunk/l3packages/xparse/xparse.dtx 2017-02-17 04:27:24 UTC (rev 6939)
@@ -4331,10 +4331,20 @@
% The user macros are pretty simple wrappers around the internal ones.
% There is however a check that the first argument is a single token,
% possibly surrounded by spaces (hence the strange \cs{use:nnn}), and
-% is definable.
+% is definable. The only command that is not defined using
+% \cs{NewDocumentCommand} is \cs{NewDocumentCommand} itself, so we
+% have to test for its existence (another option would be to use
+% \cs{cs_new_protected:Npn} but then \cs{NewDocumentCommand} would not
+% be a document command).
% \begin{macrocode}
-\cs_new_protected:Npn \NewDocumentCommand #1#2#3
+\cs_if_exist:NT \NewDocumentCommand
{
+ \__msg_kernel_error:nnxx { xparse } { command-already-defined }
+ { \use:nnn \token_to_str:N \NewDocumentCommand { } }
+ { \token_to_str:N \NewDocumentCommand }
+ }
+\@@_declare_cmd:Nnn \NewDocumentCommand { +m +m +m }
+ {
\@@_check_definable:nNT {#1} \NewDocumentCommand
{
\cs_if_exist:NTF #1
@@ -4346,7 +4356,7 @@
{ \@@_declare_cmd:Nnn #1 {#2} {#3} }
}
}
-\cs_new_protected:Npn \RenewDocumentCommand #1#2#3
+\NewDocumentCommand { \RenewDocumentCommand } { +m +m +m }
{
\@@_check_definable:nNT {#1} \RenewDocumentCommand
{
@@ -4359,12 +4369,12 @@
}
}
}
-\cs_new_protected:Npn \ProvideDocumentCommand #1#2#3
+\NewDocumentCommand { \ProvideDocumentCommand } { +m +m +m }
{
\@@_check_definable:nNT {#1} \ProvideDocumentCommand
{ \cs_if_exist:NF #1 { \@@_declare_cmd:Nnn #1 {#2} {#3} } }
}
-\cs_new_protected:Npn \DeclareDocumentCommand #1#2#3
+\NewDocumentCommand { \DeclareDocumentCommand } { +m +m +m }
{
\@@_check_definable:nNT {#1} \DeclareDocumentCommand
{ \@@_declare_cmd:Nnn #1 {#2} {#3} }
@@ -4381,21 +4391,21 @@
% \begin{macro}{\DeclareDocumentEnvironment}
% Very similar for environments.
% \begin{macrocode}
-\cs_new_protected:Npn \NewDocumentEnvironment #1#2#3#4
+\NewDocumentCommand { \NewDocumentEnvironment } { +m +m +m +m }
{
\cs_if_exist:cTF {#1}
{ \__msg_kernel_error:nnx { xparse } { environment-already-defined } {#1} }
{ \@@_declare_env:nnnn {#1} {#2} {#3} {#4} }
}
-\cs_new_protected:Npn \RenewDocumentEnvironment #1#2#3#4
+\NewDocumentCommand { \RenewDocumentEnvironment } { +m +m +m +m }
{
\cs_if_exist:cTF {#1}
{ \@@_declare_env:nnnn {#1} {#2} {#3} {#4} }
{ \__msg_kernel_error:nnx { xparse } { environment-not-yet-defined } {#1} }
}
-\cs_new_protected:Npn \ProvideDocumentEnvironment #1#2#3#4
+\NewDocumentCommand { \ProvideDocumentEnvironment } { +m +m +m +m }
{ \cs_if_exist:cF {#1} { \@@_declare_env:nnnn {#1} {#2} {#3} {#4} } }
-\cs_new_protected:Npn \DeclareDocumentEnvironment #1#2#3#4
+\NewDocumentCommand { \DeclareDocumentEnvironment } { +m +m +m +m }
{ \@@_declare_env:nnnn {#1} {#2} {#3} {#4} }
% \end{macrocode}
% \end{macro}
@@ -4409,7 +4419,7 @@
% \begin{macro}{\DeclareExpandableDocumentCommand}
% The expandable versions are essentially the same as the basic functions.
% \begin{macrocode}
-\cs_new_protected:Npn \NewExpandableDocumentCommand #1#2#3
+\NewDocumentCommand { \NewExpandableDocumentCommand } { +m +m +m }
{
\@@_check_definable:nNT {#1} \NewExpandableDocumentCommand
{
@@ -4422,7 +4432,7 @@
{ \@@_declare_expandable_cmd:Nnn #1 {#2} {#3} }
}
}
-\cs_new_protected:Npn \RenewExpandableDocumentCommand #1#2#3
+\NewDocumentCommand { \RenewExpandableDocumentCommand } { +m +m +m }
{
\@@_check_definable:nNT {#1} \RenewExpandableDocumentCommand
{
@@ -4435,7 +4445,7 @@
}
}
}
-\cs_new_protected:Npn \ProvideExpandableDocumentCommand #1#2#3
+\NewDocumentCommand { \ProvideExpandableDocumentCommand } { +m +m +m }
{
\@@_check_definable:nNT {#1} \ProvideExpandableDocumentCommand
{
@@ -4443,7 +4453,7 @@
{ \@@_declare_expandable_cmd:Nnn #1 {#2} {#3} }
}
}
-\cs_new_protected:Npn \DeclareExpandableDocumentCommand #1#2#3
+\NewDocumentCommand { \DeclareExpandableDocumentCommand } { +m +m +m }
{
\@@_check_definable:nNT {#1} \DeclareExpandableDocumentCommand
{ \@@_declare_expandable_cmd:Nnn #1 {#2} {#3} }
@@ -4459,26 +4469,36 @@
% normal \cs{c_true_bool} and \cs{c_false_bool}, so testing for them is
% done with the \cs{bool_if:NTF} functions from \textsf{l3prg}.
% \begin{macrocode}
-\cs_new_eq:NN \IfBooleanTF \bool_if:NTF
-\cs_new_eq:NN \IfBooleanT \bool_if:NT
-\cs_new_eq:NN \IfBooleanF \bool_if:NF
+\NewExpandableDocumentCommand { \IfBooleanTF } { +m +m +m }
+ { \bool_if:NTF {#1} {#2} {#3} }
+\NewExpandableDocumentCommand { \IfBooleanT } { +m +m }
+ { \bool_if:NT {#1} {#2} }
+\NewExpandableDocumentCommand { \IfBooleanF } { +m +m }
+ { \bool_if:NF {#1} {#2} }
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\IfNoValueT, \IfNoValueF, \IfNoValueTF}
% Simple re-naming.
% \begin{macrocode}
-\cs_new_eq:NN \IfNoValueF \@@_if_no_value:nF
-\cs_new_eq:NN \IfNoValueT \@@_if_no_value:nT
-\cs_new_eq:NN \IfNoValueTF \@@_if_no_value:nTF
+\NewExpandableDocumentCommand { \IfNoValueF } { +m +m }
+ { \@@_if_no_value:nF {#1} {#2} }
+\NewExpandableDocumentCommand { \IfNoValueT } { +m +m }
+ { \@@_if_no_value:nT {#1} {#2} }
+\NewExpandableDocumentCommand { \IfNoValueTF } { +m +m +m }
+ { \@@_if_no_value:nTF {#1} {#2} {#3} }
% \end{macrocode}
% \end{macro}
+%
% \begin{macro}{\IfValueT, \IfValueF, \IfValueTF}
% Inverted logic.
% \begin{macrocode}
-\cs_new:Npn \IfValueF { \@@_if_no_value:nT }
-\cs_new:Npn \IfValueT { \@@_if_no_value:nF }
-\cs_new:Npn \IfValueTF #1#2#3 { \@@_if_no_value:nTF {#1} {#3} {#2} }
+\NewExpandableDocumentCommand { \IfValueF } { +m +m }
+ { \@@_if_no_value:nT {#1} {#2} }
+\NewExpandableDocumentCommand { \IfValueT } { +m +m }
+ { \@@_if_no_value:nF {#1} {#2} }
+\NewExpandableDocumentCommand { \IfValueTF } { +m +m +m }
+ { \@@_if_no_value:nTF {#1} {#3} {#2} }
% \end{macrocode}
% \end{macro}
%
@@ -4493,17 +4513,22 @@
% \begin{macro}{\ReverseBoolean, \SplitArgument, \SplitList, \TrimSpaces}
% Simple copies.
% \begin{macrocode}
-\cs_new_eq:NN \ReverseBoolean \@@_bool_reverse:N
-\cs_new_eq:NN \SplitArgument \@@_split_argument:nnn
-\cs_new_eq:NN \SplitList \@@_split_list:nn
-\cs_new_eq:NN \TrimSpaces \@@_trim_spaces:n
+\NewDocumentCommand { \ReverseBoolean } { +m }
+ { \@@_bool_reverse:N {#1} }
+\NewDocumentCommand { \SplitArgument } { +m +m +m }
+ { \@@_split_argument:nnn {#1} {#2} {#3} }
+\NewDocumentCommand { \SplitList } { +m +m }
+ { \@@_split_list:nn {#1} {#2} }
+\NewDocumentCommand { \TrimSpaces } { +m }
+ { \@@_trim_spaces:n {#1} }
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ProcessList}
% To support \cs{SplitList}.
% \begin{macrocode}
-\cs_new_eq:NN \ProcessList \tl_map_function:nN
+\NewExpandableDocumentCommand { \ProcessList } { +m +m }
+ { \tl_map_function:nN {#1} {#2} }
% \end{macrocode}
% \end{macro}
%
@@ -4514,18 +4539,20 @@
% More simple mappings, with a check that the argument is a single
% control sequence or active character.
% \begin{macrocode}
-\cs_new_protected:Npn \GetDocumentCommandArgSpec #1
+\NewDocumentCommand { \GetDocumentCommandArgSpec } { +m }
{
\@@_check_definable:nNT {#1} \GetDocumentCommandArgSpec
{ \@@_get_arg_spec:N #1 }
}
-\cs_new_eq:NN \GetDocumentEnvironmentArgSpec \@@_get_arg_spec:n
-\cs_new_protected:Npn \ShowDocumentCommandArgSpec #1
+\NewDocumentCommand { \GetDocumentEnvironmentArgSpec } { +m }
+ { \@@_get_arg_spec:n {#1} }
+\NewDocumentCommand { \ShowDocumentCommandArgSpec } { +m }
{
\@@_check_definable:nNT {#1} \ShowDocumentCommandArgSpec
{ \@@_show_arg_spec:N #1 }
}
-\cs_new_eq:NN \ShowDocumentEnvironmentArgSpec \@@_show_arg_spec:n
+\NewDocumentCommand { \ShowDocumentEnvironmentArgSpec } { +m }
+ { \@@_show_arg_spec:n {#1} }
% \end{macrocode}
% \end{macro}
% \end{macro}
More information about the latex3-commits
mailing list