I am trying to populate a list of variables (in the attached example starting with \@addressone
) with the values obtained from a set of commands. The first variable will get the first of whatever values I have, the second the second, etc. until values run out and from then on all the variables shall be empty. I am trying to do this with nested if statements:
\def \mystreet#1{\def\@mystreet{#1}} % Defines the \name command to set name
\def \mycity#1{\def\@mycity{#1}} % Defines the \name command to set name
\def \myphone#1{\def\@myphone{#1}} % Defines the \name command to set name
\def \myemail#1{\def\@myemail{#1}} % Defines the \name command to set name
\def \myurl#1{\def\@myurl{#1}} % Defines the \name command to set name
\let \@mystreet \relax
\let \@mycity \relax
\let \@myphone \relax
\let \@myemail \relax
\let \@myurl \relax
\ifdefined\@mystreet
\def \@addressone {\@mystreet}
\else
\ifdefined\@mycity
\def \@addressone {\@mycity}
\else
\ifdefined\@myphone
\def \@addressone {\@myphone}
\else
\ifdefined\@myemail
\def \@addressone {\@myemail}
\else
\ifdefined\@myurl
\def \@addressone {\@myurl}
\else
\def \@addressone {}
\fi
\fi
\fi
\fi
\fi
All of this seems to be ignored beyond the first if statement. If \@mystreet
is undefined \@addressone
will be empty, even if say \@mycity
is defined.
COMMENT: it turns out my issue had nothing to do with the nested \ifdefined
statements (which work just as you would expect them to) but rather with how and when LaTeX decided that my user input from files using this class counts as having defined the variables.
\relax
isn't undefined so the tests are always going to be true.@
catcode 11?\relax
lose those lines (depending what you want to do, which isn't clear)*.cls
file, and I pass the values to it from another file via e.g.\myurl{}
. If I lose the\relax
that will make all the values undefined - for some reason :-/, even though some of them do have values. (The full file can be seen here, though I have no idea whether this will help).