# etoc and memoir compatibility isuues

I was just doing some test with the etoc package and as soon as I changed the document class from book to memoir, errors appeared. This simple document

%\documentclass{book}
\documentclass{memoir}
\usepackage{etoc}

\begin{document}

\tableofcontents
\chapter{A test chapter}

\end{document}


triggers the error message

! Undefined control sequence.
<argument> \if@cftnctoc
\else \renewcommand *\etocstandarddisplaystyle {\eto...
l.1150      }


which indicates that \if@cftnctoc is not defined. I checked the code for etoc and in lines 1106 to 1124 (one can also see this in the page 88 of the package documentation), there are two uses of this command, but I couldn't figure out what the problem really was. The etoc documentation mentions that the package is compatible with memoir, so I am lost. Am I missing something?

Edit: this appears in the Foreword of etoc's documentation:

etoc appears to be (at least partially) compatible with the article, book, report, scrartcl, scrbook, scrreprt and memoir classes. Starting with release 1.07k it is possible to use etoc concurrently with package tocloft.

• The memoir class emulates tocloft (with differences) and, in order to avoid users load it, fakes it being loaded, so etoc gets confused. Unfortunately, \DisemulatePackage{tocloft} doesn't work. – egreg Apr 21 '14 at 20:54
• @egreg yes, that's what I suspected, but please see my edit (a little note in the Foreword of the package documentation). I guess something else is going on? – Gonzalo Medina Apr 21 '14 at 21:01
• If you add \newif\if@cftnctoc\@cftnctoctrue before loading etoc, it compiles. But I'm not sure what the implications of this are. if@cftnctoc appears to be defined by tocloft but not by memoir and you cannot load tocloft because memoir is emulating it... – cfr Apr 21 '14 at 21:06
• I guess that the fix for making etoc compatible with tocloft made it incompatible with memoir. However I found the same workaround as @cfr and motivated the reasons in my answer. – egreg Apr 21 '14 at 21:09
• @egreg I had the same reasons but you'd already posted them in a comment (but not yet posted the workaround)... – cfr Apr 21 '14 at 21:11

The memoir class emulates tocloft (with differences) and, in order to avoid users load it, fakes it being loaded, so etoc gets confused. In particular, tocloft defines

\newif\if@cftnctoc\@cftnctocfalse
\DeclareOption{titles}{\@cftnctoctrue}


So the conditional seems to be used only for the titles option, which has no meaning for memoir. My suggestion is to file a bug report and do

\documentclass{memoir}

\makeatletter
\let\if@cftnctoc\iftrue
\makeatother
\usepackage{etoc}

\begin{document}

\tableofcontents*
\chapter{A test chapter}

\end{document}


The titles option in tocloft makes it not override the code for chapter titles in the table of contents or similar lists, so I guess setting it to true is the right thing to do with memoir.

• release 1.07k improved a bit etoc compatibility with memoir, and then with tocloft but the developer did not re-test memoir after the latter :-(. Your analysis and work-around is correct: etoc tricks tocloft into believing it has been loaded with titles option. But this fails (and is unneeded) under memoir's emulated version of tocloft. Release 1.07l of etoc will be available on CTAN soon and fixes this issue and another similar one having with tocvsec2: the memoir emulated version does not need the work-arounds put into place by etoc for the original thing. – user4686 Apr 22 '14 at 20:29
• @jfbu It happens; only DPC's packages are bug free, they only have undocumented features. ;-) – egreg Apr 22 '14 at 20:41