tags:

views:

56

answers:

2

I am writing a document class for LaTeX and I want it to be generic. In this document class I redefine the \maketitle command to display a custom title page, and here I want to display some information, like the title, author, etc., but also some other informations. Here is how I display the title:

{\LARGE{\bf \@title}}\\

I'd like to create a new command that works similarly to \title or \author, how can I do that?

+2  A: 

If you look at latex.ltx you can see that \title is defined as follows:

\def\title#1{\gdef\@title{#1}}
\def\@title{\@latex@error{No \noexpand\title given}\@ehc}

Those are low-level TeX commands. \title is a command that redefines \@title to expand to the argument given to \title. In more modern LaTeX commands your own definition could look like this:

\newcommand\foo[1]{\renewcommand\@foo{#1}}
\newcommand\@foo{\@latex@error{No \noexpand\foo given}\@ehc}

It's better to use \PackageError or \ClassError to show the error message. Or, if you want \foo to be optional and be empty by default:

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

If this is not inside a package, you'll have to put it between \makeatletter and \makeatother because of the @ signs.

Thomas
+1  A: 

Here is a sample command I used in my thesis.cls class. It defines a new command \university that works as the \title or \author commands with a default value equals to "no university". If I don't use the \university command in my preamble the default value will be used instead.

\def\@university{no university}
\newcommand{\university}[1]{
  \def\@university{#1}
}

Then, in the \maketitle command you can have something like:

\newcommand{\maketitle}{
  {\LARGE{\bf \@title}}\\
  {\small{\@university}}\\
}
Lohrun