summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/ltxmisc/ifmtarg.sty
blob: 1c489af34c2e13d2013e15ddcd264db21e27e465 (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
% ifmtarg.sty
%
% Provides an if-then-else command for an empty macro argument
% (empty = zero or more spaces only)
% Use as \@ifmtarg{arg1}{Code for arg1 empty}{Code for arg1 not empty}
%
% author: Peter Wilson (CUA)
%         (now at peter.r.wilson@boeing.com)
% Copyright Peter Wilson, 1996
% Copyright Peter Wilson and Donald Arseneau, 2000
% Released under the LaTeX Project Public License
%
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{ifmtarg}[2000/03/24 v1.2 check for an empty argument]

%% Commands by Donald Arseneau
\begingroup
\catcode`\Q=3
\long\gdef\@ifmtarg#1{\@xifmtarg#1QQ\@secondoftwo\@firstoftwo\@nil}
\long\gdef\@xifmtarg#1#2Q#3#4#5\@nil{#4}
\long\gdef\@ifnotmtarg#1{\@xifmtarg#1QQ\@firstofone\@gobble\@nil}
\endgroup

\endinput

%
% The \@ifmtarg command takes 3 arguments and \@ifnotmtarg takes 2 arguments.
% \@ifnotmtarg is slightly more efficient when code is only required
% for a non-empty argument.
%
% Example usages:
% \newcommand{\isempty}{1]{%
%   \@ifmtarg{#1}{\typeout{YES}}{\typeout{NO}}}
%
% \isempty{}    -> YES
% \isempty{   } -> YES
% \isempty{E}   -> NO
% \isempty{ E } -> NO
%
% \newcommand{\isnotempty}[1]{%
%    \@ifnotmtarg{#1}{\typeout{YES}}}
%
% \isnotempty{}    -> 
% \isnotempty{   } -> 
% \isnotempty{E}   -> YES
% \isnotempty{ E } -> YES
%
%     In an Email to me on 13 March 2000, Donald Arseneau pointed out some
% failings with my original definition of the \@ifmtarg command:
% \newcommand{\@ifmtarg}[3]{%
%   \edef\@mtarg{\zap@space#1 \@empty}%  
%   \ifx\@empty\@mtarg\relax #2\else #3\fi}
%
% It works most of the time correctly but Donald showed that it can 
% give unexpected results 
% under conditions that I had not thought of. He suggested the coding 
% that now appears in the package above for the \@ifmtarg and 
% \@ifnotmtarg commands. For a discussion on detecting empty arguments 
% see CTAN/info/aro-bend/answer.002
%
% Peter W.
%