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 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?

share|improve this question
    
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
    
Thanks, i will follow this tip. –  SadChi Mar 14 '12 at 10:37

1 Answer 1

up vote 5 down vote accepted

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:

 \setcounter{tocdepth}{2}
\newcommand\tableofcontents{%
    \if@twocolumn
      \@restonecoltrue\onecolumn
    \else
      \@restonecolfalse
    \fi
    \chapter*{\contentsname
        \@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
    \@starttoc{toc}%
    \if@restonecol\twocolumn\fi
    }
\newenvironment{theindex}
   {\if@twocolumn
      \@restonecolfalse
      \else
         \@restonecoltrue
      \fi
      \twocolumn[\@makeschapterhead{\indexname}]%
      \@mkboth{\MakeUppercase\indexname}%
              {\MakeUppercase\indexname}%
                \thispagestyle{plain}\parindent\z@
                \parskip\z@ \@plus .3\p@\relax
                \columnseprule \z@
                \columnsep 35\p@
                \let\item\@idxitem}
      {\if@restonecol\onecolumn\else\clearpage\fi}
\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.

share|improve this answer
    
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

 
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.