A table of contents (ToC) is produced by inserting \tableofcontents
at the appropriate place in your document.
\documentclass{book}
\begin{document}
\tableofcontents
\chapter{(Chapter Name)}
\section{Real Analysis}
\section{Role of LUB Axiom}
\end{document}
Note that you need at least two LaTeX runs to produce the ToC (LaTeX collects the data for the ToC in the first run and typesets it in the second run). If the ToC itself comprises several pages, a third LaTeX run may be necessary to get the ToC's page references right.
Here are two answers. (You've already said you don't like the second one; I'm leaving it because someone might find it useful some day.)
First:
With this TeX
source
\documentclass{book}
\usepackage{etoolbox}
\newtoggle{volumeone}
%\toggletrue{volumeone}
\togglefalse{volumeone}
\iftoggle{volumeone}{
\includeonly{ch1,ch2}
}{
\includeonly{ch2,ch3}
}
\begin{document}
\tableofcontents
\include{ch1} % \chapter{one} contents
\include{ch2} % \chapter{two} contents
\include{ch3} % \chapter{three} contents
\end{document}
run pdflatex
several times (to stabilize all references). Here is book.toc
:
\contentsline {section}{\numberline {1.1}one}{4}
\contentsline {section}{\numberline {1.2}two}{4}
\contentsline {chapter}{\numberline {2}two}{5}
\contentsline {section}{\numberline {2.1}one}{5}
\contentsline {section}{\numberline {2.2}two}{5}
\contentsline {chapter}{\numberline {3}three}{7}
\contentsline {section}{\numberline {3.1}one}{7}
\contentsline {section}{\numberline {3.2}two}{7}
Edit that file, to remove the first two lines (all the references to Chapter one). Then rerun pdflatex
once.
This works for me on Windows 7,
$ pdflatex -version
MiKTeX-pdfTeX 2.9.4535 (1.40.13) (MiKTeX 2.9)
since pdflatex
hasn't noticed that the toc
file is out of date.
You could automate this workflow with a shell script or batch file, using perl
or python
or awk
to edit the toc
.
Second: pagination is right but lots of other things need fixing - headers, chapter counters, references ... . I don't know how.
\documentclass{book}
\usepackage{etoolbox}
\newtoggle{volumeone}
\toggletrue{volumeone}
%\togglefalse{volumeone}
\iftoggle{volumeone}{
\includeonly{ch1,ch2,ch3}
}{
\includeonly{ch3,ch4}
}
\newcommand{\tocline}[1]{%
\addcontentsline{toc}{chapter}{#1}
}
\newcommand{\mychapter}[1]{%
%do everything the actual \chapter
%command does except enter a line in
%the table of contents
}
\newcommand{\mysection}{%
%check volumeone toggle, omit from toc as approprate
}
\begin{document}
\tableofcontents
\mychapter{one}
\iftoggle{volumeone}{\tocline{one}}{}
\include{ch1} % contents of chapter one in ch1.tex
\mychapter{two}
\iftoggle{volumeone}{\tocline{two}}{}
\include{ch2}
\mychapter{three}
\tocline{three} % in both volumes
\include{ch3}
\mychapter{four}
\iftoggle{volumeone}{}{\tocline{four}}
\include{ch4}
\end{document}
toggle the toggle
Best Answer
Hey this should get the job done. I would like to work on one thing, however.
I will update this code when I find a better solution.