6

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.

  • 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 9 '13 at 13:53
  • I solved that problem for my Master thesis and posted the results here: tex.stackexchange.com/questions/124228/… – papabravo Dec 9 '13 at 14:00
  • @Chris the point is that I'm working with only subprojets and do compile them independently. – cherep Dec 9 '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 9 '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 9 '13 at 16:49
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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.