GeneralPrint document-title given by \title

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Montag
Posts: 340
Joined: Wed Jul 15, 2009 9:25 am

Print document-title given by \title

Post by Montag »

Hello,

I'd like to print out the document title at certain points in the document. For this, I'd like to print out (I thought of \thetitle but it doesn't work) the title I defined via \title. Just to clarify: It's a string of words, maybe only one word, but it's not the titlepage.

Is that possible?

I've searched for a solution for good 15 minutes now, but it seems my queries were too general for Google and Bing.
Last edited by Montag on Tue Mar 08, 2011 6:38 pm, edited 1 time in total.
OS: Win 7 64-bit LaTeX: MikTeX 2.9 64-bit Editor: TXC 1 RC1

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Print document-title given by \title

Post by localghost »

The arguments of \author and \title are stored in special internal macros. Save them to another macro and you can use them wherever you want. If I understand you right, the code below should do what you want.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\title{Using the document title wherever needed}
\author{Montag}

\makeatletter
\let\thetitle\@title
\let\theauthor\@author
\makeatother

\begin{document}
  \maketitle

  The title of this short document is: »\thetitle«.
  Author of this document is: \theauthor.
\end{document}
Note that the sequence of commands is very important. The title and author have to be declared first to make the new commands work.


Thorsten
Montag
Posts: 340
Joined: Wed Jul 15, 2009 9:25 am

Re: Print document-title given by \title

Post by Montag »

Thanks a lot, Thorsten, that is what I looked for.
OS: Win 7 64-bit LaTeX: MikTeX 2.9 64-bit Editor: TXC 1 RC1
Montag
Posts: 340
Joined: Wed Jul 15, 2009 9:25 am

Re: Print document-title given by \title

Post by Montag »

Is there a way these internal commands could be nullified somehow? I just noticed in one document the author and title field are empty and I can't figure out why, that's why I'm asking.
OS: Win 7 64-bit LaTeX: MikTeX 2.9 64-bit Editor: TXC 1 RC1
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Print document-title given by \title

Post by localghost »

Do you mean accidentally or user intended? Can you give a short example?
Montag
Posts: 340
Joined: Wed Jul 15, 2009 9:25 am

Print document-title given by \title

Post by Montag »

localghost wrote:Do you mean accidentally or user intended?
Accidentally!
Can you give a short example?
I'd like to, but like I said, I defined the title and author like you showed above and so far I had no problems.
But in one document of mine, the fields stay empty. And I already made a "folder search" in TXC and can't find some second definitions for \title{This is the title} and \author{My name} anywhere. So I guess this code

Code: Select all

\makeatletter
\let\thetitle\@title
\let\theauthor\@author
\makeatother
gets re-set to zero or empty later on.
I don't really understand it. :/

EDIT:
Got it. Clear case of Luser. :/
I accidentally switched the order of the commands you provided in your answer, in which you also underlined the importance of their order. :)
OS: Win 7 64-bit LaTeX: MikTeX 2.9 64-bit Editor: TXC 1 RC1
paul
Posts: 49
Joined: Thu Apr 08, 2010 5:56 am

Print document-title given by \title

Post by paul »

Montag wrote:Is there a way these internal commands could be nullified somehow? I just noticed in one document the author and title field are empty and I can't figure out why, that's why I'm asking.
They're cleared by \maketitle, to save memory.

You could do

Code: Select all

\makeatletter
\let\m@ketitle=\maketitle
\def\maketitle{\let\@@author=\@author\let\@@title=\@title
\m@ketitle
\let\author=\@@author\let\title=\@@title}
\makeatother
(and then use \author and \title for those values)
Post Reply