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 astonished how good and informational this site is. However, I was unable to find an answer to the following problem:

Background: I'm working on a book for IOS-press, and my first chapter is built with the class IOS-Book-Article. It has bunch of definitions required by publisher, but it forbids making a TOC. I need it for checking and draft working, also for my co-authors.

Problem: I'm unable to run pdflatex on my tex document, because it says \tableofcontents is undefined. Also the toc file is 0 size.

The error message:

! Undefined control sequence.
l.20 \tableofcontents

My TEX source:

\documentclass[secfloat,final]{IOS-Book-Article}
% our definitions and macros
\input{macros.tex}
\makeindex
\begin{document}
\tableofcontents
..... the rest of doc

Question: How to make table of contents in this document class? I need only draft version, nothing fancy, only sections/sub/subsub and chapters, with page numbers for revision.

My investigation: The class can be found on IOS Author Corner, but I give here only an url (it's too long to copy): http://www.iospress.nl/authco/iospressbookarticle-latex.zip (direct url, sorry). I've found that in this class there are some defs for:

% Block preparation of contents:
\def\addcontentsline#1#2#3{}
\long\def\addtocontents#1#2{}

which I commented out, but it don't help. There is no \tableofcontents definition inside this class. I've copied one found in default book.cls class, but it didn't work, saying that some variables are empty and then set to 0. Nevertheless, I was unable to got anything similar to toc and I'm too beginner to make my own class.

Please, how to manage to do this?

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Nothing fancy ... just copy-and-paste of the relevant macro definitions from the LaTeX sources and from article.cls.

\documentclass{IOS-Book-Article}

\makeatletter

% Copied from the LaTeX sources
\def\addcontentsline#1#2#3{%
  \addtocontents{#1}{\protect\contentsline{#2}{#3}{\thepage}}}
\long\def\addtocontents#1#2{%
  \protected@write\@auxout
    {\let\label\@gobble \let\index\@gobble \let\glossary\@gobble}%
    {\string\@writefile{#1}{#2}}}

% Copied from article.cls
\newcommand\@pnumwidth{1.55em}
\newcommand\@tocrmarg{2.55em}
\newcommand\@dotsep{4.5}
\setcounter{tocdepth}{3}
\newcommand\tableofcontents{%
    \section*{\contentsname
        \@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
    \@starttoc{toc}%
    }
\newcommand*\l@section[2]{%
  \ifnum \c@tocdepth >\z@
    \addpenalty\@secpenalty
    \addvspace{1.0em \@plus\p@}%
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode \bfseries
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      #1\nobreak\hfil \nobreak\hb@xt@\@pnumwidth{\hss #2}\par
    \endgroup
  \fi}
\newcommand*\l@subsection{\@dottedtocline{2}{1.5em}{2.3em}}
\newcommand*\l@subsubsection{\@dottedtocline{3}{3.8em}{3.2em}}
\newcommand*\l@paragraph{\@dottedtocline{4}{7.0em}{4.1em}}
\newcommand*\l@subparagraph{\@dottedtocline{5}{10em}{5em}}
\newcommand\listoffigures{%
    \section*{\listfigurename}%
      \@mkboth{\MakeUppercase\listfigurename}%
              {\MakeUppercase\listfigurename}%
    \@starttoc{lof}%
    }
\newcommand*\l@figure{\@dottedtocline{1}{1.5em}{2.3em}}
\newcommand\listoftables{%
    \section*{\listtablename}%
      \@mkboth{%
          \MakeUppercase\listtablename}%
         {\MakeUppercase\listtablename}%
    \@starttoc{lot}%
    }
\let\l@table\l@figure
\newcommand\contentsname{Contents}
\newcommand\listfigurename{List of Figures}
\newcommand\listtablename{List of Tables}

\makeatother

\begin{document}

\tableofcontents

\section{foo}

\subsection{bar}

Some text.

\end{document}

EDIT: Removed definition of \l@part because IOS-Book-Article doesn't feature a \part command.

share|improve this answer
    
WOW, you've made my day! It is PERFECT solution, works like charm! Thank you. Now I have not only table of contents, but beautiful table of contents! :) –  piotao Jul 20 '11 at 9:18
add comment

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.