7

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. :-(

Complex Guy
  • 1,711
  • For a good specific answer simple MWE might help. For eg: What would be the absolute/relative paths of child1.tex,child2.tex files with respect to master.tex ? What is the preamble in child.tex files and are they self-compilable with their own \documentclass{} ? TeX UK faq website has some excellent information on it – texenthusiast Jul 09 '13 at 10:23
  • Please post the contents of the oscillonsource.tex file and of the file in which you want to include oscillonsource.tex – Red Jul 09 '13 at 11:09
  • @compex-guy If you use \input{}, you could write path to the file, e.g., if you have your tex file in the forder WORK, but there are subfolders CH1, CH2, etc., use \input{CH1/sec1.tex} and so on! Cheers. – Dox Jul 09 '13 at 13:38
  • \input{oscillon130613/oscillonsource.tex}

    I inserted the above one, but didn't work. My file name is oscillon13061 and tex file name is oscillonsource.tex.

    – Complex Guy Jul 09 '13 at 15:45
  • combine documentclass can do it. – ernesto Jul 09 '13 at 08:40
  • Change \input{oscillon130613/...} to \input{../oscillon130613/...}. .. is the Unix shortcut for the parent folder relative to your working directory. – JBantje Jan 14 '15 at 16:04

2 Answers2

11

Yes, the \include{<filename>} command inserts the file after a page break. If you don't want the page break, use \input{<filename>}. The major reason you would want to use \include rather than \input is the \includeonly command, which can save compilation time when writing your document.

ChrisS
  • 13,529
  • a tex file name "oscillon source.tex" and I have write in another file like this \include{} , but didn't work. Do I need to insert these file in thje same folder. ? – Complex Guy Jul 09 '13 at 08:52
  • 1
    You don't need the angle brackets (they're just to indicate it's a placeholder), and you don't need the extension: use \include{oscillon source} – ChrisS Jul 09 '13 at 08:54
  • 2
    Don't use filenames with spaces with \include... – karlkoeller Jul 09 '13 at 08:55
  • I wrote \include{oscillon source} and the file opened but cant see any element of that file in the new file :-( – Complex Guy Jul 09 '13 at 09:01
  • @karlkoeller you told me to to give any space between filenames? Can you elaborate please? – Complex Guy Jul 09 '13 at 09:28
  • TeX doesn't like spaces in file names; you'll have to rename the file oscillonsource.tex, and then \include it, as \include{oscillonsource.tex}. – ChrisS Jul 09 '13 at 09:32
  • Done as you say but It's not working. – Complex Guy Jul 09 '13 at 10:04
  • I've tried it on my system, and \include isn't working for me either, which is strange. However, \input works, although it lacks the advanced features – ChrisS Jul 09 '13 at 10:16
  • 2
    @ComplexGuy: we are plainly not understanding what you have written. rename "oscillon source.tex" as "oscillon-source.tex", and write a latex file that's as small as possible, and shows the error: that way ("minimal example") we see what your problem is, not your description of your problem. – wasteofspace Jul 09 '13 at 10:16
  • Do I have to write something in the beginning as I wrote \usepackage{graphicx} when I added graphics. – Complex Guy Jul 09 '13 at 10:33
11

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.

Ubiquitous
  • 2,566
  • If I want to open the tex file, then I need to open three folders, my tex file name is oscillonsource.tex and it is placed on the last opened folder, oscillon130613 . – Complex Guy Jul 09 '13 at 15:42
  • \date{July 07, 2013}
    \begin{document} \baselineskip=16pt

    \input{oscillon130613/oscillonsource.tex}

    \end{document}

    But didn't work.

    – Complex Guy Jul 09 '13 at 15:43
  • I think problem is in my input cause when I insert it, then the tex file is not running. – Complex Guy Jul 09 '13 at 15:55