# What variable contains the word “Appendix” when a chapter is an appendix?

I've designed a whole new fancy chapter header layout, and have hard coded the word "Chapter" in there before the chapter number. I just realized now that this won't work because I have an appendix named "Chapter A".

Is there a variable that will contain the word Chapter or Appendix depending on which it is typesetting at the moment? \chaptername only seems to have the word "Chapter" even though I'm using it under the appendix section.

Edit: I've got it working in my chapter headers, thanks to answers below; but my TOC isn't working properly. I've changed my TOC with titletoc, and it still says "Chapter" even though I've got the following code:

\documentclass{book}
\usepackage{titletoc}
\usepackage{color}

\makeatletter
\titlecontents{chapter}[-2em]
{\@chapapp \contentslabel{-0.25em}\hspace{2em}}
{}
{\hspace{3em}\contentspage}
\makeatother

\begin{document}
\tableofcontents
\chapter{test}
\appendix
\chapter{asdf}
\end{document}

-
Unfortunately it's called \@chapapp so you need \makeatletter and \makeatother when using it. –  egreg Jan 31 '13 at 21:23

In the standard classes book and report, the \chapter command uses the internal command \@chapapp to typeset chapter headings. \@chapapp is initially defined as \chaptername ("Chapter"), and redefined to \appendixname ("Appendix") as soon as you issue \appendix in the document body.

In response to your follow-up question: Here's one (possibly not the most elegant) way to achieve correct naming in the ToC:

\documentclass{book}
\usepackage{titletoc}
\usepackage{color}

\makeatletter

\titlecontents{chapter}[-2em]
{\@chapapp \contentslabel{-0.25em}\hspace{2em}}
{}
{\hspace{3em}\contentspage}

}

\makeatother

\begin{document}
\tableofcontents
\chapter{test}
\appendix
\chapter{asdf}
\end{document}

-
\@chapapp indeed works for my custom header. Thanks. But how can I get it to show in my TOC as well? I've modified the TOC with titletoc and even though I've surrounded my code with \makeatletter and \makeatother, it still says "Chapter". –  agent154 Jan 31 '13 at 21:33
Do you know how I could redefine \appendix to have \switchchapapp get fired in that? I'd like to make this work without having to get another user to use esoteric commands. –  agent154 Jan 31 '13 at 22:47
@agent154 My bad -- answer improved. –  lockstep Jan 31 '13 at 23:26
That works beautifully. Thanks. –  agent154 Jan 31 '13 at 23:36

If you use titlesec, then the command you look for is \chaptertitlename that defaults to \chaptername, but it is \appendixname in the appendix.

-