[Tex/LaTex] How to include tex files

formattingincludeinput

Is there any way that I can add different .tex files (From different folders) into another folder's .tex file?

I meant that all of the .tex files will be fine and separated and I just need to aggregate into one without copy & pasting these files into a single one.

enter image description here

I have saved the input file like this, but it's not working when I write in another file,
like enter image description here

\include{oscillonsource.tex}.

It's still not working. 🙁

Best Answer

Here is a complete example of the input/include command at work:

The example consists of 3 files in a folder structure as follows:

[Parent Folder]
 |
 +-- file1.tex
 |
 +-- fig.jpg
 |
 +-- [folder]
      |
      +-file2.tex

fig.jpg is just an ordinary jpg image file. The contents of file1.tex are as follows:

\documentclass{article}
\usepackage{graphicx}
\begin{document}
\input{folder/file2.tex}
\end{document}

Note the inclusion of the (relative) path as well as the filename of file2.tex.

The contents of file2.tex are

\includegraphics{fig.jpg}

Note that file2.tex does not have its own preamble, document class, \begin{document} etc.

Think of \input as having a similar effect to you manually copying and pasting whatever is in file2.tex into file1.tex: no need to include anything you wouldn't want to copy in this fashion. Following through this copying/pasting logic: note also that the path to fig.jpg needs to be relative to file1.tex, not file2.tex. Since fig.jpg is in the same folder as file1.tex this means that we don't have to specify any path.

Saving this file/folder structure and compiling file1.tex results in a document with fig.jpg included in it.