7

My question is similar to this one, but I have a problem with relative paths when including files.

Assume I have three projects which all start with

\documentclass[12pt,a4paper]{article}
\usepackage[]{}
...
\usepackage[]{}
\begin{document}
...
\input{parts/chapter1}
...
\includegraphics{graphics/figure1.eps}
...
\end{document}

All these projects include own relative paths to other resources, e.g. graphics and chapters.

My goal is to build a new file that will contain all three including everything between \begin{document} and \end{document}, such that I can work on my three small projects and easily compile them into my PhD Thesis.

I could get it working with package catchfilebetweentags, but with full paths only. I also found another package import that helps to recognize relative paths. But I do not know how to combine these two packages. Can one help?

A simple example:

main.tex

\documentclass[12pt,a4paper]{article}
\usepackage{import}
\begin{document}
1.Hello World
\subimport{test/}{inputFile.tex}
\end{document}

test/inputFile.tex

\documentclass[12pt,a4paper]{article}
\begin{document}
2.Hello World\\
\input{inputFile2.tex}
\end{document}

test/inputFile2.tex

3.Hello World

It would work if I commented \documentclass[12pt,a4paper]{article}, \begin{document}, \end{document} in inputFile.tex. But then I cannot compile inputFile.tex independently.

Jonas Stein
  • 8,909
cherep
  • 81
  • Do you need to compile your subprojects independently? If not, set up a general file like thesis.tex which has a proper preamble and loads all the packages you need. Then use input after the begin{document} command to load the subprojects. These files should then only contain the text (and markup needed for it). You can still compile only one subproject by commenting out the other project files. – Chris Dec 09 '13 at 13:53
  • I solved that problem for my Master thesis and posted the results here: http://tex.stackexchange.com/questions/124228/pgfplotstableread-and-subfiles – papabravo Dec 09 '13 at 14:00
  • @Chris the point is that I'm working with only subprojets and do compile them independently. – cherep Dec 09 '13 at 14:22
  • @papabravo there are other people working on subprojects with me and I cannot really change their structure such that they notice it. – cherep Dec 09 '13 at 14:24
  • 1
    I think without changing something in the subfiles this task is close to impossible. The packages you are suggesting will not take care of package or makro clashes between subfiles and main file. – papabravo Dec 09 '13 at 16:49
  • Possible duplicate of http://tex.stackexchange.com/questions/11311/how-to-include-a-document-into-another-document See especially Martin's answer. – Willie Wong Dec 11 '13 at 15:48
  • @cherep, so other people are working on your PhD thesis? :o – quinmars Apr 10 '14 at 19:22

1 Answers1

1

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?

Troy
  • 13,741
cherep
  • 81