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.
4 Answers
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.
-
2Thanks, that did the trick, although I had to enclose the define in
\makeatletter
and\makeatother
, which starts to be a whole lot of effort. So since I only need to use the title one other time, there's not much point. It'd be nice if there were a more sensible solution.– nednedCommented Mar 28, 2010 at 9:36 -
3This should be in tex.stackexchange.com. This didn't work for me. I needed to use
\title{My Title} \makeatletter \let\thetitle\@title \makeatother
And then use\thetitle
later in the text.– goneCommented Mar 26, 2016 at 15:33
I had success just writing a new command.
\newcommand{\mytitle}{...}
\title{\mytitle}
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}
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...
\makeatletter \@title \makeatother
.