# Capitalize first letter of words in chapter mark

I would like to capitalize the first letter of several words in the chapter and the chapter mark. While text in the chapter itself is capitalized, in the chapter mark it is not.

Here is a MWE of my current code:

\documentclass{book}

\usepackage{mfirstuc,fancyhdr,lipsum}

\fancypagestyle{mainmatter}{%
\fancyhf{}
}

\begin{document}
\pagestyle{mainmatter}
\chapter{\ecapitalisewords{some thing} with Text}
\lipsum[1-5]
\end{document}


How can I make fancyhdr work with \ecapitalisewords ?

EDIT:

I noticed that \nouppercase kills \MakeUppercase

\def\nouppercase##1{{\let\uppercase\relax\let\MakeUppercase\relax
\expandafter\let\csname MakeUppercase \endcsname\relax##1}}%


which however is needed by \ecapitalisewords which uses

\def\@gls@makefirstuc#1{\MFUapplytofirst\mfirstucMakeUppercase{#1}}
\newcommand*{\mfirstucMakeUppercase}{\MakeUppercase}


I further notices, that fancyhdr.sty defines \chaptermark with \MakeUppercase.

For this reason, I tried

 \documentclass{book}

\usepackage{mfirstuc,fancyhdr,lipsum}

\fancypagestyle{mainmatter}{%
\fancyhf{}
}
%

\let\orgMakeUppercase\MakeUppercase

\usepackage{xpatch}
\makeatletter
\xpatchcmd{\chaptermark}{\MakeUppercase}{}{}{}
\xpatchcmd{\sectionmark}{\MakeUppercase}{}{}{}
\xpatchcmd{\@gls@makefirstuc}{\mfirstucMakeUppercase}{\orgMakeUppercase}{}{}
\makeatother

\begin{document}
\pagestyle{mainmatter}
\chapter{\ecapitalisewords{some thing} with Text}
\lipsum[1-5]
\end{document}


But without success, the chaptermark is this time ALL CAPITAL, meaning the patching did not seem to work to being with.

The reason why your solution doesn't work is that \chaptermark and \sectionmark are redefined when you call \pagestyle{mainmatter}. This happens because every page style created with \fancypagestyle also calls \ps@fancy when set, and this sets both \chaptermark and \sectionmark to something that uses \MakeUppercase.

To get rid of these \MakeUppercases, you could add the lines (which I copied from your question)

\xpatchcmd{\chaptermark}{\MakeUppercase}{}{}{}%
\xpatchcmd{\sectionmark}{\MakeUppercase}{}{}{}%


to your document, right after calling \pagestyle{mainmatter}.

Adding these lines to the second argument of \fancypagestyle won't work because \ps@fancy is called last and would undo these patches. You could however patch the macro \ps@mainmatter that was created by \fancypagestyle{mainmatter}{…} directly to include these lines. Here's how that would/could go:

\documentclass{book}
\usepackage{mfirstuc,fancyhdr,lipsum}

\fancypagestyle{mainmatter}{% %% <- defines \ps@mainmatter
\fancyhf{}%
}

\usepackage{xpatch}
\makeatletter
\appto\ps@mainmatter{% %% <- appends to \ps@mainmatter
\xpatchcmd{\chaptermark}{\MakeUppercase}{}{}{}%
\xpatchcmd{\sectionmark}{\MakeUppercase}{}{}{}%
}
\makeatother

\begin{document}
\pagestyle{mainmatter} %% <- calls \ps@mainmatter
\chapter{\ecapitalisewords{some thing} with Text}
\lipsum[1-5]
\end{document}


You could also redefine \ps@fancy to remove all instance of \MakeUppercase there, but you're asking for the least invasive solution, and that probably wouldn't be it. For completeness, though, here's a way to do that:

\documentclass{book}
\usepackage{mfirstuc,fancyhdr,lipsum}

\fancypagestyle{mainmatter}{% %% <- defines \ps@mainmatter
\fancyhf{}%
}

\usepackage{xpatch}
\newrobustcmd\exhaustivepatchcmd[3]{% %%<- patches as often as necessary
\patchcmd{#1}{#2}{#3}{\exhaustivepatchcmd{#1}{#2}{#3}}{}%
}
\makeatletter
\patchcmd{\ps@fancy}{\def\MakeUppercase{\uppercase}}{}{}{}
\exhaustivepatchcmd{\ps@fancy}{\MakeUppercase}{\@firstofone}
\makeatother

\begin{document}
\pagestyle{mainmatter}
\chapter{\ecapitalisewords{some thing} with Text}
\lipsum[1-5]
\end{document}


(I only define \exhaustivepatchcmd because manually calling \patchcmd three times feels wrong. I remove \def\MakeUppercase{\uppercase} because that instance of \MakeUppercase shouldn't be patched (and serves no purpose).)

A possible solution would be this:

\documentclass{book}

\usepackage{mfirstuc,fancyhdr,lipsum}

\fancypagestyle{mainmatter}{%
\fancyhf{}
}
\newcounter{mychap}

This solution uses the command \mchapter but you could redefine the original \chapter command to do it even if it is a starred command etc. (See here)
• Thanks! is there also a less invasive method? I though the root of the problem is the \nouppercase macro, is that possible? – bonanza Feb 27 at 18:55