I am trying to conditionally-print a List of Figures and List of Tables only when the relevant elements exist. (I started by modifying the solution to this question: Add list of figures/tables only when content)
The following code works for the List of Figures (the first three/last three lines exist because I am modifying an existing thesis class and attempting to make minimal changes; my contribution is the middle two):
\newif\if@figures
\@figurestrue
\def\listoffigures{
\newbox\tmpboxA\newbox\tmpboxB%
\setbox\tmpboxA\vbox{\makeatletter\@input{\jobname.lof}}\setbox\tmpboxB\vbox{Figure 1}%
\ifdim\ht\tmpboxA<\ht\tmpboxB\@figuresfalse\fi
\if@figures\chapter*{List of Figures\markboth
{LIST OF FIGURES}{LIST OF FIGURES}}\@starttoc{lof}\fi
}
However, doing the same for the List of Tables does not work:
\newif\if@tables
\@tablestrue
\def\listoftables{
\newbox\tmpboxA\newbox\tmpboxB%
\setbox\tmpboxA\vbox{\makeatletter\@input{\jobname.lot}}\setbox\tmpboxB\vbox{Table 1}%
\ifdim\ht\tmpboxA<\ht\tmpboxB\@tablesfalse\fi
\if@tables\chapter*{List of Tables\markboth
{LIST OF TABLES}{LIST OF TABLES}}\@starttoc{lot}\fi
}
I can see that this is because \jobname.lof is empty, while \jobname.lot contains six
\addvspace{10pt} (one for each chapter). Is there a way around this/a better way to handle this?
Edit: after cleaning out the directory, the problem seems to be that the \@starttoc command is responsible for generating the files \jobname.lof and \jobname.lot. So testing the size of the list can't work until \@starttoc is called?
.lofand.lotdiffer in the number of lines\addvspace{...}they contain, the class is corrupted since the files should be exactly the same in this manner; it's the top sectioning command (\chapteror\section) that inserts the space there (in both of them by default). Could you add a full MWE? – yo' Mar 12 '15 at 16:29