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....}{}  
kando
  • 1,338
  • 3
    \IfFileExists{yourlocaltocfilename}{\printcontents....}{} perhaps? –  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! –  Aug 12 '16 at 16:05
  • @ChristianHupfer Alright. So, that definitely fixes the comment, run, uncomment, run issue. Master file still errors out. Which is weird. It's like the master file searches for the .ptc file in its own folder, but it must generate the .ptc in the subfile's folder since it doesn't create one for itself. – kando Aug 12 '16 at 16:17
  • 1
    Perhaps you should post a version of your file such that it is compilable. –  Aug 12 '16 at 17:49
  • @ChristianHupfer MWE provided as requested. – kando Aug 18 '16 at 17:06
  • @ChristianHupfer The question has changed slightly: With the MWE provided, if childA.ptc exists, it is found by the parent and by the child, and a partial toc appears as intended. If the .ptc does not exist, however, the master does not create one. – kando Aug 18 '16 at 17:14
  • Your setup requires us to use explicitly your directory tree :-( This is tedious –  Aug 18 '16 at 18:30
  • @ChristianHupfer Apologies. I had assumed you wanted the other way, but the problem went away in that format. I recreated the original setup and ultimately found that it was because I loaded hyperref before titletoc. I think I read some that I should always load hyperref last; is that a golden rule of latex? – kando Aug 22 '16 at 18:12
  • Yes, that's the golden rule, only to be ruled out by the platinum rule of LaTeX: Use cleveref after hyperref, if cleveref is needed ;-) –  Aug 22 '16 at 18:13
  • @ChristianHupfer As an added note: the .ptc file needed to be deleted whenever commenting out / shifting around packages. This led to a lot of false errors. I think I tried the hyperref solution previously; however, the problem persisted because the old .ptc remained, causing a similar error. – kando Aug 22 '16 at 18:18
  • 1
    Yes I know, as well as with babel etc. settings ;-) All very well-known features of LaTeX ;-) –  Aug 22 '16 at 18:19
  • @ChristianHupfer "features" :/ – kando Aug 22 '16 at 18:28

1 Answers1

0

Loading hyperref before titletoc will cause issues.

Always load hyperref last.

kando
  • 1,338
  • 1
    Not always: https://tex.stackexchange.com/questions/1863/which-packages-should-be-loaded-after-hyperref-instead-of-before :) – cmhughes Nov 23 '17 at 09:00