Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to include the values of author, date, and title in my use of fancyhdr in a document that uses \maketitle. Googling about, I saw that @date, etc. can access the date, etc., values set in the document preamble. It works fine, provided \maketitle is not used. Here's a minimal working example:

\documentclass{article}

\title{Things about Stuff}
\author{Someone}
\date{Somewhen}

\begin{document}

%\maketitle  %Toggle comment and:

Now you see them, now you don't.

\makeatletter
\@date
\@author
\@title
\makeatother

\end{document}

So, 1) why does the use of \maketitle cause subsequent invocation of @date, etc. to yield nothing, and 2) how can I access the value of \date, etc after the use of \maketitle?

share|improve this question
    
To answer 1) the normal \maketitle macro resets all of these macros: \global \let \@author \@empty \global \let \@date \@empty \global \let \@title \@empty –  Martin Scharrer Sep 6 '11 at 23:01
    
    
@Alan I don't think so. I did link to that other question in the answer that I gave below, but I could well imagine that someone might run into the difficulty that I did without having the interest in producing a custom title page. I added my question despite the existence of that one as mine seems to represent a distinct (way of arriving at the) problem. But, if the community disagrees, so be it :-) –  vanden Sep 7 '11 at 6:27
add comment

3 Answers

up vote 13 down vote accepted
\documentclass{article}

\makeatletter
\title{Things about Stuff}\let\Title\@title
\author{Someone}          \let\Author\@author
\date{Somewhen}           \let\Date\@date
\makeatother

\begin{document}

\maketitle 

Now you see them
\Date
\Author
\Title

\end{document}
share|improve this answer
add comment

Use the titling package, which provides \thedate, \theauthor, \thetitle even after you've called \maketitle.

It's as simple as adding the package, and instead of calling \@date you call \thedate (which also avoids requiring \makeatletter and \makeatother).

\documentclass{article}

\usepackage{titling}

\title{Things about Stuff}
\author{Someone}
\date{Somewhen}

\begin{document}

\maketitle

Now you still see them.

\thedate
\theauthor
\thetitle

\end{document}
share|improve this answer
add comment

Checking this site before I posted this question, I saw that this earlier question yielded the answer "use the titling package". That seems to work. But, I'd also come up with putting

\newcommand{\setdocdata}{
\title{Things about Stuff}
\author{Someone} 
\date{Somewhen}
}
\setdocdata{}

in my preamble and then using

\maketitle\setdocdata

which works, too, and might appeal to those who prefer to use as few packages as necessary.

(I still would like to know why, for the love of puppies, \maketitle was coded to blank the date, etc values.)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.