Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to redefine the \appendix command so that my appendix headings go to the top of the pages. To do this, I tried the following code, but I get the error ! Illegal parameter number in definition of \appendix. Why am I getting this error and how to get rid of it?

\documentclass{book}
\makeatletter
\renewcommand\appendix{\par
\def\@makechapterhead#1{%
  \vspace*{0\p@}%
  {\parindent \z@ \raggedright \normalfont
    \ifnum \c@secnumdepth >\m@ne
      \if@mainmatter
        \huge\bfseries \@chapapp\space \thechapter
        \par\nobreak
        \vskip 20\p@
      \fi
    \fi
    \interlinepenalty\@M
    \Huge \bfseries #1\par\nobreak
    \vskip 40\p@
  }}
  \setcounter{chapter}{0}%
  \setcounter{section}{0}%
  \gdef\@chapapp{\appendixname}%
  \gdef\thechapter{\@Alph\c@chapter}}
\makeatother
\begin{document}
\appendix
\chapter{Foo}
\end{document}

Please keep in mind that, I know that a solution is to put the redefinition of the \@makechapterhead at the beginning of the \appendix command in the document body, but I want to do the job in the preamble. Also, I'd prefer not to use extra packages to do the job.

share|improve this question

1 Answer 1

up vote 6 down vote accepted

Inside the definition of \appendix, #1 would be the first parameter of \appendix that does not exists, \appendix is defined without parameters. For the parameters of a definition inside a definition you need to double the hash char:

\renewcommand\appendix{\par
  \def\@makechapterhead##1{%
    ... ##1 ...
  }%
  ...
}

If \@makechapterhead contained another definition with a parameter, then #### would be needed for the inner parameter.

share|improve this answer
    
This really helped me with the todonotes package. If you want \todo{Here is some \lstinline{SomeClass#SomeMethod}}, you have to escape the # or todonotes gets confused e.g. \todo{Here is some \lstinline{SomeClass\#SomeMethod}}. HTH future travelers –  Hamy Aug 26 '13 at 14:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.