I got it working with import
package and linux terminal command sed
that creates inputFileDis.tex with the text between \begin{document}
and \end{document}
from inputFile.tex:
sed -n -e '0,/^\\begin{document}$/d' -e '/^\\end{document}/,$d' -e p test/inputFile.tex > test/inputFileDis.tex
which I need to run every time before I compile main.tex.
Then main.tex
\documentclass[12pt,a4paper]{article}
\usepackage{import}
\begin{document}
1.Hello World
\subimport{test/}{inputFileDis.tex}
\end{document}
test/inputFile.tex
\documentclass[12pt,a4paper]{article}
\begin{document}
2.Hello World\\
\input{inputFile2.tex}
\end{document}
test/inputFileDis.tex
2.Hello World\\
\input{inputFile2.tex}
test/inputFile2.tex
3.Hello World
Does anyone have better solution in mind?
Use the import package.
Suppose I write a document describing how to make a banana milkshake. Separate the document into the header and the content:
/banana/bananaMilkshake.tex (pseudocode)
\documentclass{whatever}
\begin{document}
\input{bananaMilkshake-content.tex}
\end{document}
/banana/bananaMilkshake-content.tex
Whatever content you want.
Then, in your thesis, just \import*
the content sections as needed:
/my_thesis_directory/thesis.tex
...
\usepackage{import}
\chapter{Milkshakes}
\import*{/banana/}{bananaMilkshake-content}
The nice thing about \import*
is that you give a path to the file you want to use. Any \input
commands or graphics inclusions in the imported files still work. You can also use \subimport
if you want relative paths. The asterisk is there to prevent TeX from using files in the local directory which might have the same name as the thing you want to import. See the documentation linked above.
Cutting the document into header and content sections isn't really an "extra" step because you really should do this anyway. For example, I have my package imports and things like that in a common .tex file which is imported as needed (the one package I have to explicitly \usepackage
is... the import package). You should have lines like \input{abstract.tex}
, etc.
Now, if you want to do something like add external files as appendices with references to one another, it's trickier. See my recent post (complete with working example) about this.
Best Answer
You don't mention what kind of thesis you have, pictures and so on, so I'm just going to go with what I got. I'd put the two parts in environments and
\excludecomment
them using thecomment
package.For completeness, I will also include something to externalize images (as mentioned in comments to the question). The image below doesn't mean anything. I just wanted to use something with at least some compilation time. You will need to run
pdflatex
(or whatever engine you require for your thesis) with the shell escape option to make use of this method.