% xparse-test.tex \RequirePackage{xparse} \typeout{Testing the complicated makebox setup} \typeout{*****************************} \typeout{* look at dvi output for this part} \typeout{*****************************} \IgnoreWhiteSpace \DeclareDocumentCommand \makebox { C{\NoValue} o O{c} m} { \IfNoValueTF{#1} { \ltx@maketextbox{#2}{#3}{#4}\mbox } { \ltx@makepicbox #1 {#2}{#4}\@firstofone } } \DeclareDocumentCommand \framebox { C{\NoValue} o O{c} m} { \IfNoValueTF{#1} { \ltx@maketextbox{#2}{#3}{#4}\fbox } { \ltx@makepicbox #1 {#2}{#4}\frame } } \def\ltx@maketextbox#1#2#3#4 { \IfNoValueTF{#1} {#4{#3}} { \leavevmode \@begin@tempboxa\hbox{#3} \setlength\@tempdima{#1} \ifx#4\fbox \setbox\@tempboxa\hb@xt@\@tempdima {\kern\fboxsep\csname bm@#2\endcsname\kern\fboxsep} \@frameb@x{\kern-\fboxrule} \else \hb@xt@\@tempdima{\csname bm@#2\endcsname} \fi \@end@tempboxa } } \def\ltx@makepicbox#1#2#3#4#5 { #5{ \vbox to#2\unitlength {\let\mb@b\vss \let\mb@l\hss\let\mb@r\hss \let\mb@t\vss \IfNoValueF{#3} { \@tfor\reserved@a :=#3\do{ \if s\reserved@a \let\mb@l\relax\let\mb@r\relax \else \expandafter\let\csname mb@\reserved@a\endcsname\relax \fi}% } \mb@t \hb@xt@ #1\unitlength{\mb@l #4\mb@r} \mb@b \kern\z@} } } \documentclass{minimal} \begin{document} \thicklines \makebox{A} \makebox(1,2){B} \makebox(0,0)[lt]{C} \makebox[20pt]{D} \makebox[30pt][r]{E} \vspace{1cm} \framebox{A} \framebox(1,2){B} \framebox(0,0)[lt]{C} \framebox[20pt]{D} \framebox[30pt][r]{E} \typeout{Testing optional coordinates} \DeclareDocumentCommand \foo { m C{{0}{0}} m } { \typeout{1:#1} \typeout{2:#2} \typeout{3:#3} } \show\foo \foo A (1,2) B \foo A B \typeout{Testing mandatory coordinates (gives error on second examples)} \DeclareDocumentCommand \foo { m c m } { \typeout{1:#1} \typeout{2:#2} \typeout{3:#3} } \show\foo \foo A (1,2) B \foo A B \typeout{Testing normal optional arguments} \DeclareDocumentCommand \foo { mmmm o mm o } { \typeout{1:#1} \typeout{2:#2} \typeout{3:#3} \typeout{4:#4} \typeout{5:#5} \typeout{6:#6} \typeout{7:#7} \typeout{8:#8} } \foo 1234[5]67[8] \foo 123467 \show\foo \expandafter\show\csname\string\foo\endcsname \typeout{Testing optional arguments with default} \DeclareDocumentCommand \baz { O{?}mmm o mm m } { \typeout{1:#1} \typeout{2:#2} \typeout{3:#3} \typeout{4:#4} \typeout{5:#5} \typeout{6:#6} \typeout{7:#7} \typeout{8:#8} } \show\baz \expandafter\show\csname\string\baz\endcsname \baz [1]234[5]678 \makeatletter\showthe\toks@ \baz 234678 \makeatletter\showthe\toks@ %\tracingall\tracingassigns=1 \DeclareDocumentCommand \bar { mmmm mmmm m} { \typeout{1:#1} \typeout{2:#2} \typeout{3:#3} \typeout{4:#4} \typeout{5:#5} \typeout{6:#6} \typeout{7:#7} \typeout{8:#8} \typeout{9:#9} } \show\bar \expandafter\show\csname\string\bar\endcsname \bar 123456789 \makeatletter\showthe\toks@ \DeclareDocumentCommand\chapter{soom} {\typeout{a{#1}^^Jb{#2}^^Jc{#3}^^Jd{#4}^^Je}} \show\chapter \expandafter\show\csname\string\chapter\endcsname \typeout{1:} \chapter*[xxx][yyy]{zzz} \typeout{2:} \chapter[xxx][yyy]{zzz} \typeout{3:} \chapter*[xxx]{zzz} \typeout{4:} \typeout{\chapter*[xxx][yyy]{zzz}} \typeout{Testing environments with args passed to end env} \typeout{****************} \typeout{* This works only if xparse is compiled with `perhaps' docstrip guard} \typeout{* This part of the code is not activated by default!} \typeout{****************} \DeclareDocumentCommand\chapter{soom} {\typeout{a{#1}^^Jb{#2}^^Jc{#3}^^Jd{#4}^^Je}} \DeclareDocumentEnvironment{hello}{ooo} {\typeout{B1(#1)^^JB2(#2)^^JB3(#3)^^J}} {\typeout{E1(#1)^^JE2(#2)^^JE3(#3)^^J}} \show\hello \expandafter\show\csname\string\hello\endcsname \show\endhello \expandafter\show\csname end\string\\hello\endcsname \begin{hello}[abc][aabbcc] \typeout{body} \typeout{5:} \chapter[xxx][yyy]{zzz} \end{hello} \begin{hello}[1] \typeout{outer body} \hello [2] \typeout{inner body} \endhello \end{hello} \stop