Doing multiple call to include only as:
\includeonly{myfirstinclude}
\includeonly{mysecondinclude}
It is only including the last file called mysecondinclude
by the last \includeonly
call. It is useful to do multiple calls to \includeonly
when you have all your \includeonly
call listed and commented out.
\documentclass{article}
% How does 'filecontents' keep LaTeX parsing while temporarily stop writing output
% https://tex.stackexchange.com/questions/104159/how-does-filecontents-keep-latex
\usepackage{filecontents}
\begin{filecontents*}{myfirstinclude.tex}
myfirstinclude
\end{filecontents*}
\begin{filecontents*}{mysecondinclude.tex}
mysecondinclude
\end{filecontents*}
\begin{filecontents*}{mythirdinclude.tex}
mythirdinclude
\end{filecontents*}
% \includeonly{myfirstinclude}
% \includeonly{mysecondinclude}
% \includeonly{mythirdinclude}
\begin{document}
\include{myfirstinclude}
\include{mysecondinclude}
\include{mythirdinclude}
\end{document}
So when you want to include only one or some files, you just uncomment the desired line(s).
\includeonly{myfirstinclude}
\includeonly{mysecondinclude}
% \includeonly{mythirdinclude}
Related Questions
- What happens to a relative path in a file added with \input{}?
- A variant of \includeonly
- How to make the main file recognize relative paths used in the imported files?
- subimport and includeonly
- Using standalone to combine multiple .tex into a single file
- Can a file know if it has been \include'ed or \input'ed?
- Generate a merged LaTeX file, with \input code in place?
- How to merge several tex files so that they have one table of contents/List of tables & figures
- When should I use \input vs. \include?
- Options for building multiple documents from the same content with different layouts
- What state changes are caused by \input?
\includeonly{myfirstinclude,mysecondinclude}
, which doesn't need any new macros. The disadvantage is that you have to change the command manually instead of commenting out lines. (You already know this, since\addtoincludeonly
is building a comma separated list. But if a TeX rookie finds this question, I would encourage them to start with the usual way before using your macro.)