0

I want to use a author object in different prints. The author has a structure like this:

{
  {NameOfFirstAuthor|EmailOfFirstAuthor|CurseOfStudiesOfFirstAuthor|SemesterOfFirstAuthor}
  {NameOfFirstAuthor|EmailOfFirstAuthor|CurseOfStudiesOfFirstAuthor|SemesterOfFirstAuthor}
}

It is saved in a command \authors Now I print those authors by calling \makeAuthors:

\newcommand{\makeAuthors}{
\expandafter\printAuthor\authors{}
}

\newcommand{\printAuthor}[1]{
\ifx\relax#1\relax \else
\printedAuthors#1\end \expandafter\printAuthor\fi
}

\def\printedAuthors #1|#2|#3|#4\end{
#1
\varExists{#2}{\\ \href{mailto:#2}{#2} }
\varExists{#3}{\\ #3}
\varExists{#4}{\\ #4. Semester}
}

That works fine, but it is not very flexible.

Now to my question: Is there a way that I can pass a command to \makeAuthors in which the syntax of the print is defined.

So that I have this command declared:

\def\newWayToPrintAuthors #1|#2|#3|#4\end{
#1
\varExists{#1}{\\ \href{mailto:#2}{#1}}
}

And that I am now able to call \makeAuthors{\newWayToPrintAuthors}.

I'd prefer a latex solution cuz for that I have a better understanding but at the end it doesn't matter and I'm just happy when it works.

Thats my try so far:

% Preamble
\documentclass[11pt]{baseClass}

\begin{document}

    % Pre Definiton in Package:
    \newcommand{\authorPrintTemplate}[4]{}

    \newcommand{\makeAuthors}[1]{
        \def\commandName#1
        \renewcommand{\authorPrintTemplate}{
            \commandName{##1}{##2}{##3}{##4}
        }
        \expandafter\makeSingleAuthor\authors{}
    }

    \newcommand{\makeSingleAuthor}[1]{
    \ifx\relax#1\relax \else
    \printedAuthors#1
\end \expandafter\printAuthor\fi
}

\def\buildSingleAuthor #1|#2|#3|#4\end{
\authorPrintTemplate{#1}{#2}{#3}{#4}
}

% What a user of the package needs to do to print something:

\def\authors{
{NameOfFirstAuthor|EmailOfFirstAuthor|CurseOfStudiesOfFirstAuthor|SemesterOfFirstAuthor}
{NameOfSecondAuthor|EmailOfSecondAuthor|CurseOfStudiesOfSecondAuthor|SemesterOfSecondAuthor}
}

\newcommand{\printFullAuthors}[4]{
#1
\varExists{#2}{\\ \href{mailto:#2}{#2} }
\varExists{#3}{\\ #3}
\varExists{#4}{\\ #4. Semester}
\hrule
}

\newcommand{\printAuthorsNames}[4]{
\varExistsElse{#2}{\href{mailto:#2}{#1}}{#1} \\
}

\makeAuthors{printFullAuthors} % I don't care if the user needs to type printFullAuthors or \printFullAuthors
\makeAuthors{printAuthorsNames}

\end{document}

Thanks in advance :D

2
  • your question would be easier to answer if you had provided a test file. You could pass a command as an argument but do you need that, if your command uses \wibble{...} in it's inner code, then a user can define \wibble to be nothing or \colorbox{blue} or whatever you need, there is no need to pass that command through the arguments Commented Nov 27, 2022 at 14:39
  • I added a test file with my current try.
    – Krypton
    Commented Nov 27, 2022 at 15:12

1 Answer 1

1

Something like this

enter image description here

\documentclass[11pt]{article}
\usepackage{hyperref,parskip}
\begin{document}


    \newcommand{\makeAuthors}[1]{% don't forget %
        \let\authorPrintTemplate#1%
        \expandafter\makeSingleAuthor\authors{}%
    }

    \newcommand{\makeSingleAuthor}[1]{%
    \ifx\relax#1\relax \else
    \buildSingleAuthor#1\end
    \expandafter\makeSingleAuthor
    \fi
}

\def\buildSingleAuthor #1|#2|#3|#4\end{%
\authorPrintTemplate{#1}{#2}{#3}{#4}%
}

% What a user of the package needs to do to print something:

\def\authors{
{NameOfFirstAuthor|EmailOfFirstAuthor|CurseOfStudiesOfFirstAuthor|SemesterOfFirstAuthor}
{NameOfSecondAuthor|EmailOfSecondAuthor|CurseOfStudiesOfSecondAuthor|SemesterOfSecondAuthor}
}

\newcommand{\printFullAuthors}[4]{%
#1
\varExists{#2}{\\ \href{mailto:#2}{#2} }%
\varExists{#3}{\\ #3}5
\varExists{#4}{\\ #4. Semester}\par
\hrule
}

\newcommand{\printAuthorsNames}[4]{%
\varExistsElse{#2}{\href{mailto:#2}{#1}}{#1}\par
}

\def\varExists#1#2{#2}%?
\def\varExistsElse#1#2{#1}%?

\makeAuthors{\printFullAuthors} % I don't care if the user needs to type printFullAuthors or \printFullAuthors

\bigskip *** \bigskip 

\makeAuthors{\printAuthorsNames}

\end{document}
1
  • Thank you very much! I'm very glad it works now!
    – Krypton
    Commented Nov 27, 2022 at 18:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .