daily pastebin goal
44%
SHARE
TWEET

Untitled

a guest May 16th, 2018 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mycmd-[options1]{action1}
  2. mycmd+[options2]{action2}
  3. mycmd/[options3]{action3}
  4.    
  5. documentclass{article}
  6. newcommandmycmd[1]{defmycase{#1}mycmdaux}
  7. newcommandmycmdaux[2][]{Case is ``mycase'', options are ``#1'' and action is ``#2''}
  8.  
  9. begin{document}
  10. mycmd-[options1]{action1}
  11.  
  12. mycmd+[options2]{action2}
  13.  
  14. mycmd/[options3]{action3}
  15. end{document}
  16.    
  17. documentclass{article}
  18.  
  19. begingroup
  20. makeatletter
  21. @firstofone{%
  22.   endgroup
  23.   %%-------------------------------------------------------------------------
  24.   %% Check whether argument is empty:
  25.   %%.........................................................................
  26.   %% @CheckWhetherNull{<Argument which is to be checked>}%
  27.   %%                   {<Tokens to be delivered in case that
  28.   %%                     argument which is to be checked is empty>}%
  29.   %%                   {<Tokens to be delivered in case that
  30.   %%                     argument which is to be checked is not empty>}%
  31.   newcommand@CheckWhetherNull[1]{%
  32.     expandafter@secondoftwostring{expandafter@secondoftwo
  33.     expandafter{expandafter{string#1}expandafter@secondoftwo
  34.     string}expandafter@firstoftwoexpandafter{expandafter
  35.     @firstoftwoexpandafter@secondoftwoexpandafter}string
  36.     }@firstoftwo
  37.   }%
  38.   %%-------------------------------------------------------------------------
  39.   %% Check whether argument contains no exclamation-mark on top-brace-level:
  40.   %%.........................................................................
  41.   %% @CheckWhetherNoExclamationMark{<Argument which is to be checked>}%
  42.   %%                   {<Tokens to be delivered in case that
  43.   %%                     argument which is to be checked does not contain !>}%
  44.   %%                   {<Tokens to be delivered in case that
  45.   %%                     argument which is to be checked does contain !>}%
  46.   newcommand@RemoveToExclamationMark{}%
  47.   longdef@RemoveToExclamationMark#1!{}%
  48.   newcommand@CheckWhetherNoExclamationMark[1]{%
  49.     expandafter@CheckWhetherNullexpandafter{@RemoveToExclamationMark#1!}%
  50.   }%
  51.   %%-------------------------------------------------------------------------
  52.   %% Fork depending on minus, plus, slash, something else.
  53.   %%.........................................................................
  54.   %% (First via kernek@ifnextchar check whether the next token is an
  55.   %%  opening brace.
  56.   %%  If it is, we know that it is neither a minus nor a plus nor a slash.
  57.   %%  If it is not, it can be processed as an undelimited macro-argument
  58.   %%  where under normal catcode-rĂ©gime brace-stripping cannot occur, thus
  59.   %%  in this ase use mycmd@furthercheck for checking for
  60.   %%  minus/plus/slash/something else.
  61.   %%  Make the command robust as due to the not fully expandable
  62.   %%  kernel@ifnextchar it should not be carried out in
  63.   %%  pure-expansion-contexts.)
  64.   newcommandmycmd{}%
  65.   DeclareRobustCommandmycmd{%
  66.     kernel@ifnextcharbgroup
  67.                       {mycmd@else}%<-Next token is opening brace or bgroup,
  68.                                    %  thus something other than minus/plus/slash.
  69.                       {mycmd@furthercheck}%<-Check for minus/plus/slash.
  70.   }%
  71.   %
  72.   newcommand@mycmdfork{}%
  73.   longdef@mycmdfork#1!!-!+!/!#2#3!!!!{#2}%
  74.   %
  75.   newcommandmycmd@furthercheck[1]{%
  76.     @CheckWhetherNoExclamationMark{#1}{%
  77.       @mycmdfork
  78.       !#1!-!+!/!{mycmd@else#1}%<-Else #1 empty (actually this can't happen.)
  79.       !!#1!+!/!{mycmd@minus}%<-minus
  80.       !!-!#1!/!{mycmd@plus}%<-plus
  81.       !!-!+!#1!{mycmd@slash}%<-slash
  82.       !!-!+!/!{mycmd@else#1}%<-ELSE no exclamation-mark
  83.       !!!!%
  84.     }{mycmd@else#1}%<-ELSE Exclamation-mark
  85.   }%
  86.   newcommandmycmd@minus[2][Optional argument's default at minus]{%
  87.     Case minus-sign:\%
  88.     Optional argument is: texttt{#1}\%
  89.     Mandatory argument is: texttt{#2}%
  90.   }%
  91.   newcommandmycmd@plus[2][Optional argument's default at plus]{%
  92.     Case plus-sign:\%
  93.     Optional argument is: texttt{#1}\%
  94.     Mandatory argument is: texttt{#2}%
  95.   }%
  96.   newcommandmycmd@slash[2][Optional argument's default at slash]{%
  97.     Case slash-sign:\%
  98.     Optional argument is: texttt{#1}\%
  99.     Mandatory argument is: texttt{#2}%
  100.   }%
  101.   newcommandmycmd@else[2][Optional argument's default at other cases]{%
  102.     Some other case:\
  103.     Optional argument is: texttt{#1}\%
  104.     Mandatory argument is: texttt{#2}%
  105.   }%
  106. }%
  107.  
  108. pagestyle{empty}
  109.  
  110. begin{document}
  111.  
  112. vspace*{-1.33in}%
  113. parskip=baselineskip
  114. parindent=0pt
  115. enlargethispage{1in}%
  116. footnotesize
  117.  
  118. verb|mycmd X| yields:\
  119. mycmd X
  120.  
  121. verb|mycmd!| yields:\
  122. mycmd!
  123.  
  124. verb|mycmd{!}| yields:\
  125. mycmd{!}
  126.  
  127. verb|mycmd{-}| yields:\
  128. mycmd{-}
  129.  
  130. verb|mycmd{+}| yields:\
  131. mycmd{+}
  132.  
  133. verb|mycmd{/}| yields:\
  134. mycmd{/}
  135.  
  136. verb|mycmd{Some other case without given optional argument}| yields:\
  137. mycmd{Some other case without given optional argument}
  138.  
  139. verb|mycmd[Given optional argument]{Some other case with given optional argument}| yields:\
  140. mycmd[Given optional argument]{Some other case with given optional argument}
  141.  
  142. verb|mycmd+{Plus case without given optional argument}| yields:\
  143. mycmd+{Plus case without given optional argument}
  144.  
  145. verb|mycmd+[Given optional argument]{Plus case with given optional argument}| yields:\
  146. mycmd+[Given optional argument]{Plus case with given optional argument}
  147.  
  148. verb|mycmd-{Minus case without given optional argument}| yields:\
  149. mycmd-{Minus case without given optional argument}
  150.  
  151. verb|mycmd-[Given optional argument]{Minus case with given optional argument}| yields:\
  152. mycmd-[Given optional argument]{Minus case with given optional argument}
  153.  
  154. verb|mycmd/{Slash case without given optional argument}| yields:\
  155. mycmd/{Slash case without given optional argument}
  156.  
  157. verb|mycmd/[Given optional argument]{Slash case with given optional argument}| yields:\
  158. mycmd/[Given optional argument]{Slash case with given optional argument}
  159.  
  160. end{document}
RAW Paste Data
Top