如何在latex中获取文档标题的值?

ned*_*ned 29 latex

我想知道如何在latex中获取文档标题,以便在文档的其他地方使用.我只是希望能够回应它.

lhf*_*lhf 27

使用\@title不起作用因为\maketitle清除\@title.这对我来说似乎很傻,但事实就是如此.一种解决方案是重新定义\title以将标题保存在其他位置.例如,

\def\title#1{\gdef\@title{#1}\gdef\THETITLE{#1}}
Run Code Online (Sandbox Code Playgroud)

然后用\THETITLE.

您可以采取相反的方式:\def\MYTITLE{...}然后\title{\MYTITLE}再使用\MYTITLE.

  • 这应该在tex.stackexchange.com中.这不适合我.我需要使用`\ title {My Title}\makeatletter\let\thetitle\@title\makeatother`然后在文本中使用`\ thetitle`. (3认同)
  • 谢谢,这就是诀窍,虽然我必须在`\ makeatletter`和`\ makeatother`中附上定义,这开始是一大堆努力.因为我只需要另一次使用标题,所以没有多大意义.如果有一个更明智的解决方案,那就太好了. (2认同)
  • 您可以采取相反的方式:\ def\MYTITLE {...}然后\ title {\ MYTITLE},然后再次使用\ MYTITLE. (2认同)

小智 16

我只是写了一个新命令就成功了.

\newcommand{\mytitle}{...}

\title{\mytitle}
Run Code Online (Sandbox Code Playgroud)


zyy*_*zyy 6

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}
Run Code Online (Sandbox Code Playgroud)