1

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....}{}  
  • 3
    \IfFileExists{yourlocaltocfilename}{\printcontents....}{} perhaps? – user31729 Aug 12 '16 at 16:02
  • @ChristianHupfer Awesome. No more needing to comment, then run, then uncomment, then run. And I'll be able to verify whether the parent file is able to see the file. [Does that require any specific package?] – kando Aug 12 '16 at 16:04
  • 2
    No, \IfFileExists is a LaTeX 'core' command (defined in latex.ltx) -- it's always there until someone screws it up by accident ;-) -- Don't forget the third {} pair, however! – user31729 Aug 12 '16 at 16:05
  • 1
    Perhaps you should post a version of your file such that it is compilable. – user31729 Aug 12 '16 at 17:49
  • 1
    Yes I know, as well as with babel etc. settings ;-) All very well-known features of LaTeX ;-) – user31729 Aug 22 '16 at 18:19
0

Loading hyperref before titletoc will cause issues.

Always load hyperref last.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.