The code for the book
document class defines \tableofcontents
as:
\newcommand\tableofcontents{%
\if@twocolumn
\@restonecoltrue\onecolumn
\else
\@restonecolfalse
\fi
\chapter*{\contentsname
\@mkboth{%
\MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
\@starttoc{toc}%
\if@restonecol\twocolumn\fi
}
The first bit, \if@twocolumn ... \fi
switches to one column mode in case you are using the twocolumn
document class option. You probably don't want that if you want the contents to be part of the running text, so we can rule that out. This also allows us to remove the \if@restonecol\twocolumn\fi
at the end, which switches back to \twocolumn
if that's the case.
Next we have \chapter*{...}
. This adds the chapter heading to the table of contents. You specifically asked to remove that, so... The \@mkboth
in the \chapter*
is responsible for the page headings saying TABLE OF CONTENTS
. If you don't have a Table of contents chapter, you probably don't want that too, so we can rule it out.
We are now left with \@starttoc{toc}
. This command basically does \@input{\jobname.toc}
, so that's what we're looking for :)
Putting it in a document:
\documentclass{book}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\makeatletter
\@starttoc{toc}
\makeatother
\lipsum[2]
\chapter{Chapter 1}
\chapter{Chapter 2}
\end{document}
the first page shows
If you examine the .toc
file you'll see it contains
\contentsline {chapter}{\numberline {1}Chapter 1}{3}
\contentsline {chapter}{\numberline {2}Chapter 2}{5}
Writing this directly to the .tex
file would've worked as well.
Also, the \contentsline{chapter}
command does \l@chapter
which, if you look in book.cls
you'll see it does a \vskip 1.0em \@plus\p@
before writing the content line. If you want to even the spacing before and after the \@starttoc
you can use this same space:
\documentclass{book}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\makeatletter
\@starttoc{toc}
\vskip 1.0em \@plus\p@
\makeatother
\lipsum[2]
\chapter{Chapter 1}
\chapter{Chapter 2}
\end{document}
\tableofcontents
macro. Can you provide a minimal working example (MWE), please?