1

I have a problem regarding toggles created with the package etoolbox and subfiling via subfiles. I would like to make some minor changes to the output every time I compile a subfile. A toggle seems an appropiate solution for this. Here my MWE:

For the main file:

\documentclass{scrbook}

\usepackage{subfiles}
\usepackage{etoolbox}

\newtoggle{documentsplit}

\begin{document}

\subfile{chap1/chap1}

\end{document}

For the subfile:

\documentclass[../Main]{subfiles}

\settoggle{documentsplit}{true}

\begin{document}

\iftoggle{documentsplit}
    {\chapter{The document ist split}}
    {\chapter{The document is complete}}

\end{document}

I receive the same output with the mainfile and with the subfile (»The document is split«) which indicates that the toggle is activated in some way when I run the main file, even though it stands before \begin{document}.

I have two questions:

  1. How can I receive the output »The document is complete« when running the main file?
  2. How come the toggle is activated? The subfiles-documentation states clearly that this should not be the case.

A little background: I am typesetting an edition which contains collected articles by the same author. The idea is, in the end, to offer single articles and the complete work. When offering single articles, it is necessary to place the name of the author somewhere prominently, for example below the chapter-heading. In the complete book this is not necessary, as the author is evident. The same goes for copyright-information etc.

Thank you for your help.

2

subfiles does use anything that is in the preamble from the main file when compiling the sub file, but the same is true the other way round for the compilation run of the main file.

The documentation of subfiles and its codes reveal that \skip@preamble does only redefine \documentclass and \relaxing \document and \enddocument, so any statement in the preamble of the sub file like \settoggle will enter the compilation of the main file as well, meaning that documentsplit is true then.

Here's a slightly different approach, by checking in the main file whether the class is subfiles or not. In the first case, set the switch to true, otherwise explicitly set it to false (just in case it has been set to true accidentally somewhere before)

\documentclass{scrbook}

\usepackage{etoolbox}
\newtoggle{documentsplit}
\usepackage{subfiles}

\makeatletter
\@ifclassloaded{subfiles}{%
  \toggletrue{documentsplit}
}{\togglefalse{documentsplit}}
\makeatother

\begin{document}


\subfile{chap1/chap1}

\end{document}

chap1.tex

\documentclass[../Main]{subfiles}


\begin{document}

\iftoggle{documentsplit}
{\chapter{The document ist split}}
{\chapter{The document is complete}}
\end{document}

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.