[Tex/LaTex] Minitoc is not updating itself

minitoctable of contents

The following MWE utilises minitoc.

\documentclass[a4paper]{book}
\usepackage{lipsum}
\usepackage{hyperref}

\usepackage{minitoc}
\dominitoc

\begin{document}
\include{TOC}
\include{chap1}
\include{chap2}
\end{document}

TOC.tex:

\tableofcontents

Chap1.tex:

\chapter{One}
\minitoc

\section{One One}
\lipsum[1-10]

\section{One Two}
\lipsum[20-30]

Chap2.tex:

\chapter{Two}
\section{Two One}
\section{Two Two}
\minitoc

\lipsum[2]

It works fine as expected and mini tocs are created. However, the problem starts when \includeonly{chap1}, as an example, is used. The minitoc for chap1.tex does not update itself when additional sections are added to the file. Also when I run the following command from terminal:

pdflatex -jobname=thechap01 "\includeonly{chap1}\input{tmp}"

I get the following error.

This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012/Debian)
 restricted \write18 enabled.
entering extended mode
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, et
hiopic, farsi, arabic, pinyin, croatian, bulgarian, ukrainian, russian, slovak,
 czech, danish, dutch, usenglishmax, ukenglish, finnish, french, basque, ngerma
n, german, swissgerman, ngerman-x-2012-05-30, german-x-2012-05-30, monogreek, g
reek, ibycus, ancientgreek, hungarian, bengali, tamil, hindi, telugu, gujarati,
 sanskrit, malayalam, kannada, assamese, marathi, oriya, panjabi, italian, lati
n, latvian, lithuanian, mongolian, mongolianlmc, nynorsk, bokmal, indonesian, e
speranto, coptic, welsh, irish, interlingua, serbian, serbianc, slovenian, friu
lan, romansh, estonian, romanian, armenian, uppersorbian, turkish, afrikaans, i
celandic, kurmanji, polish, portuguese, galician, catalan, spanish, swedish, th
ai, loaded.
(./tmp.tex (/usr/share/texlive/texmf-dist/tex/latex/base/book.cls
Document Class: book 2007/10/19 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/bk10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/lipsum/lipsum.sty)
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/hobsub-hyperref.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/hobsub-generic.sty))
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texlive/texmf-dist/tex/generic/ifxetex/ifxetex.sty)
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/kvoptions.sty)
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/pd1enc.def)
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/hyperref.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/url/url.sty))

Package hyperref Message: Driver (autodetected): hpdftex.

(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hpdftex.def
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/rerunfilecheck.sty))
(/usr/share/texlive/texmf-dist/tex/latex/minitoc/minitoc.sty
(/usr/share/texlive/texmf-dist/tex/latex/minitoc/mtcmess.sty) (./thechap01.mtc0
) (/usr/share/texlive/texmf-dist/tex/latex/minitoc/english.mld)
(/usr/share/texlive/texmf-dist/tex/latex/minitoc/english.mld)) (./thechap01.aux
 (./TOC.aux) (./chap1.aux) (./chap2.aux))
(/usr/share/texlive/texmf-dist/tex/latex/hyperref/nameref.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/gettitlestring.sty))
(./thechap01.out) (./thechap01.out)

Package minitoc(hints) Warning: W0030
(minitoc(hints))                --- The \part command is altered 
(minitoc(hints))                after minitoc.


Package minitoc(hints) Warning: W0023
(minitoc(hints))                --- It may be the consequence 
(minitoc(hints))                of loading the ``hyperref'' package.


Package minitoc(hints) Warning: W0028
(minitoc(hints))                --- The \chapter command is altered 
(minitoc(hints))                after minitoc.


Package minitoc(hints) Warning: W0023
(minitoc(hints))                --- It may be the consequence 
(minitoc(hints))                of loading the ``hyperref'' package.


! LaTeX Error: No counter 'Hy@AnnotLevel' defined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.12 \include{TOC}

? x
No pages of output.
Transcript written on thechap01.log.

Any help is appreciated.

Best Answer

In your current set up the \tableofcontents command is not called when you invoke \includeonly{chap1} because you have hidden it in TOC.tex.

If you simplify your document slightly to

...
\begin{document}
\tableofcontents
\include{chap1}
\include{chap2}
\end{document}

then the \tableofcontents command is called every time, and your .toc and minitoc files will be updated as you wish.