[Tex/LaTex] Default values in \newcommand & renewing \maketitle

documentclass-writingtitles

I am working on customizing a thesis document class according to my needs.
I am trying to renew the \maketitle command to modify my title page, and I am facing two problems:

  1. I wish to define a newcommand for the logo in the title page. If there is no user-defined parameter, a default value called "logo.pdf" should be passed to the \includegraphics command to load the default logo.

    \newcommand{\logo}[1][logo.pdf]{\includegraphics[width=40mm]{#1}}
    

    Is this correct?

  2. There seems to be some problem with my class file, as I keep getting the Undefined control sequence in \maketitle error. Below is my document class:

mythesis.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mythesis}[2013/07/25 v1.0 My thesis class]
\LoadClass[a4paper]{report}

\RequirePackage{graphicx} % needed for logo and pictures

\newcommand{\logo}[1][logo.pdf]{\includegraphics[width=40mm]{#1}}
\newcommand{\college}[1][My School]{{#1}}
\newcommand{\degree}[1][My degree]{{#1}}
\newcommand{\university}[1][My university]{{#1}}

\newenvironment{alwayssingle}{%
       \@restonecolfalse
       \if@twocolumn\@restonecoltrue\onecolumn
       \else\if@openright\cleardoublepage\else\clearpage\fi
       \fi}%
       {\if@restonecol\twocolumn
       \else\newpage\thispagestyle{empty}\fi}

\makeatletter
\renewcommand\maketitle{
\begin{alwayssingle}
    \begin{center}
        {\Huge {\bfseries {\@title}} \par}
        {\large \vspace*{10mm} {\@logo \par} \vspace*{15mm}}
        {{\Large \bf \@author} \par}
        {\large \vspace*{1ex} {{\@college} \par}
        {\large \@university \par}
        {\Large \it {\@degree} \par}
        \vspace*{2ex}
        {\today}}
    \end{center}
\null\vfill
\end{alwayssingle}
}
\makeatother

thesis.tex:

\documentclass[12pt]{mythesis}

\begin{document}
\title{My research}
\author{My name}
\logo{logo_new.pdf}
\maketitle
\end{document}

Any help on this is appreciated.
P.S.: I am a newbie, especially in document class creation.

Best Answer

Both your problems are addressed in the below provided edited class file:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mythesis}[2013/07/25 v1.0 My thesis class]
\LoadClass[a4paper]{report}

\RequirePackage{graphicx} % needed for logo and pictures

\let\@college\@empty
\let\@degree\@empty
\let\@university\@empty
\def\@logo{\includegraphics[width=40mm]{logo.pdf}}
\newcommand{\logo}[1]{\gdef\@logo{\includegraphics[width=40mm]{#1}}}
\newcommand{\college}[1][My School]{\gdef\@college{#1}}
\newcommand{\degree}[1][My degree]{\gdef\@degree{#1}}
\newcommand{\university}[1][My university]{\gdef\@university{#1}}

\newenvironment{alwayssingle}{%
       \@restonecolfalse
       \if@twocolumn\@restonecoltrue\onecolumn
       \else\if@openright\cleardoublepage\else\clearpage\fi
       \fi}%
       {\if@restonecol\twocolumn
       \else\newpage\thispagestyle{empty}\fi}

\renewcommand\maketitle{
\begin{alwayssingle}
    \begin{center}
        {\Huge\bfseries\@title\par}
        {\vspace*{10mm}\par\@logo\par\vspace*{15mm}}
        {\Large\bfseries\@author\par}
        {\ifx\@college\@empty\else\large\vspace*{1ex}\par\@college\par\fi}
        {\ifx\@university\@empty\else\large\@university\par\fi}
        {\ifx\@degree\@empty\else\Large\itshape\@degree\par\fi}
        \vspace*{2ex}
        {\today}
    \end{center}
\null\vfill
\end{alwayssingle}
}
\endinput

Some points:

  1. \makeatletter and \makeatother is not required in class and style files. If you give one, then it is not a problem.
  2. See \@logo defined above. It will be taken as default if you did not provided \logo command in your TeX file, otherwise \logo command will redefine \@logo with the new file you had given in the TeX file.
  3. Commands like \@logo, \@college, \@degree, \@university etc were not defined inside \maketitle which were causing the error. I have added those in their respective macros.
  4. Commands such as \it, \bf, \sl etc are now obsolete and we need to use \itshape, \bfseries, \slshape etc.

Otherwise, its a great way to start with!