I'm working with a class file, trying to adjust it to my needs, and somewhere in the middle of it is defined a function that writes the title of the paper. What I have is this:
\title{
\vspace{-30pt}
\begin{flushleft}
\HorRule
\\
\fontsize{35}{40}
\usefont{T1}{phv}{b}{n}
\color{titlecolor}
\@TheTitle
\\
\end{flushleft}
}
\renewcommand{\title}[2]{\def\@TheTitle{#1}\def\@ShortTitle{#2}}
Let us begin with the last line of code. It defines a command \title
with two arguments. When you call \title
inside your .tex
file what it does is to define two text replacements inside the .cls
file. The \@ShortTitle
will be used in the footer and \@TheTitle
in the title. Now, going back to the first block of code, it calls a function \title
which uses the value stored in \@TheTitle
. My doubt is this: how can \title
be called before it is defined (in the last line of the code)? And how can it use something that was not defined yet (the \@TheTitle
)?
I tried to pass the line
\renewcommand{\title}[2]{\def\@TheTitle{#1}\def\@ShortTitle{#2}}
to the begining of the code but it simply does not work that way. What is going on?
\title
define maybe\createtitle
and then define a command to change the variables used within\createtitle
:\newcommand{\mytitle}[2]{\def\@TheTitle{#1}\def\@ShortTitle{#2}}
. So, in yourtex
file you can use\title{}{}
and\createtitle
.cls
file. It will be executed only ontex
file when you call it. In thecls
you can change orders, no problem.\def
or\newcommand
are only checked for existance at the time they are expanded. So in your case\@TheTitle
can be used in the\title
command even if it hasn't been defined so far. Problems only arise if\title
is actually called in your code without\@TheTitle
being defined at that point.