Finally I have narrowed down the problem to a custom definition of a sectioning command using titlesec
in explicit mode. I suspect it has something to do with me not providing an adequate counter for etoc
.
The first run compiles as usual. The second run results in:
! Missing number, treated as zero. \Etoc@level l.27 \section {etoc} ?
Code
\documentclass{article}
\usepackage{fontspec}
%\usepackage{tocloft} % I use this package too.
\usepackage[explicit]{titlesec}
\usepackage{etoc}
%\usepackage{hyperref} % I use this package too.
%\let\tableofcontents\etoctableofcontents %counteract the overwriting by tocloft of \tableofcontents done at \begin{document} <--Do I need this?
% MINISECTION (Custom)
\titleclass{\minisec}{straight}[\paragraph]
\newcounter{minisec}
\titleformat{\minisec}[hang]{\normalsize\bfseries}{\theminisec}{0pt}{#1}% Change 0pt to a positive value once the representation for the counter has been established
\titlespacing*{\minisec}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\newcommand{\minisecautorefname}{minisec}
\setcounter{secnumdepth}{5}% minisecs will be numebered
\renewcommand\theminisec{}% Provisional empty definition for the counter representation
% Settings for the bookmarks and the ToC entries (change the second
% and third arguments of \@dottedtocline if minisecs should be in the ToC)
\makeatletter
\def\toclevel@minisec{5}
\def\l@minisec{\@dottedtocline{5}{3.8em}{3.2em}}
\makeatother
\begin{document}
\localtableofcontents
\section{etoc}
\minisec{Minisec Test}
\end{document}
\etocsetlevel{minisec}{5}
. – egreg Oct 25 '15 at 19:06