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.
36
votes
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.
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.)
\makeatletter \@title \makeatother
. – isomorphismes