Here is probably a non-conventional way of doing this. I was trying to combine a few files while still hoping to be able to compile each file individually. I used the catchfilebetweentags
package to get it done.
Let says I have file1.tex
and file2.tex
, which I only want to include the part lies between \begin{document}
and \end{document}
. I labelled it with tag name of document
.
In file1.tex
and file2.tex
,
\begin{document}
%<*document>
...
%</document>
\end{document}
For clarity, %<*tagname>
and %</tagname>
is the way to tag the content to be used in the catchfilebetweentags
package.
So in my main.tex
, I want to include the content in file1.tex
and file2.tex
.
<remember to add preambles that are needed>
\usepackage{catchfilebetweentags}
\begin{document}
\ExecuteMetaData [file1.tex] {document}
\ExecuteMetaData [file2.tex] {document}
\end{document}
Voila! Here you go! You can still compile each of the file individually.
There is one problem with cathcfilebetweentags
as mentioned in \input only part of a file using catchfilebetweentags package. The line break is not recognised when you are having an empty line to indicate line break.
Thank to egreg for providing the solution here. Basically you can just add this to your preamble.
\makeatletter
\def\CatchFBT@Fin@l#1[#2]{%
\begingroup
%\endlinechar\m@ne % <- this is the guilty party
\makeatletter #2%
\scantokens\expandafter{%
\expandafter\CatchFBT@tok\expandafter{\the\CatchFBT@tok}}%
\CatchFBT@IsAToken{#1}
{\global#1\expandafter{\the\CatchFBT@tok}}
{\xdef#1{\the\CatchFBT@tok}}%
\ifx\CatchFBT@tok#1\else\global\CatchFBT@tok{}\fi
\endgroup
}% \CatchFBT@Final
\makeatother
If you desire more explanation on this, please check out on \input only part of a file using catchfilebetweentags package.