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 !
\ifmasteris lost. Use\includecommentand\excludecomment, like in this answer – Phelype Oleinik Apr 18 '21 at 19:08\begin{comment}, I want the preamble automatically in comment when I incorporate the slave code in his master. The problem with\includecommentis that it require thecommentpackage and for isolate a complete preamble (with\documentclass), I can only use\newif– Bruno Douchy Apr 18 '21 at 19:29\fiis skipped and everything skipped until the\end{comment}then the\fiafter that finally matches the first\ifwhy not _justuse\ifmaster` and not use comment at all? – David Carlisle Apr 18 '21 at 22:33docmutepackage, which does exactly the job I wished to without adding a line of code over a simpleMWE! – Bruno Douchy Apr 21 '21 at 09:47