# nameref changes header when referencing a chapter*

I'm writing a LaTeX document with book as document class and compiled with pdflatex. TexLive version is latest 2012.

For introduction (and conclusions) chapter, I'm using:

\chapter*{Introduction \markboth{INTRODUCTION}{}}
\label{intro}

• chapter* because I want it to be non-numbered
• \markboth because otherwise header is not "INTRODUCTION" but "CONTENTS" instead (cf. header and chapter* for example)
• \addcontentsline to have it appear in the table of contents

But if I reference it using \nameref{intro} in another chapter (\chapter{my chapter}) then the header of that chapter becomes "INTRODUCTION" instead of "CHAPTER 1 - MY CHAPTER".

Note that if I don't use \markboth for the Introduction the header of chapter 1 is correct but the header for the Introduction is not (it becomes "CONTENTS").

Of course if just after the \nameref{} in chapter 1, I call \markboth{CHAPTER 1 - MY CHAPTER}{} then the chapter 1 header is correct again but this is obviously not practical.

Here is a minimal code showing the problem :

\documentclass[a4paper,twoside]{book}

%\usepackage[english]{babel}
% nameref is buggy, when used, header names for chapter in which it is used are wrong
% if previous chapter is a chapter
% even version from 2012/07/31 is buggy ...
\usepackage{nameref}[2012/07/31]

\title{test}
\author{alex}

\begin{document}
\frontmatter
\maketitle
blabla
\tableofcontents

\mainmatter
%\markboth is needed otherwise header is "CONTENTS" instead of "INTRODUCTION" because this is a chapter*{}, not a chapter{}
\chapter*{Introduction \markboth{INTRODUCTION}{}}
\label{intro}
blabla.
\newpage
blabla.
\chapter{On the use of Foo in Bar}
\label{chap1}
blabla.
\newpage
And here if I namereference the \nameref{intro} it will break the nice header.
%And here if I namereference the \nameref{intro} with a \markboth{CHAPTER 1 - On the use of Foo in Bar}{} it will do what I need but it is *not* practical at all.

\chapter{On the use of Bar in Foo}
\label{chap2}
blabla.
\chapter*{Conclusions \markboth{CONCLUSIONS}{}}
\label{conclusions}
blabla.
\newpage
blabla
\chapter{And here too}
\label{chap3}
blabla.
\newpage
blabla with a nameref. to the \nameref{chap1}. cause the same problem, header that should read "CHAPTER 3 - AND HERE TOO" is replaced by "INTRODUCTION".

\backmatter
blabla
\end{document}

-
putting \markboth outside of the chapter{} fixes the issue. I'll answer my own question as soon as stackexchange lets me do it (i.e. in 8 hours) –  alexis Aug 7 '12 at 16:55

\chapter*{Introduction \markboth{INTRODUCTION}{}}

What is the title? The whole argument:

Introduction \markboth{INTRODUCTION}{}


What happens, if \nameref is used? The whole title including \markboth is called and the execution of \markboth changed your header.

Solutions:

• Put \markboth after \chapter*:

\chapter*{Introduction}
\markboth{INTRODUCTION}{}

• Since version 2009/12/08 v2.34 package nameref uses package gettitlestring. This package knows a title extract method using expansion that allows to filter stuff out, see package documentation of gettitlestring.

\GetTitleStringSetup{expand}
\GetTitleStringDisableCommands{%
\def\markboth#1#2{\unskip}%
}


During title string extraction macro \markboth removes its arguments and calls unskip to get rid of the previous space.

-