# Make two PDF's from one Latex file where one is in a different directory

so I have been trying to learn how to compile multiple files into a single pdf using Latex. I am working on Windows 10, with TexMaker.

I have the organized in the following manner:

Dropbox

-Main

--Main.tex

-File1

--File1.tex

-File2

--File2.tex

which hopefully is easy to understand. Not sure if there is a standard way to denote file nesting.

I started off by trying to just have one Latex file which pulls in all the other ones, but I couldn't get it to work out. From what I've gathered I believe this is due to my files not being written to be pieces of a bigger main file.

So instead I decided to use \includepdf to take the outputs of my separate files (each produces its own outputs) and put them all together. This worked out more or less, but my issue is I can't get my compiler to look in directories other than the one my main file is in. So I was wondering if I could have my File1.tex put a pdf in both File1 and Main? This would keep me from having to copy paste all the time.

If you could be very specific I would be most appreciative, because I am fairly new to manipulating Latex like this. I am also open to any other suggestions you may have.

Thanks.

• With other words: File1.tex and File2.tex are .tex - documents of their own and \include{File1} etc. doesn't work then
– user31729
Aug 8, 2015 at 14:20
• Correct. At least I haven't been able to get it to. Aug 8, 2015 at 14:21
• If both files are using the same documentclass as main.tex, you could try the combine package. Otherwise, \includepdf is perhaps the besser way
– user31729
Aug 8, 2015 at 14:22
• This answer might help you. Aug 8, 2015 at 14:25
• What do you mean by you "can't get my compiler to look in directories"? What did you try and what are the errors? Aug 8, 2015 at 14:43

As Christian Hupfer says in his comment, you usually cannot \input full .tex files which are compilable stand alone. However, you can do the trick with docmute package. Here is a extraction from the manual;

It [docmute package] redefines the \documentclass command in such a way that everything between this command and the \begin{document} is skipped, as well as everything after the \end{document}.

In imitation of directories you show, let the directory structure be

cd/
├─parent/
| └parent.tex
├─child1/
| └child1.tex
└─child2/
└child2.tex


All you have to do is load docmute package in parent.tex.

% parent.tex
\documentclass{article}
\usepackage{docmute}
\newcommand*\child[1]{This is \texttt{child#1.tex}.}
\makeatletter
\def\input@path{{../}}
\makeatother
\begin{document}
\input{child1/child1}\par
\input{child2/child2}
\end{document}

% child1.tex
\documentclass{article}
\begin{document}
This is \texttt{child1.tex}.
\end{document}

% child2.tex
\documentclass{article}
\begin{document}
\child{2}
\end{document}


Then, you can compile both parent.tex and child1.tex respectively.

However, here occurs a problem; consider compiling child2.tex. Since \child is defined only in the parent file, running pdflatex child2.tex throws ! Undefined control sequence. You need to be careful about what user-defined macros should be defined and what packages should be loaded in the child files. The author says

No attempts are made to analyse the actual content of the preamble — it is simply discarded. It is up to the user to ensure that the main document loads all packages required by subsidiary documents. To easily share (part of) a preamble between documents, simply put it in a separate file and \input it in each document.

Although this trick has a limitation mentioned above, I hope this would help you.

• package used is docmute (ctan.org/pkg/docmute), not documate. \usepackage{docmute} not \usepackage{documate}` Sep 6, 2015 at 20:45
• @EdyJo Thank you for pointing out the typo. I'll fix them later. Sep 7, 2015 at 2:48