Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- mycmd-[options1]{action1}
- mycmd+[options2]{action2}
- mycmd/[options3]{action3}
- documentclass{article}
- newcommandmycmd[1]{defmycase{#1}mycmdaux}
- newcommandmycmdaux[2][]{Case is ``mycase'', options are ``#1'' and action is ``#2''}
- begin{document}
- mycmd-[options1]{action1}
- mycmd+[options2]{action2}
- mycmd/[options3]{action3}
- end{document}
- documentclass{article}
- begingroup
- makeatletter
- @firstofone{%
- endgroup
- %%-------------------------------------------------------------------------
- %% Check whether argument is empty:
- %%.........................................................................
- %% @CheckWhetherNull{<Argument which is to be checked>}%
- %% {<Tokens to be delivered in case that
- %% argument which is to be checked is empty>}%
- %% {<Tokens to be delivered in case that
- %% argument which is to be checked is not empty>}%
- newcommand@CheckWhetherNull[1]{%
- expandafter@secondoftwostring{expandafter@secondoftwo
- expandafter{expandafter{string#1}expandafter@secondoftwo
- string}expandafter@firstoftwoexpandafter{expandafter
- @firstoftwoexpandafter@secondoftwoexpandafter}string
- }@firstoftwo
- }%
- %%-------------------------------------------------------------------------
- %% Check whether argument contains no exclamation-mark on top-brace-level:
- %%.........................................................................
- %% @CheckWhetherNoExclamationMark{<Argument which is to be checked>}%
- %% {<Tokens to be delivered in case that
- %% argument which is to be checked does not contain !>}%
- %% {<Tokens to be delivered in case that
- %% argument which is to be checked does contain !>}%
- newcommand@RemoveToExclamationMark{}%
- longdef@RemoveToExclamationMark#1!{}%
- newcommand@CheckWhetherNoExclamationMark[1]{%
- expandafter@CheckWhetherNullexpandafter{@RemoveToExclamationMark#1!}%
- }%
- %%-------------------------------------------------------------------------
- %% Fork depending on minus, plus, slash, something else.
- %%.........................................................................
- %% (First via kernek@ifnextchar check whether the next token is an
- %% opening brace.
- %% If it is, we know that it is neither a minus nor a plus nor a slash.
- %% If it is not, it can be processed as an undelimited macro-argument
- %% where under normal catcode-régime brace-stripping cannot occur, thus
- %% in this ase use mycmd@furthercheck for checking for
- %% minus/plus/slash/something else.
- %% Make the command robust as due to the not fully expandable
- %% kernel@ifnextchar it should not be carried out in
- %% pure-expansion-contexts.)
- newcommandmycmd{}%
- DeclareRobustCommandmycmd{%
- kernel@ifnextcharbgroup
- {mycmd@else}%<-Next token is opening brace or bgroup,
- % thus something other than minus/plus/slash.
- {mycmd@furthercheck}%<-Check for minus/plus/slash.
- }%
- %
- newcommand@mycmdfork{}%
- longdef@mycmdfork#1!!-!+!/!#2#3!!!!{#2}%
- %
- newcommandmycmd@furthercheck[1]{%
- @CheckWhetherNoExclamationMark{#1}{%
- @mycmdfork
- !#1!-!+!/!{mycmd@else#1}%<-Else #1 empty (actually this can't happen.)
- !!#1!+!/!{mycmd@minus}%<-minus
- !!-!#1!/!{mycmd@plus}%<-plus
- !!-!+!#1!{mycmd@slash}%<-slash
- !!-!+!/!{mycmd@else#1}%<-ELSE no exclamation-mark
- !!!!%
- }{mycmd@else#1}%<-ELSE Exclamation-mark
- }%
- newcommandmycmd@minus[2][Optional argument's default at minus]{%
- Case minus-sign:\%
- Optional argument is: texttt{#1}\%
- Mandatory argument is: texttt{#2}%
- }%
- newcommandmycmd@plus[2][Optional argument's default at plus]{%
- Case plus-sign:\%
- Optional argument is: texttt{#1}\%
- Mandatory argument is: texttt{#2}%
- }%
- newcommandmycmd@slash[2][Optional argument's default at slash]{%
- Case slash-sign:\%
- Optional argument is: texttt{#1}\%
- Mandatory argument is: texttt{#2}%
- }%
- newcommandmycmd@else[2][Optional argument's default at other cases]{%
- Some other case:\
- Optional argument is: texttt{#1}\%
- Mandatory argument is: texttt{#2}%
- }%
- }%
- pagestyle{empty}
- begin{document}
- vspace*{-1.33in}%
- parskip=baselineskip
- parindent=0pt
- enlargethispage{1in}%
- footnotesize
- verb|mycmd X| yields:\
- mycmd X
- verb|mycmd!| yields:\
- mycmd!
- verb|mycmd{!}| yields:\
- mycmd{!}
- verb|mycmd{-}| yields:\
- mycmd{-}
- verb|mycmd{+}| yields:\
- mycmd{+}
- verb|mycmd{/}| yields:\
- mycmd{/}
- verb|mycmd{Some other case without given optional argument}| yields:\
- mycmd{Some other case without given optional argument}
- verb|mycmd[Given optional argument]{Some other case with given optional argument}| yields:\
- mycmd[Given optional argument]{Some other case with given optional argument}
- verb|mycmd+{Plus case without given optional argument}| yields:\
- mycmd+{Plus case without given optional argument}
- verb|mycmd+[Given optional argument]{Plus case with given optional argument}| yields:\
- mycmd+[Given optional argument]{Plus case with given optional argument}
- verb|mycmd-{Minus case without given optional argument}| yields:\
- mycmd-{Minus case without given optional argument}
- verb|mycmd-[Given optional argument]{Minus case with given optional argument}| yields:\
- mycmd-[Given optional argument]{Minus case with given optional argument}
- verb|mycmd/{Slash case without given optional argument}| yields:\
- mycmd/{Slash case without given optional argument}
- verb|mycmd/[Given optional argument]{Slash case with given optional argument}| yields:\
- mycmd/[Given optional argument]{Slash case with given optional argument}
- end{document}
Add Comment
Please, Sign In to add comment