I'm trying to include a file whose path relative to the main tex file is ../folder/chapter.tex
. I tried
\input{../folder/chapter.tex}
but it doesn't work: I get an error of file not found. I'm using MikTex 2.9 under Windows.
After some testing from the command line using xelatex.exe, it seems to be the case that Latex requires the relative paths in your source files to be defined relative to the folder in which the Latex compiler is executed (not relative to the location of your main Latex file). This actually makes a fair bit of sense. These relative paths aren't being passed to your main Latex file; they're being passed to the Latex compiler. It will interpret relative paths in relation to where it was invoked.
Since you're using a GUI, I have no idea what MikTeX considers to be the folder in which the Latex compiler is executed.
I see two different solutions:
One, abandon relative paths and use absolute paths. You can even include the drive letter. Just remember to keep on using Latex's preferred forward slashes for the directory levels, for example:
\input{C:/project/latexfiles/mychapter.tex}
Two, you can start compiling from the command line. Keep a DOS box open to the folder where your main Latex file lives. When you're ready to compile, run the command to do so. Here are the parameters I use:
xelatex -synctex=-1 -shell-escape -halt-on-error mymainfile.tex
When I need to recompile, I go to the DOS box and press up to get the last command, then I hit return. Very convenient. You can of course use pdflatex.exe or whichever Latex compiler you need, and you can google to learn more about the various command line parameters and their effects.
import
package.
\input
, at least with XeLaTex from TeXLive 2015. Relative paths are fine. I am not sure about \include
, though. I'm having some trouble with it ....
xelatex
relative to where the main file I'm compiling is located, and my \input
paths are always relative to that. (If that's what you meant--I now think it is--maybe a small clarification would be worthwhile.)
Using an IDE is in general more practical than command line. When an IDE is asked to typeset a file, it somehow goes to the directory of the file and launches the typesetting tool such that relative file paths are resolved relatively to the directory where the main file is located.
Some IDEs implement a concept of project (LaTeX Workshop
...), whereas others just typeset the current file. TeXworks
and others support magic comments to specify the master file.
In that case your chapter.tex
could start with something like
% !TEX root = ../Main/main.tex
telling the IDE where the main file to be typeset is located.
\input{../folder/chapter.tex}
(i.e. braces not parentheses) right?..
in every case.\input
that should be OK, but\include
would fail.