# Default values in \newcommand & renewing \maketitle

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]

\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.

-

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

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

\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!

-
Thanks! It fixed all my errors. Just a few questions: (1) why do you make use of \gdef? (2) can I make use of \newcommand instead of \def? Is it just a personal choice or is there a reason why you used it? –  pyro Jul 25 '13 at 7:37
@PradeepKumar: \gdef is \global\def. It overrides the \def. I personally used \def rather than \newcommand, which is more convenient for me. The main logic is, define a default value for logo inside \@logo and if you have your own logo provided by \logo command in TeX, make it a global value to \@logo and override the default value. –  Jagath AR Jul 25 '13 at 7:45
Got it, thanks. –  pyro Jul 25 '13 at 7:59
1. Yes, but there might be a better way. Why? Well, you create \logo[<logo>] to have an optional argument but you would never call \logo without an argument so that it would take the default. That is, it should take the default of logo.pdf by default, without doing anything else. Perhaps using

\makeatletter
\newcommand{\logo}[1]{\def\@logoname{#1}}\logo{logo.pdf}
\def\@logo{\includegraphics[width=40mm]{\@logoname}}
\makeatother


would help. This creates \logo{<logo>} which stores it's argument in \@logoname. Then immediately sets the default to logo.pdf, and subsequently defines \@logo to insert \@logoname (whatever it may be).

2. Similar to the above, you need to define the way the unknown macros \@college, \@university and \@degree function. Perhaps you can do something similar for these:

\makeatletter
\newcommand{\college}[1]{\def\@collegename{#1}}\college{My college}
\def\@college{\@collegename}
\newcommand{\university}[1]{\def\@universityname{#1}}\university{My university}
\def\@university{\@universityname}
\newcommand{\degree}[1]{\def\@degreename{#1}}\degree{My degree}
\def\@degree{\@degreename}
\makeatother


In this instance, the use of \@college as an alias \@collegename is a bit superfluous, so you could use \@collegename directly in your \maketitle construction. Your choice.

-
Thank you Werner! –  pyro Jul 25 '13 at 7:56