# Access the title when defining page headers?

I'm trying to wrap up some stuff into a document class that I have always coded manually into the document files so far. During this, I ran into a problem. Given the following MWE

\documentclass{scrartcl}
\usepackage{lipsum}
\title{Of Foo And Bar}
\author{Me And Myself}
\automark{section}
\begin{document}
\maketitle
\tableofcontents
\clearpage
\section{Foo}
\lipsum[1]
\subsection{Bar}
\lipsum[2-3]
\subsection{Baz}
\lipsum[4-6]
\section{Boo}
\lipsum[1]
\subsection{Bar}
\lipsum[2-3]
\subsection{Baz}
\lipsum[4-6]
\end{document}


I need to remove the redundant title in the call to \ihead and replace it with something that inserts the title I specified earlier using \title{...}. How do I access the title that was set with \title?

-

You can access the title via the command \mytitle if you add

\makeatletter
\let\mytitle\@title
\makeatother


in your preamble after \title:

\documentclass{scrartcl}

\usepackage{lipsum}

\title{Of Foo And Bar}
\makeatletter
\let\mytitle\@title
\makeatother

\author{Me And Myself}
\automark{section}

\begin{document}
\maketitle
\tableofcontents
\clearpage
\section{Foo}
\lipsum[1]
...
\end{document}


Alternatively, the title is accessible via \thetitle if the titling package is loaded, but the latter interferes with the formatting of KOMA-script classes.

-
Works perfectly - since I'm about to move the stuff into a document class, I embedded the \let command into an \AtBeginDocument. –  vwegert Mar 17 '13 at 20:03
@vwegert Please consider accepting my answer if you're satisfied with it :) –  Jubobs Mar 17 '13 at 21:15
I could have sworn I did that last night - must have been too late... –  vwegert Mar 18 '13 at 7:23

If you "dare" to "hack" into the system, read Jubobs answer. If you don't, you can define your own command to substitute the \title command:

\documentclass{scrartcl}
\usepackage{lipsum}

\newcommand{\titledefined}{}
\newcommand{\definetitle}[1]{%
\title{#1}
\renewcommand{\titledefined}{#1}
}

\definetitle{Of Foo And Bar}
\author{Me And Myself}
\automark{section}
\begin{document}
\maketitle
\tableofcontents
\clearpage
\section{Foo}
\lipsum[1]
\subsection{Bar}
\lipsum[2-3]
\subsection{Baz}
\lipsum[4-6]
\section{Boo}
\lipsum[1]
\subsection{Bar}
\lipsum[2-3]
\subsection{Baz}
\lipsum[4-6]
\end{document}


It's longer than Jubobs answer, but it's more suitable to your personal package(s) [if you have them]. You can put the command \definetitle in your personal package (which you load by default), and then simply use it instead of \title.

-