Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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[headsepline,footsepline]{scrpage2}
\usepackage{lipsum}
\title{Of Foo And Bar}
\author{Me And Myself} 
\pagestyle{scrheadings}
\clearscrheadfoot
\ihead{Of Foo And Bar\\\headmark}
\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?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

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[headsepline,footsepline]{scrpage2}
\usepackage{lipsum}

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

\author{Me And Myself} 
\pagestyle{scrheadings}
\clearscrheadfoot
\ihead{\mytitle\\\headmark}
\automark{section}

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

enter image description here

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

share|improve this answer
    
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
add comment

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[headsepline,footsepline]{scrpage2}
\usepackage{lipsum}

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

\definetitle{Of Foo And Bar}
\author{Me And Myself} 
\pagestyle{scrheadings}
\clearscrheadfoot
\ihead{\titledefined\\\headmark}
\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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.