Document ClassesStandard classes: relationship between \author and \@author?

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
deniss
Posts: 11
Joined: Tue Aug 04, 2009 9:06 pm

Standard classes: relationship between \author and \@author?

Post by deniss »

Hello,

I'm using the texlive-2008 distribution through gentoo linux, and I'm trying to learn a little bit about class file structure in order to edit what I need (writing a thesis). Most of the things seem more or less straightforward, but I cannot find any information about the differences between "\title" and "\@title" or "\author" and "\@author" in the standard report class file (report.cls), if any.

My understanding is that since we use commands "\author{}" and "\title{}" in the preamble of the document to set those variables, they must be defined and used in the class file. But do we have to put an "@" after the "\" in the class file when we refer to the variables we set in the preamble (like "\@author" for "\author{}")?

For example, suppose I wanted to insert a dedication page into my document and in the preamble of the document, I would like to enter the text for my dedication page as:

\dedication{To my family.}

then in the class file, do I define/refer to this as "\@dedication" or just "\dedication"?

Many thanks!
Denis

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Standard classes: relationship between \author and \@author?

Post by josephwright »

There is nothing magic about \@title, \@author, etc. The main idea is to use a different name from \author, \title, and so on so that

Code: Select all

\author{First}
\author{Second}
does not give odd results. If you did something like:

Code: Select all

\def\author#1{\def\author{#1}}
then things would go wrong if \author was used more than once in the preamble.
Joseph Wright
deniss
Posts: 11
Joined: Tue Aug 04, 2009 9:06 pm

Standard classes: relationship between \author and \@author?

Post by deniss »

josephwright wrote:There is nothing magic about \@title, \@author, etc. The main idea is to use a different name from \author, \title, and so on so that

Code: Select all

\author{First}
\author{Second}
does not give odd results. If you did something like:

Code: Select all

\def\author#1{\def\author{#1}}
then things would go wrong if \author was used more than once in the preamble.
I am a beginner at this, so I am still confused. Why do standard class files contain \@author AND \author simultaneously? I don't understand which one links to the declaration within the preamble of the document. And why would things go wrong from your second example?

Are we talking about \author and \@author being separate variables? But how would you declare \@author in the preamble when the codes containing \@ aren't allowed in the preamble?
deniss
Posts: 11
Joined: Tue Aug 04, 2009 9:06 pm

Standard classes: relationship between \author and \@author?

Post by deniss »

deniss wrote:I cannot find any information about the differences between "\title" and "\@title" or "\author" and "\@author" in the standard report class file (report.cls), if any.

My understanding is that since we use commands "\author{}" and "\title{}" in the preamble of the document to set those variables, they must be defined and used in the class file. But do we have to put an "@" after the "\" in the class file when we refer to the variables we set in the preamble (like "\@author" for "\author{}")?

For example, suppose I wanted to insert a dedication page into my document and in the preamble of the document, I would like to enter the text for my dedication page as:

\dedication{To my family.}

then in the class file, do I define/refer to this as "\@dedication" or just "\dedication"?
I looked at the classes.dtx file and answered my own question. Sorry for being dense about the basics.

What I need is:

Code: Select all

\newcommand*{\dedication}[1]{\gdef\@dedication{#1}}
So basically we define a command \dedication to create a global variable whose value is \@dedication. So the \author, \title, etc are commands, while \@author, \@title, etc are variables holding values defined by corresponding commands.

So what actually happens if you do

Code: Select all

\author{me}
\author{you}
in the preamble? I didn't see any looping commands in the class file where titlepage is created - is the second author command just ignored?
josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

Standard classes: relationship between \author and \@author?

Post by josephwright »

In the standard classes, something like

Code: Select all

\author{First}
\author{Second}
does indeed just leave \@author as "Second", with "Fist" completely lost. However, other document classes (for example REVTeX) allow multiple \author statements and do include looping (it tends to be a bit complicated, I'm afraid).
Joseph Wright
Post Reply