I'm trying to create a custom class to replace the class book and need to include ToC functionality. Placing the command \tableofcontents leads to error "Undefined control sequence". Using packages like minitoc or tocloft doesn't help.

What should I write to my custom class to let ToC work?

  • Welcome to TeX.sx! A tip: You can use backticks ` to mark your inline code as I did in my edit. Also, we don't usually put a greeting or a "thank you" in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Upvoting is the preferred way here to say "thank you" to users who helped you. – doncherry Mar 14 '12 at 10:20

You should lift the minimum code from the book.cls, not guaranteed and I am not too sure what you are defining in your class but include as a minimum the following:

                \parskip\z@ \@plus .3\p@\relax
                \columnseprule \z@
                \columnsep 35\p@
\newcommand\@idxitem{\par\hangindent 40\p@} (*@\label{idxitem}@*)
\newcommand\subitem{\@idxitem \hspace*{20\p@}}
\newcommand\subsubitem{\@idxitem \hspace*{30\p@}}
\newcommand\indexspace{\par \vskip 10\p@ \@plus5\p@ \@minus3\p@\relax}

It is normally a better idea to load one of the standard classes in your own class definition so that at least your class inherits all the basic functionality. Many a time you only need a package rather than a class.

  • Thanks. I will try to load some class in my class and to twik functionality. – SadChi Mar 14 '12 at 10:46
  • 3
    @user12603 It is much easier to do it this way. Another class to copy functionality is octavo. It is very easy to understand what is going on and well documented in .dtx. – Yiannis Lazarides Mar 14 '12 at 10:49
  • Presumably you need a \newcounter{tocdepth} before the \setcounter line? – Seamus Mar 14 '12 at 14:08
  • @Seamus There is code all over the place, especially in section definitions, that is why I suggested to rather inherit a base class, which I think the OP accepted as the answer. – Yiannis Lazarides Mar 14 '12 at 14:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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