3

I am running a script that starts pdflatex in a terminal. Since I have my tex files in different folders I need to change the dir before pdflatex can 'see' the input tex file. So my question is there an alternative for the following command to tell pdflatex to look for the input files in a custom folder? In the manual I can't find anything like -output-directory=DIR for the input.

cd somepath/ && pdflatex -halt-on-error file.tex

1 Answer 1

7

Almost always this is the best form

cd somepath/ && pdflatex -halt-on-error file.tex

There are alternatives eg

TEXINPUTS=somepath:
pdflatex -halt-on-error file.tex

works as the initial file may be found anywhere on the input path, so for example you can type

pdflatex sample2e

anywhere and generate the standard latex test document output. sample2e.tex will be found by the same process that article.cls is found (and from the same place).

Or you could do

 pdflatex -halt-on-error somepath/file.tex

which also works for simple files.

The problem with the second two forms is that they require the process has write access to the current directory to write the log file etc, this may not be the case if you set up an editor pipeline in such a way and start the editor from a desktop menu that may start in some system area.

Secondly all relative paths for \input, \includegraphics etc are relative to the working directory of the tex process, not to the directory containing the main file. So this often fails if you have multi-file documents. Starting with a cd to the directory of the main document makes the process current directory match the filepath to the main document which makes everything much simpler.

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.