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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With