General ⇒ Print document-title given by \title
Print document-title given by \title
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.
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Print document-title given by \title
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}
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Print document-title given by \title
Re: Print document-title given by \title
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Re: Print document-title given by \title
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Print document-title given by \title
Accidentally!localghost wrote:Do you mean accidentally or user intended?
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.Can you give a short example?
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
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.

Print document-title given by \title
They're cleared by \maketitle, to save memory.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.
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