7

I am trying to include the document title in a heading using scrartcl. For some reason when I call \maketitle, the \@title variable seems to be unset and all uses of it turn up empty.

My document looks something like this (stripped to just a test case):

\documentclass{scrartcl}
    \usepackage[english]{babel}
    \usepackage[automark,headsepline]{scrpage2}
    \pagestyle{scrheadings}

    \makeatletter
    \ihead{\MakeUppercase{\@title}}
    \makeatother

    \usepackage{blindtext}

\title{my doc title}

\begin{document}

\blinddocument % headers show the document title on these pages

\maketitle

\blinddocument % these pages have an empty header

\end{document}

As noted, my headings show the document title fine up until the point where I call \maketitle, then the field is blank. I have tried re-assigning the header and even title variable after outputting the title to no-avail. How can I get my header back?

5
  • If you look up scrartcl.cls, you'll see that \maketitle wipes \@title (and other similar macros) globally after using them to typeset the title page.
    – jub0bs
    Mar 7, 2014 at 14:36
  • 1
    i can't say why it's done, but the basic article.cls definitely wipes out the title and a lot more, and furthermore, disables \title, \author, and the definitions for other top matter elements. i suspect that scrartcl is simply following that example. Mar 7, 2014 at 14:38
  • The answer is "because", I'm afraid. ;-) There should be a question about how keeping the title in a variable also after \maketitle.
    – egreg
    Mar 7, 2014 at 14:43
  • 2
    @egreg -- i looked this up with texdoc classes (classes.pdf presents the annotated code for the basic latex classes), and it appears to be a matter of saving space. (see lines 564-576.) space was a real consideration when this code was written; it isn't any more, and i'd like to see this changed with latex3. Mar 7, 2014 at 15:41
  • 1
    @barbarabeeton I agree; \documentclass{article3} shouldn't do this saving. Twenty years of experience with LaTeX2e and technology development also show that other metadata should be dealt with, even if not used with \maketitle.
    – egreg
    Mar 7, 2014 at 15:46

3 Answers 3

3

You can redefine \maketitle to save and restore a copy of \@title.

\documentclass{scrartcl}
    \usepackage[english]{babel}
    \usepackage[automark,headsepline]{scrpage2}
    \pagestyle{scrheadings}

    \makeatletter
    \ihead{\MakeUppercase{\@title}}
    \makeatother

    \usepackage{blindtext}

\title{my doc title}

\makeatletter
  \let\svmaketitle\maketitle
  \def\maketitle{\protected@edef\saved@title{\@title}%
  \svmaketitle%
  \let\@title\saved@title}%
\makeatother

\begin{document}

\blinddocument % headers show the document title on these pages

\maketitle

\blinddocument % these pages have an empty header

\end{document}
4

If you use a current KOMA-Script version, at least version 3.12 which is already available for MiKTeX and TeX Live via normal package update, everything works as expected: enter image description here

Note: This feature depends on option version. So if you are using a deprecated option, that sets version=first, it doesn't work.

2
  • When did v3.12 come out (sorry I don't speak German so the site you linked to isn't helping me). I have v3.11b per the standard TexLive packages I installed just this week.
    – Caleb
    Mar 7, 2014 at 15:20
  • @Caleb: Around Christmas 2013. TeXLive updates have it. Mar 7, 2014 at 15:44
3

You don't have to patch \maketitle just to remember the title

\documentclass{article}

\newcommand{\mytitle}{Save This Title}

\title{\mytitle}
\author{me}

\begin{document}

\maketitle
The title of this document is \mytitle.

\end{document}

Edit ... but this will not remember the title for the header.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .