[Tex/LaTex] Problem with defining a titlepage

documentclass-writingerrorstitles

I am writing a LaTeX 2e class with two options msc and phd for my department theses/dissertations. In this class, I need to define a titlepage for the first page of the theses/dissertations which contains the university name, the department name, the title, the author name and so on. The code is something like the following:

\documentclass[‎phd‎]{‎book‎}‎
‎\makeatletter‎‎
‎‎\newif\if@‎phdthesis‎
‎\@‎phdthesis‎‎false‎
‎\DeclareOption{phd}{\@‎phdthesis‎‎true}‎
‎\newif\if@‎msc‎thesis‎‎
‎\@‎mscthesis‎‎false‎
‎\DeclareOption{‎msc‎}{\@‎mscthesis‎‎true}‎‎
‎‎‎
‎\def\author‎#1{\gdef\@‎author‎{#1}}‎‎‎‎
‎‎\if@‎mscthesis‎‎
‎\def‎‎\mytitle‎‎{‎‎‎‎‎\begin{titlepage}‎‎‎‎
    \begin{center}‎
    ‎A‎  thesis ‎for the degree ‎of master of science by‎\\‎
    ‎\@author‎‎
    \end{center}‎‎
    ‎\end‎{titlepage}‎‎‎‎
‎‎‎‎}‎‎
‎\fi‎
‎‎\if@‎phdthesis‎‎
‎\def‎‎‎\my‎title{‎‎‎‎\begin{titlepage}‎‎‎
‎   \begin{center}‎
    A ‎Dissertation‎ for the ‎Degree‎‎ of Doctor of ‎Philosophy ‎by\\‎
    \@author‎
‎   \end{center}‎‎‎‎
    ‎\end‎{titlepage}‎‎
‎‎‎‎}‎‎
‎\fi‎
‎\makeato‎ther‎
\begin{document}‎
\author{‎Vahid‎}‎‎‎
‎‎\mytitle‎
‎‎\chapter{Chapter Name}‎
‎bla ‎bla ‎bla‎
‎\newpage‎
‎bla ‎bla ‎bla‎‎
‎\end{document}

But I get an error: Undefined control sequence.l.32 \mytitle. I am wondering if anybody help me solve this problem.

Best Answer

You get this error, because you define the two versions of \mytitle inside conditionals. Both of them are false in you example, so the macro never gets defined.

You missing an \ProcessOptions which actually handles the given [phd] option, before the first use of the if's:

%...
‎\DeclareOption{‎msc‎}{\@‎mscthesis‎‎true}‎‎
\ProcessOptions   

‎\def\author‎#1{\gdef\@‎author‎{#1}}‎‎‎‎
%...

I assume here the code is in a class file. Please also see the clsguide for more information on how to define options.