36
votes

I am wondering how I can get the document title in LaTex, for use elsewhere in the document. I just want to be able to echo it.

5
I'm sure there's a way of having the header of every page have the title in it. With fancyhdr or the memoir document class. So those files will contain an answer. I don't know enough to extract the info though... (I just searched fancyhdr.sty for "title" and got no hits, though...)Seamus
How is this not a real question? The answer is \makeatletter \@title \makeatother.isomorphismes
Indeed. If there's any problem with this question it's that it should be moved to the tex stack exchange site.nedned
This question should be on tex.stackexchange.com.Kalin

5 Answers

30
votes

Using \@title does not work because \maketitle clears \@title. This seems silly to me but that's the way it is. One solution is to redefine \title to save the title somewhere else. For instance,

\def\title#1{\gdef\@title{#1}\gdef\THETITLE{#1}}

then use \THETITLE.

You can do the other way around: \def\MYTITLE{...} then \title{\MYTITLE} and later use \MYTITLE again.

22
votes

I had success just writing a new command.

\newcommand{\mytitle}{...}

\title{\mytitle}
3
votes

There is a package called authoraftertitle that does exactly this

\documentclass{article}
\usepackage{authoraftertitle}
\setlength\parindent{0 pt}

\begin{document}

\title{a good title}
\author{a better author}
\date{the best date}

\maketitle

the title is: \textbf{\MyTitle} \\
the author is: \textbf{\MyAuthor} \\
the data is: \textbf{\MyDate} \\

\end{document}
2
votes

This is a workaround...

\let\titleoriginal\title           % save original \title macro
\renewcommand{\title}[1]{          % substitute for a new \title
    \titleoriginal{#1}%               % define the real title
    \newcommand{\thetitle}{#1}        % define \thetitle
}

\title{This is my title}

\begin{document}
\thetitle
\end{document}

The short version of the title was ignored here...

0
votes

Answered in the tex.stackexchange.com site (hint: titling package). (I don't know how to mark the question as duplicate across SE sites.)