1

Verified, it does not have the answer in the linked post.

I would like to create table of contents based on chapters. When I insert command \tableofcontents almost at the top -- after opening document and making few definitions, as the result I get empty TOC (not desirable).

When I move it right before new chapter (as an experiment) and I get nothing -- i.e. no TOC at all (empty TOC has at least heading "Table of contents").

For example:

\tableofcontents 

\begin{verse}
some quote
\end{verse}

\def\enddoc{} 
\def\input#1{}

\include{intro1}
\include{intro2}

\chapter{Program} 

intro1 and intro2 are chapters written as separate files. This gives me empty TOC, when I move TOC before chapter "Program" TOC is not created.

I added usepackage with \usepackage{tocloft,calc} and \usepackage{titletoc}. No change at all?

What do I do wrong way?


Update

I found the culprit, but I don't know how to fix it. My entire document consists of several chapter (with bibliography), each chapter is written as separate file. The preamble is also saved as separate file.

What's important currently I can create each chapter as separate pdf (on its own) -- because each chapter includes preamble, not only the main .tex file.

In the main .tex file I have such line:

\def\input#1{}

I don't know what it does (my mistake, I should I added explanation in comment), but it allowed me to build entire document so far.

When I tested it on the stripped sample .tex, removing it allows TOC to be created correctly, but when I comment it in my main document (not just sample) the compilation fails right from the beginning. First separate chapter file includes preamble (so the inclusion is from the middle of .tex file really) and I get error:

Can be used only in preamble. \documentclass

So, is it possible to build TOC nevertheless, or should I drop this separation if I want to create TOC?

  • 1
    to get anything in the table of contents, you need to run latex at least twice. (the first pass creates the entries in the .toc file and the second pass reads in and processes the .toc file.) if you run latex only once with a \tableofcontents command, you will get just the heading (as you did). and you don't want to delete the .toc file, as that is what contains the entries to be listed in the output. – barbara beeton Aug 09 '13 at 15:26
  • 1
    And just for information: tocloft and titletoc do nothing if you only add them to the preamble. They provide some useful commands to manipulate the TOC, but one has to use them :-) Moreover calc does not fit here at all here because it helps LaTeX to do arithmetics. Finally \usepackage{tocloft,calc} and \usepackage{titletoc} is equivalent to \usepackage{tocloft,calc,titletoc}. – Ruben Aug 09 '13 at 15:47
  • @barbarabeeton, I use Kile with pdflatex. I checked the man page for pdflatex but I don't see an option to make it run twice. – greenoldman Aug 09 '13 at 17:03
  • 2
    No, you just have to actually run it twice. I.e., hit Alt + 6 in Kile, wait until the process finishes, and hit Alt + 6 again. – Torbjørn T. Aug 09 '13 at 18:29
  • @TorbjørnT., then I am in trouble, because I already did it, each time I have empty .toc file. And I see such message " old toc file detected, not used; run LaTeX again." – greenoldman Aug 09 '13 at 18:34

1 Answers1

3

The warning message

old toc file detected, not used; run LaTeX again

comes from package hyperref.

If you get the warning again after running LaTeX twice, then \nofiles might be active that prevents the rewriting of the auxiliary files. Or the search path for TeX files is messed up and a .toc file from a different project is found. However the title of the table of contents is set in either case. Both speculations explain an empty table of contents. No table of contents at all is caused by a different issue.

Thus, generate a complete minimal working example (MWE)!. It should show the relevant packages, e.g. hyperref, the document class and relevant code before/after \tableofcontents; but keep it minimal.

Heiko Oberdiek
  • 271,626
  • Thank you very much. Following your instruction I found the problem, but since the explanation is rather lengthy, I updated my question. – greenoldman Aug 11 '13 at 15:45