summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/xargs/xargs.dtx
blob: ce655e3f39f527f4b2d22c197919cd9e95e714c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
% ^^A (utf-8 encoded source)
% 
% \iffalse meta-comment 
%
% Copyright (C) 2007 Manuel P\'egouri\'e-Gonnard <mpg@math.jussieu.fr>
% ----------------------------------------------------------------------
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in:
%
%    http://www.latex-project.org/lppl.txt
%
% and version 1.3c or later is part of all distributions of LaTeX
% version 2006/05/20 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The current maintainer of this work is Manuel P\'egouri\'e-Gonnard.
%
% This work consists of the files xargs.dtx and xargs.ins
% and the derived files xargs.sty and xargs.pdf.
%
% \fi
%
% \iffalse ^^A trick below with this \if...
%<*driver>
\ProvidesFile{xargs.dtx}
%</driver>
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{xargs}
%<*package>
  [2007/10/20 v1.0  extending optional arguments facilities (mpg)]
%</package>
%
%<*driver>
\documentclass[a4paper]{ltxdoc}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%\usepackage{lmodern}
\usepackage[expansion=false]{microtype}
\usepackage[bookmarks=false, colorlinks=true,
  linkcolor=black, urlcolor=black]{hyperref}
\usepackage{fixltx2e}
\newif\iffrenchdoc %\frenchdoctrue % à décommenter pour la doc française
\iffrenchdoc
  \OnlyDescription
  \usepackage[english, french]{babel}
\else
  \usepackage[french, english]{babel}
\fi
\usepackage{xargs}
\newcommand\package{\textsf}
\newcommand\xargs{\package{xargs}}
\setlength\parskip{\smallskipamount}
\begin{document}
  \DocInput{xargs.dtx}
