开发者

How to get the value of the document title in latex?

开发者 https://www.devze.com 2022-12-24 13:35 出处:网络
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.Using \\@title does not work because \\maketitle clears \\

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.


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.


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...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号