1

For big documents, I choose to use a master/slave structure.

Rather than play comment/uncomment the preamble of the slave code with the comment package and also the \end{document} (for avoid conflict once the slave code incorporate in his master with \input{slave.tex}) like I used to until now, I wish make a group of instruction for a "special" MWE.tex who can automatically be incorporated in a other MWE.tex or in the master code with \input{} but without the obligation to play with % every time I want to compile a slave code, following this exemple :

\makeatletter
\@ifundefined{ifmaster}
    {\expandafter\newif\csname ifmaster\endcsname
    \masterfalse}
    {\mastertrue}
\makeatother

\ifmaster \begin{comment} \else \fi

\documentclass{memoir}

\begin{document}

\ifmaster \end{comment} \else \fi

INPUT TEST

\ifmaster \else \end{document} \fi

At this point, it work pretty well when I put the condition \mastertrue after \newif\ifmaster in the preamble of the master code. Everything is "automatic", I just have to compile the master with the incorporated slaves codes or the slave only to produce the document and I don't have to play anymore with % to comment the preamble of the slave code.
But, once I want make two levels of slave with \input{slave_in_slave}, like the following exemple, I have this error :

! Emergency stop.
<*> test_inclusion.tex
*** (job aborted, no legal \end found)

I know that is the \end{document} who messes in the process, and this is why I ask you to help me on that (or maybe is there a cleaner way to automate the compilation of slave code).

I precise that the input code test_inclusion_inclusion have exactly the same MWE.tex than the first and I want to have only one MWE.tex for all the purpuses :

\makeatletter 
\@ifundefined{ifmaster}
    {\expandafter\newif\csname ifmaster\endcsname
    \masterfalse}
    {\mastertrue}
\makeatother

\ifmaster \begin{comment} \else \fi

\documentclass{memoir}

\begin{document} %

\ifmaster \end{comment} \else \fi

INPUT TEST

\input{test_inclusion_inclusion}

\ifmaster \else \end{document} \fi

Thanks for your help !

  • Things inside a comment environment are not “seen”, s your \ifmaster is lost. Use \includecomment and \excludecomment, like in this answer – Phelype Oleinik Apr 18 '21 at 19:08
  • This is the purpose of the use of \begin{comment}, I want the preamble automatically in comment when I incorporate the slave code in his master. The problem with \includecomment is that it require the comment package and for isolate a complete preamble (with \documentclass), I can only use \newif – Bruno Douchy Apr 18 '21 at 19:29
  • combining skipping with iffalse and with comment is rather odd, when ifmaster is true you do begin{comment} so the apparently matching \fi is skipped and everything skipped until the \end{comment} then the \fi after that finally matches the first \if why not _justuse\ifmaster` and not use comment at all? – David Carlisle Apr 18 '21 at 22:33
  • The begin doesn't need this complicated setup. You only need a command for the preamble which redefines itself to a no-op after the first use. But the end needs to keep track of the nesting level of the files (assuming that you want to support more than one nesting level), and for this you need a counter or some other stack so that you can identify the last \end{document} of level 0. – Ulrike Fischer Apr 19 '21 at 06:49
  • I found a better way, far far far simpler. I use the docmute package, which does exactly the job I wished to without adding a line of code over a simple MWE ! – Bruno Douchy Apr 21 '21 at 09:47

0 Answers0