My master file is not able to call subfiles (using input)
which contain code to print a partial table of contents.
I run subfiles using the standalone package.
The subfile, when run standalone works fine.
The following line of code generates an undescriptive error message:
\printcontents[Scripts]{}{1}{ \subsection*{List of Contents} } \clearpage
I know that the \printcontents command gives me trouble
if the subfile has not been run standalone at least once
without the \printcontents command.
(Effectively, \startcontents and optionally \stopcontents
must have already generated a partial toc file for \printcontents
to not produce an error.)
I am wondering if the \printcontents command generates an error
because it cannot find the partial toc file when run from the master file.
(The master file is in a higher-level parent directory.)
If this is the problem:
Is it possible to include a relative directory
along with the partial toc filename within the \printcontents command?
MWE
masterFile.tex:
%! arara: lmkclean
%! arara: pdflatex: { draft: yes }
%! arara: bibtex
% arara: pdflatex: { draft: yes }
% arara: pdflatex: { synctex: yes }
% arara: lmkclean
\documentclass[crop=false,float=true,class=scrartcl]{standalone}
\providecommand{\main}{.}
\input{\main/Subfiles/Preamble.tex} % Preamble [document configuration]
\begin{document}
\addcontentsline{toc}{section}{List of Contents} \tableofcontents \clearpage
\input{\main/Subfiles/2-Main/child1.tex}
\textbf{\LARGE{Appendices}}
\addappheadtotoc
\begin{appendices} \clearpage
\input{\main/Subfiles/3-Append/childA.tex}
\end{appendices}
\end{document}
Subfiles/Preamble.tex:
% meta tools
\usepackage{standalone} % allows for independent runs of subfiles.
% layout: page/spacing/headings
\usepackage{scrlayer-scrpage} % improved header commands. [supercedes `fancyhdr' package].
\usepackage{appendix} % appendices.
% references
\usepackage{titletoc} % allows sub-[tables of contents]. [breaks \section* commands. use \setcounter{secnumdepth}{0} instead.]
Subfiles/2-Main/child1.tex:
%! arara: lmkclean
%! arara: pdflatex: { draft: yes }
%! arara: bibtex
% arara: pdflatex: { draft: yes }
% arara: pdflatex: { synctex: yes }
% arara: lmkclean
\documentclass[crop=false,float=true,class=scrartcl]{standalone}
\providecommand{\main}{../..}
\input{\main/Subfiles/Preamble.tex} % Preamble [document configuration]
\begin{document}
\section{Section 1} \clearpage
\subsection{Subsection 1.1} \clearpage
\subsection{Subsection 1.2} \clearpage
\section{Section 2} \clearpage
\subsection{Subsection 2.1} \clearpage
\subsection{Subsection 2.2} \clearpage
\end{document}
Subfiles/3-Append/childA.tex:
%! arara: lmkclean
%! arara: pdflatex: { draft: yes }
%! arara: bibtex
% arara: pdflatex: { draft: yes }
% arara: pdflatex: { synctex: yes }
% arara: lmkclean
\documentclass[crop=false,float=true,class=scrartcl]{standalone}
\providecommand{\main}{../..}
\input{\main/Subfiles/Preamble.tex} % Preamble [document configuration]
\begin{document}
\startcontents[appendices]
\IfFileExists{\main/Subfiles/3-Append/childA.ptc}{
\printcontents[appendices]{}{1}{ \subsection*{List of Contents} } \clearpage
}{}
\section{Section A} \clearpage
\subsection{Subsection A.1} \clearpage
\subsection{Subsection A.2} \clearpage
\section{Section B} \clearpage
\subsection{Subsection B.1} \clearpage
\subsection{Subsection B.2} \clearpage
\stopcontents[appendices]
\end{document}
.
.
.
Digression:
Does anyone know of a method to not run \printcontents
if the .toc file which printcontents is seeking does not exist?
[Answer]: (per @ChristianHupfer. Give him +1 in the comments.)
\IfFileExists{yourlocaltocfilename}{\printcontents....}{}
\IfFileExists{yourlocaltocfilename}{\printcontents....}{}perhaps? – Aug 12 '16 at 16:02\IfFileExistsis a LaTeX 'core' command (defined inlatex.ltx) -- it's always there until someone screws it up by accident ;-) -- Don't forget the third{}pair, however! – Aug 12 '16 at 16:05childA.ptcexists, it is found by the parent and by the child, and a partial toc appears as intended. If the.ptcdoes not exist, however, the master does not create one. – kando Aug 18 '16 at 17:14hyperrefbeforetitletoc. I think I read some that I should always loadhyperreflast; is that a golden rule of latex? – kando Aug 22 '16 at 18:12cleverefafterhyperref, ifcleverefis needed ;-) – Aug 22 '16 at 18:13.ptcfile needed to be deleted whenever commenting out / shifting around packages. This led to a lot of false errors. I think I tried thehyperrefsolution previously; however, the problem persisted because the old.ptcremained, causing a similar error. – kando Aug 22 '16 at 18:18babeletc. settings ;-) All very well-known features of LaTeX ;-) – Aug 22 '16 at 18:19