\end{document}
%</driver>
% \fi ^^A double \fi for a single \iffalse because of 
% \fi ^^A the false \if in \newif\iffrenchdoc above :)
%
% \GetFileInfo{xargs.dtx}
% \iffrenchdoc
%   \title{L'extension \xargs}
% \else
%   \title{The \xargs{} package} 
% \fi
% \author{Manuel Pégourié-Gonnard \\ 
%   \href{mailto:mpg@math.jussieu.fr}{mpg@math.jussieu.fr}}
% \date{\fileversion{} (\filedate)}
%
% \maketitle
% \iffrenchdoc \else \tableofcontents \fi
%
%         \section{Introduction}
%
% \iffrenchdoc
%
% \LaTeXe{} permet de définir facilement des commandes ayant un argument
% optionel. Cependant, il y a deux restrictions : il peut y avoir au plus un
% argument optionel, et ce doit être le premier. L'extension \xargs{} fournit
% des versions étendues de \cs{newcommand} et de ses analogues standard, qui ne
% présentent pas ces restrictions.
%
% Vous connaissez peut-être des astuces pour définir des commandes avec
% plusieurs arguments optionels, ou avec l'argument optionel en dernier. Mais
% utiliser ces astuces vous force à résoudre certains problèmes (ordre
% d'utilisation des arguments, gestions des espaces) qui peuvent s'avérer
% délicats. C'est n'est de toute façon pas le genre de choses auxquelles vous
% devriez avoir à réfléchir quand vous rédigez un document.
%
% L'extension \xargs{} vous fournit donc un moyen pratique et (je l'espère)
% robuste de définir de telles commandes, avec une syntaxe intuitive de la forme
% \meta{clé}=\meta{valeur}.
%
% \else
%
% Defining commands with an optional argument is easy in \LaTeXe{}. There is,
% however, two limitations: there can be at most one optional argument and it
% must be the first one. The \xargs{} package provide extended variants of
% \cs{newcommand} \& friends, for which these limitations no longer hold.
%
% You may know some tricks in order to define commands with many optional
% arguments, or with last argument optional, etc. Theses tricks are subject to
% a few problems (using arguments in arbitrary order can be difficult, sometimes
% space is gobbled where it should not), which can be difficult to solve.
% Anyway, you don't want to worry about such tricky things while writing a
% document.
%
% The \xargs{} package provides you with an easy and (hopefully) robust way to
% define such commands, using a nice \meta{key}=\meta{value} syntax.
%
% \fi
%
%         \section{Usage}
%
% \iffrenchdoc
%
% L'extension \xargs{} fournit des analogues de toutes les macros de \LaTeXe{}
% relatives à la définition de macros. Les macros de \xargs{} ont le même nom
% que leur analogue standard, mais avec un |x| supplémentaire à la fin : par
% exemple, \cs{newcommandx}, \cs{renewcommandx} ou encore \cs{newenvironmentx}.
% Elles ont par ailleurs toutes la même syntaxe. Je ne présenterai donc que
% \cs{newcommandx}.
%
% Commençons par un exemple. Après la définition
% \begin{center}
% |\newcommandx*\vect[3][1=1, 3=n]{(#2_{#1},\ldots,#2_{#3})}|
% \end{center}
% ^^A j'en profite pour vérifier les espaces parasites...
% vo\newcommandx*\vect[3][1=1, 3=n]{(#2_{#1},\ldots,#2_{#3})}us
% pouvez utiliser la macro \cs{vect} d'une des façons suivantes :
% \begin{center}
% \begin{tabular}{ll}
% |$\vect{x}$| & $\vect{x}$ \\
% |$\vect[0]{y}$| & $\vect[0]{y}$ \\
% |$\vect{z}[m]$| & $\vect{z}[m]$ \\
% |$\vect[0]{t}[m]$| & $\vect[0]{t}[m]$ \\
% \end{tabular}
% \end{center}
%
% Vous avez sans doute compris qu'il s'agit d'une macro prennant trois arguments
% au total, mais dont le premier et le troisième argument sont optionnels. Ils
% ont chacun une valeur par défaut (respectivement |1| et |n| ici). Vous pouvez
% également remarquer que la syntaxe de \cs{newcomandx} est très proche de celle
% de \cs{newcommand}, la seule différence étant qu'au lieu d'indiquer la valeur
% par défaut de l'unique argument optionel, vous indiquez ici le numéro de
% chaque argument à rendre optionel, suivi de sa valeur par défaut.
%
% Détaillons maintenant la syntaxe de \cs{newcommandx}, qui, répétons-le, est
% aussi la syntaxe de toutes les autres commandes de l'extension \xargs.
% (Pendant qu'on est dans les détails, voici la liste complète de ces commandes
% : \cs{newcommandx} et \cs{renewcommandx} pour les macros simples,
% \cs{providecommandx} pour s'assurer qu'une macro existe,
% \cs{DeclareRobustCommandx} pour (re)définir une macro robuste,
% \cs{CheckCommandx} pour vérifier le sens d'une macro, \cs{newenvironmentx} et
% \cs{renewenvironmentx} pour les environnements.)
%
% \begin{center}
% \cs{newcommandx} \meta{|*|} \marg{commande} \oarg{nombre} \oarg{liste}
% \marg{définition}
% \end{center}
%
% Rappellons brièvement tout ce qui est commun avec la syntaxe usuelle, à savoir
% tout sauf \meta{liste}. Si une |*| est présente, elle signifie que la macro
% crée est \emph{courte} au sens de \TeX{}, c'est-à-dire que ses arguments ne
% peuvent pas contenir de saut de paragraphe (\cs{par} ou ligne vide). La
% \meta{commande} est n'importe quelle séquence de contrôle, que vous pouvez ou
% non entourer d'accolades suivant vos goûts. Le \meta{nombre} définit le nombre
% total d'argument de la \meta{commande}, c'est un entier compris entre $0$ et
% $9$. La \meta{définition} est un texte équilibré en accolades, et où chaque
% caractère |#| est suivi soit d'un chiffre représentant un des arguments, soit
% d'un autre caractère |#|. Les arguments entre crochets sont optionnels.
%
% La partie intéressante maintenant. La \meta{liste} est une\ldots{} liste (!)
% d'éléments de la forme \meta{chiffre}=\meta{valeur}, séparés par des virgules.
% Le \meta{chiffre} doit être un entier compris entre $1$ et le nombre
% d'arguments, donné par \meta{nombre}. La \meta{valeur} est n'importe quelle
% texte équilibré en accolades. Il peut être vide si vous le souhaitez : le
% signe égal qui le précède est alors optionel. Tous les arguments dont le
% numéro figure en tant que \meta{chiffre} dans la \meta{liste} seront
% optionnels, avec pour valeur par défaut celle donnée par la \meta{valeur}
% correspondante.
%
% Concernant l'usage des commandes, notez que, si les arguments $1$ et $2$ (par
% exemple) sont optionnels, vous ne pouvez spécifier de valeur pour l'argument
% $2$ si vous n'en avez pas spécifié pour l'argument $1$. Ce comportement est
% cohérent avec celui de commandes \LaTeX{} existantes, comme \cs{makebox}. Il
% ne provient pas d'une limitation technique mais surtout de mon incapacité à
% imaginer une situation où il est vraiment gênant et une syntaxe intelligente
% pour le contourner.  À ce sujet, observez comment j'ai pris soin de séparer
% les deux arguments optionels par l'argument obligatoire dans le définition de
% \cs{vect} ci-dessus.
%
% Quelques remarques supplémentaires sur la syntaxe de la \meta{liste}, que vous
% pouvez sauter si vous êtes familiers avec la syntaxe fournie par
% \package{xkeyval}. Vu que les éléments sont séparés par des virgules, si une
% \meta{valeur} doit contenir une virgule, il faut entourer la valeur par des
% accolades pour protéger la virgule. (Cette précaution est également
% indispensable si la \meta{valeur} contient une accolade fermante.) Ne vous
% inquiétez pas, cette parie d'accolade sera retirée ultérieurement. D'ailleurs,
% jusqu'à trois paires d'accolades seront retirées ainsi, et si vous voulez
% vraiment que votre valeur reste entourée d'acollades, il vous faudra écrire
% quelque chose comme~|1={{{{\large blabla}}}}|.
%
% La dernière particularité de la \meta{liste} que vous devez connaître, est
% qu'elle ne doit pas contenir de |\par| (ou de ligne vide). C'est le seul point
% (à ma connaissance) sur lequel les macros d'\xargs{} diffèrent des macros
% standard. Cette limitation est liée à un choix dans l'implémentation
% d'\package{xkeyval}, que j'ai eu un peu la flemme de contourner (en fait, je
% ne suis pas pleinement satisfait de la fiabilité des contournements que je
% connais). Vous pouvez utiliser \cs{endgraf} à la place de \cs{par} en cas de
% besoin. Si cette limitation vous gêne, merci de me le faire savoir.
%
% Parlons maintenant de trois fonctionnalités d'\xargs{} qui sont plus ou
% moins cachées mais que j'espère pratiques. La première est que les macros sont
% crées si possible de façon économique : si vous utilisez \cs{newcommandx} pour
% définir un macro que vous auriez pu définir avec \cs{newcommand}, \xargs{} le
% détectera et utilisera automatiquement \cs{newcommand} à la place. Ainsi, vous
% n'avez à vous soucier de rien et vous pouvez utiliser tout le temps
% \cs{newcommandx} sans vous poser de questions.
%
% La deuxième fonctionnalité est elle aussi transparente, mais comme j'ai pris
% la peine de la coder, il faut bien que j'en parle. Une macro crée par \xargs{}
% n'avalera pas les espaces qui la suivent, même si le dernier argument est
% optionel et n'est pas spécifié. C'est un des avantages d'\xargs{} sur les
% astuces classiques. Comparez les deux sur l'exemple (idiot) suivant :
% \begin{quote}
% |\newcommand\compliment[1]{#1 est gentil\complinterne}|\\
% |\newcommand\complinterne[1][le]{#1}|\\
% |\newcommandx\complimentx[2][2=le]{#1 est gentil#2}|
% \end{quote}
% \newcommand\compliment[1]{#1 est gentil\complinterne}
% \newcommand\complinterne[1][le]{#1}
% \newcommandx\complimentx[2][2=le]{#1 est gentil#2}
% \begin{center}\begin{tabular}{ll}
% |\compliment{Clothilde} et\ldots| & 
% \compliment{Clothilde} et\ldots   \\ 
% |\complimentx{Clothilde} et\ldots| & 
% \complimentx{Clothilde} et\ldots  \\ 
% \end{tabular}\end{center}
% Observez comme l'espace a été avalé de façon indésirable dans le premier cas.
%
% Enfin, les macros d'\xargs{} essayent de se comporter en tous points comme
% leurs homoloques standard. Il y a deux exceptions : la première est que vous
% ne vous pouvez pas utiliser \cs{par} comme vous voulez, je l'ai dit plus haut,
% et je le regrette. La deuxième réside dans certains comportements de
% \cs{CheckCommandx}. En effet, à l'heure où j'écris ces lignes,
% \cs{CheckCommand} souffre de deux bugs (voir
% \href{http://www.latex-project.org/cgi-bin/ltxbugs2html?pr=latex/3971&introduction=yes&state=open}
% {PR/3971}) que j'espère avoir évités dans \cs{CheckCommandx}.
% \bigskip
%
% Vous savez maintenant tout ce qu'il y a à savoir sur l'utilisation de
% \xargs{}. Si vous souhaitez vous pencher sur son implémentation, il vous
% faudra lire les commentaires en anglais car je n'ai pas eu le courage de
% commenter mon code en deux langues. Si vous découvrez des bugs, merci de me
% les signaler. Si vous trouvez cette extension utile, ça me ferait aussi
% plaisir de le savoir.
%
% \begin{center}\large
% C'est tout pour cette fois ! \\
% Amusez-vous bien avec \LaTeX{} !
% \end{center}
%
% \else
%
% The \xargs{} package defines an extended variant for every \LaTeX{} macro
% related to macro definition. \xargs{}'s macro are named after their \LaTeX{}
% couterparts, just adding an |x| at end, e.g. \cs{newcommandx},
% \cs{renewcommandx} or \cs{newenvironmentx}. Since they all share the same
% syntax (closely ressembling \cs{newcommand}'s one), I will only explain with
% \cs{newcommandx}.
%
% Let's begin with the following example.
% \begin{center}
% |\newcommandx*\vect[3][1=1, 3=n]{(#2_{#1},\ldots,#2_{#3})}|
% \end{center}
% \newcommandx*\vect[3][1=1, 3=n]{(#2_{#1},\ldots,#2_{#3})}
% \begin{center}
% \begin{tabular}{ll}
% |$\vect{x}$| & $\vect{x}$ \\
% |$\vect[0]{y}$| & $\vect[0]{y}$ \\
% |$\vect{z}[m]$| & $\vect{z}[m]$ \\
% |$\vect[0]{t}[m]$| & $\vect[0]{t}[m]$ \\
% \end{tabular}
% \end{center}
%
% You surely understood \cs{vect} is now a macro with 3 arguments, the first and
% third being optional. They both have their own default value (resp.\@ |1| and
% |n|). You maybe noticed how \cs{newcommandx}'s syntax closely ressembles
% \cs{newcommand}'s syntax: The only difference is, instead of the default value
% of the only optional argument, you have to specifiy the number of the optional
% arguments, followed by a = and their default value.
%
% Now let's have a closer look at \cs{newcommandx}'s syntax, shared by all other
% \xargs{} commands. (While dealing with details, here is the complete list of
% those: \cs{newcommandx} and \cs{renewcommandx} for simple macros,
% \cs{providecommandx} to make sure a macro exists, \cs{DeclareRobustCommandx}
% to (re)define a robust macro, \cs{CheckCommandx} to check if a macro has the
% correct meaning, \cs{newenvironmentx} and \cs{renewenvironmentx} for
% environments.)
%
% \begin{center}
% \cs{newcommandx} \meta{|*|} \marg{command} \oarg{number} \oarg{list}
% \marg{definition}
% \end{center}
%
% Everything here is the same as usual \cs{newcommand} syntax, except
% \meta{list}. Let's recall this briefly. The optional |*| make \LaTeX{} define
% a ``short'' macro, that is a macro that won't accept a paragraph break
% (\cs{par} or an empty line) inside its argument, otherwise the macro will be
% long.  \meta{command} is any control sequence, and can but need not be
% enclosed in braces, as you like. The \meta{number} specifies how many
% arguments your macro will take (including optional ones): It should be a
% non-negative integer, and at most $9$. The macro's \meta{definition} is a
% balanced text, where every |#| sign must be followed with a number, thus
% representing an argument, or with another |#| sign. The two arguments
% \meta{number} and \meta{list} are optionals.
%
% Now comes the new and funny part. \meta{list} is a coma-separated list of
% element \meta{digit}=\meta{value}. Here, \meta{digit} should be non-zero, and
% at most \meta{number} (the total number of arguments). The \meta{value} is any
% balanced text, and can be empty. If so, the |=| sign becomes optional: You
% only need to write \meta{digit} if you want the \meta{digit}th argument to be
% optional, with empty default value. Of course, every argument whose number is
% a \meta{digit} in the \meta{list} becomes optional, with \meta{value} as its
% default value.
%
% While using a macro with many optional arguments, keep in mind the following
% fact. If arguments, say $1$ and $2$, are optional, then if you specify a value
% for only one optional argument, it will be used for argument $1$, and argument
% $2$ will be considered non-specified (thus its default value will be used).
% This behaviour is consistent with existing \LaTeX{}'s command, like
% \cs{makebox}. It isn't a technical limitation, I just couldn't imagine a
% better way to do. By the way, please notice the way I separated the two
% optional arguments from the exemple above in order to be able to use them
% independantly.
%
% If you are not very familiar with some aspects of the syntax provided by the
% \package{xkeyval} package, you may be interested in the following remarks
% about the syntax of \meta{list}. Since \meta{list} is coma-separated, if you
% want to use a coma inside a \meta{value}, you need to enclose it (either the
% coma or the whole \meta{value}) in braces. The same applies if you want to use
% a closing square bracket inside the \meta{list}. Don't worry about those
% unwanted braces, they will be removed later. Actually, \package{xkeyval}
% removes up to $3$ braces set: If you really want braces around a value, you
% need to type something like |1={{{{\large stuff}}}}|.
%
% The last thing you (maybe) need to know about \meta{list} is a little
% limitation of \xargs{}, inherited from \package{xkeyval}, which I didn't
% managed to work around (actually, I know a way to do it, but it fails in rare
% cases involving \cs{let}ing an active character equal to a brace, so I decided
% not to include it). So what is this problem? It's just you cannot use \cs{par}
% (or an empty line) in the \meta{list}. If you need a paragraph break in a
% \meta{value}, try \cs{endgraf}. If this issue really bothers you, please let
% me know.
%
% There's only three features or \xargs{} not yet discussed. Since they are all
% ``good'' features, you may not need to read the end of the documentation, but
% since I made the effort to implement it, I want to talk about it. First one is
% that macros are made in a minimalistic way: If you use \cs{newcommandx} to
% create a macro you could have made with \cs{newcommand}, \xargs{} will notice
% and use \cs{newcommand} internally. So, you can allways use \cs{newcommandx}
% without bothering.
%
% Second feature consist in avoiding a possible problem with spaces after a
% macro whose last argument is optional. If defined in a naive way, such macros
% would gobble spaces after them when the optional argument is not specified,
% but macros created with \xargs{} don't, so you don't need to take any special
% care about spaces.
%
% Last, \xargs{} macros try to behave exactly as standard \LaTeX{} macros do. As
% far as I know, there are only two exceptions. I allready mentionned the first,
% which is the problem with \cs{par} in default value, due to \package{xkeyval}.
% The other one is that, right now, the current implementation of
% \cs{CheckCommand} has some problems (see
% \href{http://www.latex-project.org/cgi-bin/ltxbugs2html?pr=latex/3971&introduction=yes&state=open}
% {PR/3971}). I tried not to reproduce them in \cs{CheckCommandx}.
%
% \fi
%
% \StopEventually{}
%
%         \section{Implementation}
%
% If you are familiar with the way \LaTeXe{} manages macros with an optional
% argument, then you will probably not be surprised by the \xargs{} way.
% Indeed, with \LaTeXe{}, a command \cs{foo} defined with, say
% |\newcommand*\foo[2][bar]{baz}| is implemented as the pair:
% \begin{quote}
% |\foo=macro:->\@protected@testopt\foo\\foo{bar}| \\
% |\\foo=macro:[#1]#2->baz|
% \end{quote}
% With \xargs's \cs{newcommandx}, a macro \cs{vect} as above is
% implemented as:
% \begin{quote}
% |\vect=macro:->\@protected@testopt@xargs\vect\\vect|\\
% \hspace*{1em}|{\xargs@test@opt{0},\xargs@put@arg,\xargs@test@opt{n},}|\\
% |\\vect=macro:[#1]#2[#3]->(#2_{#1},\ldots ,#2_{#3})|
% \end{quote}
%
% This is very similar: the ``real'' macro is the one whose name begins with a
% \cs{} and the macro called by the user just checks the protection context and
% collects the arguments for the internal macro, using the default value if none
% is given for the optional argument(s). However, the analogy ends here, since
% in ``normal'' \LaTeX{} there is only one optional argument, but
% \xargs{} commands need more information about optional arguments,
% namely their position, and not only the default values.
%
% This information is stored as a coma-separated list of ``actions'', each
% action consisting of either the single command \cs{xargs@put@arg}, which
% denotes a mandatory argument and makes \LaTeX{} grab it and add it to the list
% of arguments to be passed to the internal macro, or \cs{xargs@test@opt} with
% argument the default value, which denotes an optional argument. In the later
% case, the presence of the optional argument is checked in a way slightly
% differing from \LaTeXe's \cs{@ifnextchar}, then the relevant value added to
% the arguments list.
%
% All this argument grabing job is done with a loop that read and executes each
% action from the originating list, and concurrently builds an argument list
% such as |[0]{x}[m]| to be passed to |\\vect| for example. The first part of
% the code consists of those macros used for the argument grabbing and execution
% of internal command process.
%
% \bigskip
% First, load the \package{xkeyval} package for it's nice key=value syntax.
%    \begin{macrocode}
\RequirePackage{xkeyval}
%    \end{macrocode}
%
% \begin{macro}{\xargs@max}
% \begin{macro}{\xargs@temp}
% \begin{macro}{\xargs@toksa}
% \begin{macro}{\xargs@toksb}
% Then allocate a few registers and make sure the name of our private scratch
% macro is free for use. Note that for certain uses, we really need a \cs{toks}
% register because the string used can possibly contain |#| characters.
% Sometimes I also use a \cs{toks} register instead of a macro just for ease of
% use (writing less \cs{expandafter}s).
%    \begin{macrocode}
\@ifdefinable\xargs@max{\newcount\xargs@max}
%    \end{macrocode}
%    \begin{macrocode}
\@ifdefinable\xargs@temp\relax
\@ifdefinable\xargs@toksa{\newtoks\xargs@toksa}
\@ifdefinable\xargs@toksb{\newtoks\xargs@toksb}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\@protected@testop@xargs}
% This first macros closely resembles kernel's \cs{@protected@testopt}
% (similarity in their names is intentional, see \cs{CheckCommandx}). It just
% checks the protection context and call the real argument grabbing macro.
%    \begin{macrocode}
\newcommand*\@protected@testopt@xargs[1]{%
  \ifx\protect\@typeset@protect
    \expandafter\xargs@read
  \else
    \@x@protect#1%
  \fi}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\xargs@read}
% Initiate the loop. \cs{xargs@toksa} will become the call to the internal macro
% with all arguments, \cs{xargs@toksb} contains the actions list for arguments
% grabbing. 
%    \begin{macrocode}
\newcommand*\xargs@read[2]{%
  \xargs@toksa{#1}%
  \xargs@toksb{#2}%
  \xargs@continue}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\xargs@continue}
% \begin{macro}{\xargs@pick@next}
% Each iteration of the loop consist of two steps: pick the next action (and
% remove it from the list), and execute it. When there is no more action in the
% list, it means the arguments grabbing stage is over, and it's time to execute
% the internal macro by expanding then contents of \cs{xargs@toksa}.
%    \begin{macrocode}
\newcommand\xargs@continue{%
  \expandafter\xargs@pick@next\the\xargs@toksb,\@nil
  \xargs@temp}
%    \end{macrocode}
%    \begin{macrocode}
\@ifdefinable\xargs@pick@next{%
  \def\xargs@pick@next#1,#2\@nil{%
    \def\xargs@temp{#1}%
    \xargs@toksb{#2}%
    \ifx\xargs@temp\empty
      \def\xargs@temp{\the\xargs@toksa}%
    \fi}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\xargz@put@arg}
% \begin{macro}{\xargz@test@opt}
% \begin{macro}{\xargz@put@opt}
% Now have a look at the argument grabbing macros. The first one,
% \cs{xargs@put@arg}, just reads an undelimited argument in the input stack and
% add it to the arguments list. \cs{xargs@testopt} checks if the next non-space
% token is a square bracket to decide if it have to read an argument from the
% input or use the default value, and takes care to enclose it in square
% brackets.
%    \begin{macrocode}
\newcommand\xargs@put@arg[1]{%
  \xargs@toksa\expandafter{\the\xargs@toksa{#1}}%
  \xargs@continue}
%    \end{macrocode}
%    \begin{macrocode}
\newcommand*\xargs@test@opt[1]{%
  \xargs@ifnextchar[%]
    {\xargs@put@opt}%
    {\xargs@put@opt[{#1}]}}
%    \end{macrocode}
%    \begin{macrocode}
\@ifdefinable\xargs@put@opt{%
  \long\def\xargs@put@opt[#1]{%
    \xargs@toksa\expandafter{\the\xargs@toksa[{#1}]}%
  \xargs@continue}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\xargs@ifnextchar}
% \begin{macro}{\xargs@ifnch}
% \begin{macro}{\xargs@xifnch}
% You probably noticed that \cs{xargs@testopt} doesn't use kernel's
% \cs{@ifnextchar}. The reason is, I don't want macros to gobble space if their
% last argument is optional and not specified. Indeed, it would be strange to
% have spaces after |\vect[0]{x}| gobbled. So the modified version of
% \cs{@ifnextchar} below works like kernel's one, except that it remembers how
% many spaces it gobbles and restitutes them in case the next non-space
% character isn't a match.
%    \begin{macrocode}
\newcommand\xargs@ifnextchar[3]{%
  \let\xargs@temp\empty
  \let\reserved@d=#1%
  \def\reserved@a{#2}%
  \def\reserved@b{#3}%
  \futurelet\@let@token\xargs@ifnch}
%    \end{macrocode}
%    \begin{macrocode}
\newcommand\xargs@ifnch{%
  \ifx\@let@token\@sptoken
    \edef\xargs@temp{\xargs@temp\space}%
    \let\reserved@c\xargs@xifnch
  \else
    \ifx\@let@token\reserved@d
      \let\reserved@c\reserved@a
    \else
      \def\reserved@c{\expandafter\reserved@b\xargs@temp}%
    \fi
  \fi
  \reserved@c}
%    \end{macrocode}
%    \begin{macrocode}
\@ifdefinable\xargs@xifnch{%
  \expandafter\def\expandafter\xargs@xifnch\space{%
    \futurelet\@let@token\xargs@ifnch}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \bigskip
% 
% Okay, we're finished with the execution related macros. Now let's start with
% stuff for the definition of macros. The idea is to collect through
% \package{xkeyval} at most 9 actions numbered 1 to \cs{xargs@max} (the total
% number of arguments) of the type seen above, then structure them in a
% coma-separated list for use in the user macro's definition. Special care is
% taken to define simpler macros in the two special cases where all arguments,
% possibly except the first one, are mandatory (standard \LaTeXe{} cases).
%
% \begin{macro}{\@namenewc} \begin{macro}{\xargs@action@1}
% \begin{macro}{\xargs@action@2} \begin{macro}{\xargs@action@3}
% \begin{macro}{\xargs@action@4} \begin{macro}{\xargs@action@5}
% \begin{macro}{\xargs@action@6} \begin{macro}{\xargs@action@7}
% \begin{macro}{\xargs@action@8} \begin{macro}{\xargs@action@9}
% So our first task is to define container macros for these at most nine
% actions, with default value \cs{xargs@put@arg} since every argument is
% mandatory unless specified.
%    \begin{macrocode}
\providecommand\@namenewc[1]{%
  \expandafter\newcommand\csname #1\endcsname}
%    \end{macrocode}
%    \begin{macrocode}
\@namenewc{xargs@action@1}{\xargs@put@arg}
\@namenewc{xargs@action@2}{\xargs@put@arg}
\@namenewc{xargs@action@3}{\xargs@put@arg}
\@namenewc{xargs@action@4}{\xargs@put@arg}
\@namenewc{xargs@action@5}{\xargs@put@arg}
\@namenewc{xargs@action@6}{\xargs@put@arg}
\@namenewc{xargs@action@7}{\xargs@put@arg}
\@namenewc{xargs@action@8}{\xargs@put@arg}
\@namenewc{xargs@action@9}{\xargs@put@arg}
%    \end{macrocode}
% \end{macro} \end{macro}
% \end{macro} \end{macro}
% \end{macro} \end{macro}
% \end{macro} \end{macro}
% \end{macro} \end{macro}
% \begin{macro}{\xargs@def@key}
% The next macro will define key for us. Its first argument is the key's
% number. The second argument will be discussed later.
%    \begin{macrocode}
\newcommand*\xargs@def@key[2]{%
  \define@key[xargs]{key}{#1}[]{%
%    \end{macrocode}
% The first thing do to, before setting any action, is to check wether this key
% can be used for this command, and complain if not.
%    \begin{macrocode}
    \ifnum\xargs@max<#1
      \PackageError{xargs}{%
        Illegal argument label in\MessageBreak
        optional arguments description%
        }{%
        You are trying to make optional an argument whose label (#1)
        \MessageBreak is higher than the total number (\the\xargs@max)
        of parameters. \MessageBreak This can't be done and your demand
        will be ignored.}%
    \else
%    \end{macrocode}
% If the key number is correct, it may be that the user is trying to use it
% twice for the same command. Since it's probably a mistake, issue a warning in
% such case.
%    \begin{macrocode}
      \expandafter\expandafter\expandafter
      \ifx\csname xargs@action@#1\endcsname\xargs@put@arg \else
        \PackageWarning{xargs}{%
          Argument #1 was allready given a default value.\MessageBreak
          Previous value will be overriden.\MessageBreak}%
      \fi
%    \end{macrocode}
% If everything looks okay, define the action to be \cs{xargs@test@opt} with the
% given value, and execute the (for now) mysterious second argument.
%    \begin{macrocode}
      \@namedef{xargs@action@#1}{\xargs@test@opt{##1}}%
      #2%
    \fi}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\ifxargs@firstopt@}
% \begin{macro}{\ifxargs@otheropt@}
% \begin{macro}{\xargs@key@1}
% \begin{macro}{\xargs@key@2} \begin{macro}{\xargs@key@3}
% \begin{macro}{\xargs@key@4} \begin{macro}{\xargs@key@5}
% \begin{macro}{\xargs@key@6} \begin{macro}{\xargs@key@7}
% \begin{macro}{\xargs@key@8} \begin{macro}{\xargs@key@9}
% The second argument just consist in setting the value for some \cs{if} wich
% will keep track of the existence of an optional argument other than the first
% one, and the of the possibly otpional nature of the first. Such information
% will be usefull when we will have to decide if we use the \LaTeXe{} standard
% way or \xargs{} custom one to define the macro.
%    \begin{macrocode}
\newif\ifxargs@firstopt@
\newif\ifxargs@otheropt@
%    \end{macrocode}
% Now actually define the keys. 
%    \begin{macrocode}
\xargs@def@key1\xargs@firstopt@true
\xargs@def@key2\xargs@otheropt@true \xargs@def@key3\xargs@otheropt@true
\xargs@def@key4\xargs@otheropt@true \xargs@def@key5\xargs@otheropt@true
\xargs@def@key6\xargs@otheropt@true \xargs@def@key7\xargs@otheropt@true
\xargs@def@key8\xargs@otheropt@true \xargs@def@key9\xargs@otheropt@true
%    \end{macrocode}
% \end{macro} \end{macro} \end{macro}
% \end{macro} \end{macro} \end{macro}
% \end{macro} \end{macro} \end{macro}
% \end{macro} \end{macro}
% \begin{macro}{\xargs@setkeys}
% \begin{macro}{\xargs@check@keys}
% We set the keys with the starred version of \cs{setkeys}, so we can check if
% there were some strange keys we cannot handle, and issue a meaningfull warning
% if there are some.
%    \begin{macrocode}
\newcommand\xargs@setkeys[1]{%
  \setkeys*[xargs]{key}{#1}%
  \xargs@check@keys}
%    \end{macrocode}
%    \begin{macrocode}
\newcommand\xargs@check@keys{%
  \ifx\XKV@rm\empty \else
    \xargs@toksa\expandafter{\XKV@rm}%
    \PackageError{xargs}{%
      Illegal argument label in\MessageBreak
      optional arguments description%
      }{%
      You can only use non-zero digits as argument labels.\MessageBreak
      You wrote: "\the\xargs@toksa".\MessageBreak
      I can't understand this and I'm going to ignore it.}%
  \fi}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\xargs@add@args}
% Now our goal is to build two lists from our up to nine actions macros. The
% first is the coma-separated list of actions allready discussed. The second
% is the parameter text for use  in the definition on the internal macro, for
% example |[#1]#2[#3]|. The next macro takes the content of a
% \cs{xargs@action@X} macro for argument and adds the corresponding items to
% this lists. It checks if the first token of its parameter is \cs{xargs@testopt}
% in order to know if the |#n| has to be enclosed in square brackets.
%    \begin{macrocode}
\newcommand\xargs@add@args[1]{%
  \xargs@toksa\expandafter{\the\xargs@toksa #1,}%
  \expandafter
  \ifx\@car#1\@nil\xargs@put@arg
    \xargs@toksb\expandafter\expandafter\expandafter{%
      \the\expandafter\xargs@toksb\expandafter##\the\@tempcnta}%
  \else
    \xargs@toksb\expandafter\expandafter\expandafter{%
      \the\expandafter\xargs@toksb\expandafter
      [\expandafter##\the\@tempcnta]}%
  \fi}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\xargs@process@keys}
% Here comes the main input processing macro, which prepares the information needed
% to define the final macro, and expands it to the defining macro.
%    \begin{macrocode}
\@ifdefinable\xargs@process@keys{%
  \long\def\xargs@process@keys#1[#2]{%
%    \end{macrocode}
% Some initialisations. We work inside a group so that the default values for
% the \cs{xargs@action@X} macros and the \cs{xargs@XXXopt@} be automatically
% restored for the next time.
%    \begin{macrocode}
  \begingroup
  \xargs@setkeys{#2}%
  \xargs@toksa{}\xargs@toksb{}%
%    \end{macrocode}
% Then the main loop actually builds up the two lists in the correct order.
%    \begin{macrocode}
  \@tempcnta0
  \@whilenum \xargs@max>\@tempcnta \do{%
    \advance\@tempcnta1
    \expandafter\expandafter\expandafter\xargs@add@args
    \expandafter\expandafter\expandafter{%
      \csname xargs@action@\the\@tempcnta\endcsname}}%
%    \end{macrocode}
% Now we need to  address a special case: If only the first argument is
% optional, we use \LaTeXe's standard \cs{newcommand}, and we dont need an
% actions list like the one just build, but only the default value for the first
% argument. In this case, we extract this value from \cs{xargs@action@1} by
% expanding it three times with a modified \cs{xargs@testopt}.
%    \begin{macrocode}
  \ifxargs@otheropt@ \else
    \ifxargs@firstopt@
      \let\xargs@test@opt\@firstofone
      \xargs@toksa\expandafter\expandafter\expandafter
      \expandafter\expandafter\expandafter\expandafter{%
        \csname xargs@action@1\endcsname}
    \fi
  \fi
%    \end{macrocode}
% Finally expand the stuff to the next macro. 
%    \begin{macrocode}
  \expandafter\expandafter\expandafter\xargs@choose@def
  \expandafter\expandafter\expandafter#1%
  \expandafter\expandafter\the\xargs@max
  \expandafter{\the\xargs@toksa}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\xargs@choose@def}
% It's time to make a choice about the method used to define the macro,
% depending of the number and place of its optional arguments. Two cases are
% handled by \LaTeX, the last is \xargs{} non-trivial case. Note the
% \cs{expandafter}\cs{endgroup} trick which allows us to use the \cs{if}s
% outside the group but have them restored to false just after.
%    \begin{macrocode}
\newcommand\xargs@choose@def[4]{%
  \expandafter\expandafter\expandafter
  \endgroup
  \ifxargs@otheropt@
    \expandafter\xargs@def@cmd\expandafter#1\expandafter{%
      \the\xargs@toksb}{#3}{#4}%
  \else
    \ifxargs@firstopt@
      \@xargdef#1[#2][#3]{#4}%
    \else
      \@argdef#1[#2]{#4}%
    \fi
  \fi}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\xargs@def@cmd}
% This is \xargs{} variant of \cs{xargdef}. The only thing not yet
% expanded is the internal macro name, for which we use all the
% \cs{expandafter}s.
%    \begin{macrocode}
\newcommand\xargs@def@cmd[4]{%
  \@ifdefinable#1{%
    \expandafter\def\expandafter#1\expandafter{%
      \expandafter\@protected@testopt@xargs
      \expandafter#1\csname \string#1\endcsname{#3}}%
    \l@ngrel@x\expandafter\def\csname \string#1\endcsname#2{#4}}}
%    \end{macrocode}
% \end{macro}
% \bigskip
% \begin{macro}{\newcommandx}
% \begin{macro}{\xargs@newc}
% All the (tricky?) internal macros are ready. It's time to define the user
% commands, beginning with \cs{newcommandx}. Like it's standard version, it
% just checks the star and call the next macro wich grabs the number of
% arguments.
%    \begin{macrocode}
\newcommand\newcommandx{%
  \@star@or@long\xargs@newc}
%    \end{macrocode}
%    \begin{macrocode}
\newcommand*\xargs@newc[1]{%
  \@testopt{\xargs@set@max{#1}}{0}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\xargs@set@max}
% Set the value of \cs{xargs@max}. If no optional arguments description
% follows, simply call \cs{argdef} because all the complicated stuff is useless
% here.
%    \begin{macrocode}
\@ifdefinable\xargs@set@max{%
  \def\xargs@set@max#1[#2]{%
    \kernel@ifnextchar[%]
      {\xargs@max=#2 \xargs@check@max{#1}}%
      {\@argdef#1[#2]}}}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\xargs@check@max}
% To avoid possible problems later, check right now that \cs{xargs@max} value is
% valid. If not, warn the user and treat this value as zero. Then begin the key
% processing.
%    \begin{macrocode}
\newcommand\xargs@check@max{%
  \ifcase\xargs@max \or\or\or\or\or\or\or\or\or\else
    \PackageError{xargs}{Illegal number, treated as zero}{The total
      number of arguments must be in the 0..9 range.\MessageBreak
      Since your value is illegal, i'm going to use 0 instead.}
    \xargs@max0
  \fi
  \xargs@process@keys}
%    \end{macrocode}
% \end{macro}
% The other macros (\cs{renewcommand} etc) closely resemble their kernel
% couterpart, since they are mostly wrappers around some call to
% \cs{xargs@newc}. There is however an exception, \cs{CheckCommand}, which I
% will treat first. Here my way differs from the kernel's one, since current
% implemetation of \cs{CheckCommand} in the kernel suffers from two bugs (see
% PR/3971).
% \begin{macro}{\CheckCommandx}
% We begin as usual detecting the possible star.
%    \begin{macrocode}
\@ifdefinable\CheckCommandx{%
  \def\CheckCommandx{%
    \@star@or@long\xargs@CheckC}}
\@onlypreamble\CheckCommandx
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\xargs@CheckC}
% \begin{macro}{\xargs@check@a}
% \begin{macro}{\xargs@check@b}
% First, we don't use the |#2#{| trick from the kernel, since it can fail if there
% are braces in the default values. Instead, we follow the argument grabing
% method used for \cs{new@environment}, ie calling \cs{kernel@ifnextchar}
% explicitly.
%    \begin{macrocode}
\@ifdefinable\xargs@CheckC{%
  \def\xargs@CheckC#1{%
    \@testopt{\xargs@check@a#1}0}}
\@onlypreamble\xargs@CheckC
%    \end{macrocode}
%    \begin{macrocode}
\@ifdefinable\xargs@check@a{%
  \def\xargs@check@a#1[#2]{%
    \kernel@ifnextchar[%]
      {\xargs@check@b#1[#2]}%
      {\xargs@check@c#1{[#2]}}}}
\@onlypreamble\xargs@check@a
%    \end{macrocode}
%    \begin{macrocode}
\@ifdefinable\xargs@chech@b{%
  \def\xargs@check@b#1[#2][#3]{%
    \xargs@check@c{#1}{[#2][{#3}]}}}
\@onlypreamble\xargs@check@b
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\xargs@CheckC}
% Here come the major difference with the kernel version. If |\\reserved@a| is
% defined, we not only check that it is equal to |\\foo| (assuming \cs{foo} is
% the macro being tested), we also check that \cs{foo} makes something sensible
% by calling \cs{xargs@check@d}.
%    \begin{macrocode}
\newcommand\xargs@check@c[3]{%
  \xargs@toksa{#1}%
  \expandafter\let\csname\string\reserved@a\endcsname\relax
  \xargs@renewc\reserved@a#2{#3}%
  \@ifundefined{\string\reserved@a}{%
    \ifx#1\reserved@a \else
      \xargs@check@complain
    \fi
    }{%
    \expandafter
    \ifx\csname\string#1\expandafter\endcsname
        \csname\string\reserved@a\endcsname
      \begingroup\escapechar 92
      \xargs@check@d
    \else
      \xargs@check@complain
    \fi}}
\@onlypreamble\xargs@check@c
%    \end{macrocode}
% \end{macro}
% So, what do we want \cs{foo} to do? If |\\foo| is defined, \cs{foo} should
% begin with one of the followings:
% \begin{quote}
% |\@protected@testopt \foo \\foo| \\
% |\@protected@testopt@xargs \foo \\foo|
% \end{quote}
% Since I'm to lazy to really check this, the \cs{xargs@check@d} macro only
% checks if the \cs{meaning} of \cs{foo} begins with \cs{@protected@test@opt}
% (without a space after it). It does this using a macro with delimited
% argument. Here are preliminaries to this definition: We need to have this
% string in \cs{catcode} 12 tokens.
%    \begin{macrocode}
\def\xargs@temp{\@protected@testopt}
{ \escapechar 92
  \global\xargs@toksa\expandafter{\meaning\xargs@temp}}
\def\xargs@temp#1 \@nil{\def\xargs@temp{#1}}
\expandafter\xargs@temp\the\xargs@toksa\@nil
%    \end{macrocode}
% \begin{macro}{\xargs@check@d}
% \begin{macro}{\xargs@check@e}
% Now, \cs{xargs@check@c} just pass the \cs{meaning} of the command \cs{foo} being
% checked to the allready mentionned macro with delimited arguments, which will
% check if its first argument is empty (ie, if \cs{foo}'s \cs{meaning} starts
% with what we want) and complain otherwise.
%    \begin{macrocode}
\@ifdefinable\xargs@check@d{%
  \expandafter\newcommand\expandafter\xargs@check@d\expandafter{%
    \expandafter\expandafter\expandafter\xargs@check@e
    \expandafter\meaning\expandafter\reserved@a\xargs@temp\@nil}}
\@onlypreamble\xargs@check@d
%    \end{macrocode}
%    \begin{macrocode}
\@ifdefinable\xargs@check@e{%
  \expandafter\def\expandafter\xargs@check@e
  \expandafter#\expandafter1\xargs@temp#2\@nil{%
    \endgroup
    \ifx\empty#1\empty \else
      \xargs@check@complain
    \fi}}
\@onlypreamble\xargs@check@e
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\xargs@check@complain}
% The complaining macro uses the name saved by \cs{xargs@check@c} in
% \cs{xargs@toksa} in order to complain about the correct macro.
%    \begin{macrocode}
\newcommand\xargs@check@complain{%
  \PackageWarningNoLine{xargs}{Command \the\xargs@toksa has changed.
    \MessageBreak Check if current package is valid}}
\@onlypreamble\xargs@check@complain
%    \end{macrocode}
% \end{macro}
% \bigskip
%
% From now on, there is absolutely nothing to comment on, since the next macros
% are mainly wrappers around \cs{xargs@newc}, just as kernel's ones are wrappers
% around \cs{new@command}. So the code below is only copy/paste with
% search\&replace from the kernel code.
%
% \begin{macro}{\renewcommandx}
% \begin{macro}{\xargs@renewc}
% The \xargs{}version of \cs{renewcommand}, and related internal macro.
%    \begin{macrocode}
\newcommand\renewcommandx{%
  \@star@or@long\xargs@renewc}
%    \end{macrocode}
%    \begin{macrocode}
\newcommand*\xargs@renewc[1]{%
  \begingroup\escapechar\m@ne
    \xdef\@gtempa{{\string#1}}%
  \endgroup
  \expandafter\@ifundefined\@gtempa{%
    \PackageError{xargs}{\noexpand#1undefined}{%
      Try typing \space <return> \space to proceed.\MessageBreak
      If that doesn't work, type \space X <return> \space to quit.}}%
    \relax
  \let\@ifdefinable\@rc@ifdefinable
  \xargs@newc#1}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\providecommandx}
% \begin{macro}{\xargs@providec}
% The \xargs{}version of \cs{providecommand}, and related internal macro.
%    \begin{macrocode}
\newcommand\providecommandx{%
  \@star@or@long\xargs@providec}
%    \end{macrocode}
%    \begin{macrocode}
\newcommand*\xargs@providec[1]{%
  \begingroup\escapechar\m@ne
    \xdef\@gtempa{{\string#1}}%
  \endgroup
  \expandafter\@ifundefined\@gtempa
    {\def\reserved@a{\xargs@newc#1}}%
    {\def\reserved@a{\renew@command\reserved@a}}%
  \reserved@a}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\DeclareRobustCommandx}
% \begin{macro}{\xargs@DRC}
% The \xargs{}version of \cs{DeclareRobustCommand}, and related internal macro.
%    \begin{macrocode}
\newcommand\DeclareRobustCcommandx{%
  \@star@or@long\xargs@DRC}
%    \end{macrocode}
%    \begin{macrocode}
\newcommand*\xargs@DRC[1]{%
  \ifx#1\@undefined\else\ifx#1\relax\else
    \PackageInfo{xargs}{Redefining \string#1}%
  \fi\fi
  \edef\reserved@a{\string#1}%
  \def\reserved@b{#1}%
  \edef\reserved@b{\expandafter\strip@prefix\meaning\reserved@b}%
  \edef#1{%
    \ifx\reserved@a\reserved@b
      \noexpand\x@protect
      \noexpand#1%
    \fi
      \noexpand\protect
      \expandafter\noexpand\csname
      \expandafter\@gobble\string#1 \endcsname}%
  \let\@ifdefinable\@rc@ifdefinable
  \expandafter\xargs@newc\csname
  \expandafter\@gobble\string#1 \endcsname}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \begin{macro}{\newenvironment}
% \begin{macro}{\xargs@newenv}
% \begin{macro}{\xargs@newenva}
% \begin{macro}{\xargs@newenvb}
% \begin{macro}{\xargs@new@env}
% The \xargs{}version of \cs{newenvironment}, and related internal
% macros.
%    \begin{macrocode}
\newcommand\newenvironmentx{%
  \@star@or@long\xargs@newenv}
%    \end{macrocode}
%    \begin{macrocode}
\newcommand*\xargs@newenv[1]{%
  \@testopt{\xargs@newenva#1}0}
%    \end{macrocode}
%    \begin{macrocode}
\@ifdefinable\xargs@newenva{%
  \def\xargs@newenva#1[#2]{%
    \kernel@ifnextchar[%]
      {\xargs@newenvb#1[#2]}%
      {\xargs@new@env{#1}{[#2]}}}}
%    \end{macrocode}
%    \begin{macrocode}
\@ifdefinable\xargs@newenvb{%
  \def\xargs@newenvb#1[#2][#3]{%
    \xargs@new@env{#1}{[#2][{#3}]}}}
%    \end{macrocode}
%    \begin{macrocode}
\newcommand\xargs@new@env[4]{%
  \@ifundefined{#1}{%
    \expandafter\let\csname#1\expandafter\endcsname
    \csname end#1\endcsname}%
    \relax
  \expandafter\xargs@newc
    \csname #1\endcsname#2{#3}%
  \l@ngrel@x\expandafter\def\csname end#1\endcsname{#4}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \begin{macro}{\renewenvironment}
% \begin{macro}{\xargs@renewenv}
% The \xargs{}version of \cs{renewenvironment}, and related internal
% macro.
%    \begin{macrocode}
\newcommand\renewenvironmentx{%
  \@star@or@long\xargs@renewenv}
%    \end{macrocode}
%    \begin{macrocode}
\newcommand*\xargs@renewenv[1]{%
  \@ifundefined{#1}{%
    \PackageError{xargs}{\noexpand#1undefined}{%
      Try typing \space <return> \space to proceed.\MessageBreak
      If that doesn't work, type \space X <return> \space to quit.}}%
    \relax
  \expandafter\let\csname#1\endcsname\relax
  \expandafter\let\csname end#1\endcsname\relax
  \xargs@newenv{#1}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \bigskip
% \begin{center}\Large
% That's all folks!\\
% Happy \TeX ing!
% \end{center}
%
% \Finale