Generaltitlesec and minitoc *can* get along!

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
herenvardo
Posts: 6
Joined: Sat May 02, 2009 2:24 pm

titlesec and minitoc *can* get along!

Post by herenvardo »

Note: when I started writing this post, it was in question form. As I tried to provide as many details as possible about the issue, I ended up gathering enough details to find a solution (work-around would be more appropriate) on my own. Since I couldn't manage to find anything like this on the web, I thought I could share my solution for others who try something similar. If this helps even a single user, it will have been worth posting it.

I know they are incompatible, and I more or less understand why. The thing is, they address two things I needed to achieve in a document I'm working on, so I had to find an alternative to either of the packages or a way to make both things work together.

My document (book class, over thousand pages) is split in a few parts and many chapters. For convenience and sanity, I wanted to put a brief ToC listing the parts and their chapters, and then a deeper ToC within each part listing its chapters, sections, and subsections. I am using the shorttoc package for the brief ToC, minitoc's \faketableofcontents command to ensure the .toc file is generated, and the \parttoc command on each part. At this point, things still went fine.

Now titlesec came to the scene: I have customized chapter, section, subsection, and so on with \titleformat, and things still went fine.
But that wasn't enough: I went into customizing the part titles to include a "cover image" on the title page, moving the title itself upwards (actually, I had to get help from this community to achieve that: http://www.latex-community.org/forum/vi ... =44&t=6752), and here is where things broke: as soon as the \titleformat{\part} command was added, the parts' ToCs no longer appear. Quite reasonable that the parts' ToCs break when I start messing with parts, but still a problem nevertheless, because the document needs both features.

I looked deeper at the issue, and noticed that the .ptc<N> files got generated and the contents in them seemed to make sense (I don't really understand all the commands in there, but the titles and numbers of my chapters and deeper divisions appeared there); so my guess is that only the \parttoc breaks because minitoc can't figure out where to put the ToC. It seemed that everything worked fine except for the last detail of rendering the part ToCs, and I thought: if everything else is already done, couldn't I handle that small but critical detail?

Since the .ptc<N> files are there, I bet it should be possible to forget about \parttoc and use all the stuff minitoc has already generated directly. It didn't took too much after that point: a test with

Code: Select all

input{\jobname.ptc\arabic{part}}
got things close to working: to my amusement, the .ptc's included an almost ready-to-use ToC for the relevant part, but lots of @-stuff were crowding it and the page numbers didn't show up. A bit of googling after, I was replacing all \parttoc commands in my project with a custom \PToC, and I had added this on my preamble:

Code: Select all

\newcommand{\PToC} {%
\makeatletter%
{\Large Table of Contents}

\input{\jobname.ptc\arabic{part}}%
\cleardoublepage%
\makeatother%
}
The \makeatletter and \makeatother commands solve the issue of the @-stuff mess-up; and I added a simple title before and a \cleardoublepage after the ToC to round things up.
I guess I could have used \renewcommand{\parttoc} instead of a brand new command, but I don't like altering commands written by third parties, and I like to have a weird-looking command like \PToC to remind myself of where I'm messing things up.

The formatting of the title is very basic, but the main task (rendering the "local" ToC) is done, and formatting details, while probably tedious on most cases, are not really an issue.

Regards,
Herenvardo

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Post Reply