Calling fancy
page style is somehow apparently causing the following condition to test true.
\documentclass{article}
\usepackage{fancyhdr}
\pagestyle{fancy}
\ifcsname chapter\endcsname%
\renewcommand{\chapter}{}
\fi
\pagestyle{empty}
\begin{document}
testing
\end{document}
If I place \pagestyle{fancy}
after the conditional, \ifcsname chapter....\fi
, everything works. This is an article
class, so this conditional should be false. If I call \pagestyle{plain}
, it doesn't matter where I place it.
Why does this order matter?
Best Answer
The page style
fancy
(\ps@fancy
) contains:That is the LaTeX test for undefined:
\csname
has the side effect that it defines an undefined command with the meaning\relax
:The meaning of
\chapter
changes:Now
\chapter
is defined for e-TeX's\ifcsname
and\renewcommand{\chapter}{}
is called that again used the LaTeX idea of undefined: A command is undefined if it is undefined or has the meaning of\relax
. As result\renewcommand
complains that `\chapter is not defined.e-TeX's
\ifcsname
does not have the side effect and lets the command untouchted. (Also it is internally optimized in the sense that it does not create a hash table entry.)The test needs to be a little longer:
A defined
\chapter
might confuse packages and macros about the capabilities of the class (article
does not have chapters). If the purpose of the mysterious\renewcommand\chapter{}
is to undefine chapter, then it will fail, because\chapter
remains defined with the meaning of an empty macro. A command can be undefined by assigning it to an undefined macro: