diff options
Diffstat (limited to 'macros/latex/contrib/songbook/conditionals.sty')
-rw-r--r-- | macros/latex/contrib/songbook/conditionals.sty | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/macros/latex/contrib/songbook/conditionals.sty b/macros/latex/contrib/songbook/conditionals.sty new file mode 100644 index 0000000000..929b0699a8 --- /dev/null +++ b/macros/latex/contrib/songbook/conditionals.sty @@ -0,0 +1,88 @@ +% rcsid = @(#)$Id: conditionals.sty,v 1.5 2010-03-31 01:04:16 rathc Exp $ +%==========Conditionals by Donald Arseneau <asnd@triumf.ca>=========== +% (as of 2002/01/17) +% Donald Arseneau asserts no claim to copyright of the contents of this +% conditionals.sty file, and it may be freely used as in the public +% domain. +% +% \if\blank{ } --- checks if parameter is blank (Spaces count as blank) +% \if\given{ } --- checks if parameter is not blank: like \if\blank{}...\else +% \if\nil{ } --- checks if parameter is null (spaces are NOT null) +% +{\catcode`\!=8 % funny catcode so ! will be a delimiter + \catcode`\Q=3 % funny catcode so Q will be a delimiter +\long\gdef\given#1{88\fi\Ifbl@nk#1QQQ\empty!} +\long\gdef\blank#1{88\fi\Ifbl@nk#1QQ..!}% if null or spaces +\long\gdef\nil#1{\IfN@Ught#1* {#1}!}% if null +\long\gdef\IfN@Ught#1 #2!{\blank{#2}} +\long\gdef\Ifbl@nk#1#2Q#3!{\ifx#3}% same as above +} +\endinput +%===================================================================== +% COMMENTARY: Donald Arseneau's commentary on these macros. +%===================================================================== +% There are many ways to check if a field is blank. The clearest is: +% +% \long\def\@tempa{#1}\ifx\@tempa\@empty ... \else ... \fi +% +% (use \empty for plain TeX) +% +% There are a few deficiencies with this approach: it is not "expandable" +% so it can't be executed in an \edef or a \write; it redefines some +% command (\@tempa here), and it is unsafe to put the first part in a +% macro because of the unbalanced \fi. Below are my versions which are +% expandable and safe. There are % two versions for the syntax: +% \ifnull{#1}\then... and \if\nil{#1}... +% [I hear the second syntax comes from DEK]. Choose your favorite. +% +%======================================================================== +% \ifblank --- checks if parameter is blank (Spaces count as blank) +% \ifgiven --- checks if parameter is not blank: like \ifblank...\else +% \ifnull --- checks if parameter is null (spaces are NOT null) +% use \ifgiven{#1}\then ... \else ... \fi etc +\let\then\iftrue +{\catcode`\!=8 % funny catcode so ! will be a delimiter + \catcode`\Q=3 % funny catcode so Q will be a delimiter +\long\gdef\ifgiven#1\then{\Ifbl@nk#1QQQ\empty!}% negative of \ifblank +\long\gdef\ifblank#1\then{\Ifbl@nk#1QQ..!}% if null or spaces +\long\gdef\Ifbl@nk#1#2Q#3!{\ifx#3} +\long\gdef\ifnull#1\then{\IfN@LL#1* {#1}!}% if null +\long\gdef\IfN@LL#1 #2!{\ifblank{#2}\then} +} +% +%--------------------------------------------------------------------- +% Other version: use \if\given{ }, \if\blank{ }, \if\nil{ } +% (There is no \then). +% +{\catcode`\!=8 % funny catcode so ! will be a delimiter + \catcode`\Q=3 % funny catcode so Q will be a delimiter +\long\gdef\given#1{88\fi\Ifbl@nk#1QQQ\empty!} +\long\gdef\blank#1{88\fi\Ifbl@nk#1QQ..!}% if null or spaces +\long\gdef\nil#1{\IfN@Ught#1* {#1}!}% if null +\long\gdef\IfN@Ught#1 #2!{\blank{#2}} +\long\gdef\Ifbl@nk#1#2Q#3!{\ifx#3}% same as above +} +%--------------------------------------------------------------------- +% +% One note of caution: Even though these macros can be nested +% because they give balanced \if - \fi constructs (\if or \then), +% nesting is still a danger if the tested parameter text contains +% an unbalanced \if or \fi. As a general rule, ill-defined parameter +% text should not be skipped over by \if. +% +% The special delimiter above is a funny Q character having the category +% 3, usually associated with $. If there is some strange application +% where Q might have catcode 3, then a better delimiter would be needed. +% The following paranoid definitions use QQ with *different* categories: +% Q(4)Q(3) as the delimiter. +% +{\catcode`\!=8 % funny catcode so ! will be a delimiter + \catcode`\Q=3 % funny catcode so Q will be a delimiter + \catcode`\R=4 % another funny catcode for Q ! + \uccode`\R=`\Q + \uppercase{\long\gdef\given#1{11\fi\Ifbl@nk#1RQ11RQ12RQ!}} + \uppercase{\long\gdef\blank#1{11\fi\Ifbl@nk#1RQ12RQ11RQ!}}% if null or spaces + \long\gdef\nil#1{\IfN@Ught#1* {#1}!}% if null + \long\gdef\IfN@Ught#1 #2!{\blank{#2}} + \uppercase{\long\gdef\Ifbl@nk#1#2RQ#3RQ#4!{\ifx#3}}% same as above +} |