Using title and author outside of the title page

2,761 views
Skip to first unread message

jbrabson

unread,
Oct 23, 2009, 7:24:24 PM10/23/09
to LaTeX Users Group

I'm sure I don't have to repeat the same information over and over in
my document.

I already define \title{foo} and \author{bar}. That information
appears in the title page.

I also want to use that information in my document. How can I get to
the information that's inside \title and \author from inside the body
of my document?

To be more specific, I want the headers of my extremely long document
to include the author on one side and the title on the other. I
already do this by hard coding the information in, but I want to put
this header information inside a stylesheet that can be used more
generically.

Any thoughts?

Thanks!
-James

Werner Grundlingh

unread,
Oct 23, 2009, 7:43:39 PM10/23/09
to LaTeX Users Group
James,

Try using a new command to define the title and author entries. For
example,
\newcommand{\titleinfo}{Document Title}
\newcommand{\authorinfo}{Name Surname}
and then use
\title{\titleinfo}
\author{\authorinfo}

Also, using the fancyhdr package, it would be easy to put the author
and title on odd/even package. Read the package documentation,
available online via CTAN from:
http://tug.ctan.org/cgi-bin/ctanPackageInformation.py?id=fancyhdr

Werner
Ps. The above LaTeX commands/defitions are untested...

James M Brabson

unread,
Oct 23, 2009, 7:48:58 PM10/23/09
to latexus...@googlegroups.com

I thought of that, but it's horrifically inelegant.  I'm sure LaTeX offers some way to access those variables.  After all, the \titlepage function does it!  Those extra lines are fine for just me, but I don't want to publicly release a stylesheet that forces people to write that kind of excess code.

Thanks,
-James

Werner Grundlingh

unread,
Oct 23, 2009, 8:03:09 PM10/23/09
to LaTeX Users Group
On Oct 23, 4:48 pm, James M Brabson <james.m.brab...@gmail.com> wrote:
> I thought of that, but it's horrifically inelegant.  I'm sure LaTeX offers some way to access those variables.  After all, the \titlepage function does it!  Those extra lines are fine for just me, but I don't want to publicly release a stylesheet that forces people to write that kind of excess code.
> Thanks,
> -James

Consider using the package authoraftertitle, available online via CTAN
from:
http://tug.ctan.org/cgi-bin/ctanPackageInformation.py?id=authoraftertitle

Alternatively, read the contents of the .sty file (located at the
above link) and see how the author/title/date is extracted.

Werner

James M Brabson

unread,
Oct 23, 2009, 8:28:39 PM10/23/09
to latexus...@googlegroups.com

Also inelegant, but it is invisible to the end user, and it's a trick I've used a dozen other times in the past.  It'll do.  Don't ask why I didn't think of it this time, I was just stuck on being able to access those variables.

Thanks, Werner!
-James

James M Brabson

unread,
Oct 23, 2009, 8:43:33 PM10/23/09
to latexus...@googlegroups.com

A final update:

Werner's suggestion is the only option.  In the definition of classes.dtx in the standard LaTeX package, at the end of the \maketitle definition, the \author, \date, and \title are all reset to empty, so they aren't defined after the title page.

To recap:
\newcommand\Originalauthor{}
\let\Originalauthor\author
\renewcommand*{\author}[1]{%
  \Originalauthor{#1}%
  \renewcommand*{\MyAuthor}{#1}%
}

Then the author is available elsewhere as \MyAuthor.  (Thanks to Matthias Bilger for the code)

-James

James M Brabson

unread,
Oct 24, 2009, 11:22:06 AM10/24/09
to latexus...@googlegroups.com

I finally realized the elegant way to do this.

The trick to using the \author and \title (and \date) variables is to
use them after they've been defined, but before the title page starts.
They don't get reset to \@empty until the titlepage is complete
(specifically until the \maketitle macro runs), so that's the magic time.

If you want to use them inside a stylesheet, your code must look like
this: (Note- When using the memoir class, this \marboth command adds the
\author to the header of even pages and the \title to the header of odd
pages)

\AtBeginDocument{\markboth{\@author}{\@title}}

The variables available to you are \@author, \@title, and \@date. As
stated earlier, you just have to use them during the proper moment. The
\AtBeginDocument macro for packages allows you to do just that.

I thought I should post the proper solution in case others come
searching for it at a later date.

-James


Anglea

unread,
Oct 27, 2009, 4:55:21 AM10/27/09
to LaTeX Users Group
Hi James

I am happy this has been discussed here, as I was thinking to post the
same question....but still the answer not clear for me, I've done the
following

\title{foo}
\author{boo}
\date{\today}
\begin{document}

\AtBeginDocument{\markboth{\@author}{\@title}}
\maketitle
But I did not get the \author to the header of even pages and the
\title to the header of odd
pages.

Anglea

James Brabson

unread,
Oct 27, 2009, 10:32:48 AM10/27/09
to latexus...@googlegroups.com

What memoir page style are you using?  If I want my output to have page numbers at the outside of the pages (left side of even pages, right side of odd pages), to have the Author on the right side of even pages and the title on the left side of odd pages, I use this code in my stylesheet:

  \pagestyle{myheadings}
  \AtBeginDocument{\markboth{\@author}{\@title}}

Note- remember to have the \AtBeginDocument _before_ your \begin{document} (put it in a stylesheet!), so the cart won't be in front of the horse.

To quote the memior pdf documentation:
The myheadings page style is simpler because the user has to specify the contents
using \markboth and \markright commands. This is the definition used in the
standard classes.

-James

Donald Arseneau

unread,
Oct 27, 2009, 1:58:26 PM10/27/09
to LaTeX Users Group
On Oct 27, 12:55 am, Anglea <hanyahamdi...@yahoo.com> wrote:

> \title{foo}
> \author{boo}
> \date{\today}
> \begin{document}
>
> \AtBeginDocument{\markboth{\@author}{\@title}}
> \maketitle

It is a bit late to say \AtBeginDocument after \begin{document}!
Also, you need to allow access to the "hidden" commands like \@author.

\title{foo}
\author{boo}
\date{\today}

\makeatletter
\AtBeginDocument{\markboth{\@author}{\@title}}
\begin{document}
Reply all
Reply to author
Forward
0 new messages