I seem to be stuck and for now am trying my luck through trial and error to find the right way to do this.
Here is a general idea:
% I DECLARE NEW MACROS WITH NAMES AS DEFFINITION. AND ASIGN LETTERS TO PEOPLE SINCE NUMBERS ARE FORBIDEN IN MACRO'S NAMES.
\newcommand{\AuthorNameA}{John}
\newcommand{\AuthorSurnameA}{Doe}
\newcommand{\AuthorNameB}{Jane}
\newcommand{\AuthorSurnameB}{Doe}
\newcommand{\AuthorNumber}{3}
% DECLARE NEW COUNTER
\newcounter{loopTitleCoverAuthor}
% START WITH LOOP
\forloop{loopTitleCoverAuthor}{1}{
%COMPARE COUNTER WITH DEFINITION OF MACRO SET PREVIOUSLY
\value{loopTitleCoverAuthor} < \value{bfThesisAuthorNumber}
}{
% IF CONDITION IS TRUE CHECK IF MACRO WITH PARTICULLAR ENDING IS DEFINED AND IF IT IS, PRINT NAME AND SURNAME
\ifdefined\expandafter\AuthorName\Alph{loopTitleCoverAuthor}
\expandafter\AuthorName\Alph{loopTitleCoverAuthor} \textsc{\expandafter\AuthorSurname\Alph{loopTitleCoverAuthor}}\\
\fi
}
a) Not surprisingly that didn't work. The first issue I got was comparing the counter to a macro value. So to continue and to see what else might be wrong I changed condition part to:
\value{loopTitleCoverAuthor} < 3 %\value{bfThesisAuthorNumber}
b) Then I had a problem with \ifdefined
check so I commented that out too and name and surname macros are always called.
c) Lastly I had a problem with \expandafter
(I think). I now get output, but not as it should be. It omits \AuthorName
and \AuthorSurname
and prints only \Alph
of the counter step.
I would expect to see:
John Doe
Jane Doe
I get:
AA
BB
So, those are my questions:
Is it possible to use a value of macro in the condition of
\forloop
(a)?How should I reformat
\ifdefined
to check properly if macro is defined in each loop (\AuthorNameA
in first loop,\AuthorNameB
in second ...) (b)? I also tried with\csname
, multiple \expandafter,\expandafter
before\ifdefined
, ... Nothing described here: https://www.tug.org/TUGboat/tb09-1/tb20bechtolsheim.pdf seems to work (or more likely I'm doing something obviously wrong and can't see it).What should I change so that
\AuthorNameA
gets expanded (c)?Is there a generally better way to do this? Declare "controls and variables" in one file and then
\input
that file and use values of those macros in loops to display and control output?
bfThesisAuthorNumber
I don't see any definition. – MaestroGlanz Apr 22 '16 at 17:29\ifdefined\csname...
you always get true. If the function in\csname
is undefined, it returns\relax
. That means, it should be\expandafter\ifx\csname someStuff\endcsname\relax (You compare the macro with
\relax`). I don't get the question exactly, so I write this as a comment first. – MaestroGlanz Apr 22 '16 at 17:32\ifcsname...\endcsname
that returns true if the control sequence that would be obtained by\csname...\endcsname
has a meaning and false otherwise, but without making it equivalent to\relax
. – egreg Apr 22 '16 at 17:59