[Tex/LaTex] If-if-else-expression using a variable

conditionalstitles

I am trying to create a document class containing the layout for a bachelors thesis and want to keep it as general as possible. In my title page (which is defined in the document class, not the main document) a line like this shall appear:

Handed in by {\@gender} {\@author} on {\@handindate}.

The variables were created using these commands:

\newcommand{\@handindate}{\@handindate}
\newcommand{\handindate}[1]{\renewcommand{\@handindate}{#1}}

\newcommand{\@gender}{Unknown}
\newcommand{\gender}[1]{\renewcommand{\@gender}{#1}}

I want LaTeX to replace \@gender by "Mr." if \@gender=male or by "Mrs." if \@gender=female and by nothing if \@gender is anything else.

I thought of using an \ifcase-command but as far as I know this command only accepts a number as input but I would like to use the variable as input.
What I basically need is something like a " if the value is equal to male, print <text1>, if the value is equal to female print <text2> in all other cases print <> "-syntax but I am not very good at programming, so can anyone help?

Best Answer

Do the check by comparing with “male” and “female”:

\documentclass{article}

\makeatletter
\newcommand{\Handed}{%
  \par
  Handed in by \Apply@Gender\@Author\space on \@Handindate
  \par
}

\newcommand{\@Gender}{Unknown}
\newcommand{\@Author}{Unknown}
\newcommand{\@Handindate}{Unknown}

\newcommand{\Gender}[1]{\renewcommand{\@Gender}{#1}}
\newcommand{\Author}[1]{\renewcommand{\@Author}{#1}}
\newcommand{\Handindate}[1]{\renewcommand{\@Handindate}{#1}}

\newcommand{\Apply@Gender}{%
  \begingroup
  \long\def\@male{male}\long\def\@female{female}%
  \ifx\@Gender\@male 
    Mr.~%
  \else
    \ifx\@Gender\@female
      Mrs.~%
    \fi
  \fi
  \endgroup
}
\makeatother

\begin{document}

\Gender{male}
\Author{G. Byron}
\Handindate{2016-06-21}

\Handed

\bigskip

\Gender{female}
\Author{M. Wollstonecraft}
\Handindate{2016-06-22}

\Handed

\bigskip

\Gender{whatever}
\Author{The Creature}
\Handindate{2016-06-23}

\Handed

\end{document}

enter image description here