# How can I execute pdflatex when I'm not in the directory?

I am currently experimenting with lilypod. To generate a PDF from the source, I have to enter

``````mkdir -p charts-out
lilypond-book --output=charts-out/ --pdf  charts.tex
cd charts-out
pdflatex charts.tex
``````

When I add this to a `Makefile` it doesn't work, because the `cd` doesn't change the directory.

So I wanted to replace

``````cd charts-out
pdflatex charts.tex
``````

with

``````pdflatex charts-out/charts.tex
``````

This does also not work:

``````moose@pc07:~\$ pdflatex charts-out/charts.tex
This is pdfTeX, Version 3.1415926-2.3-1.40.12 (TeX Live 2011)
restricted \write18 enabled.
entering extended mode
(./charts-out/charts.tex
LaTeX2e <2011/06/27>
Babel <v3.8m> and hyphenation patterns for english, dumylang, nohyphenation, ge
rman-x-2011-07-01, ngerman-x-2011-07-01, afrikaans, ancientgreek, ibycus, arabi
c, armenian, basque, bulgarian, catalan, pinyin, coptic, croatian, czech, danis
h, dutch, ukenglish, usenglishmax, esperanto, estonian, ethiopic, farsi, finnis
h, french, galician, german, ngerman, swissgerman, monogreek, greek, hungarian,
icelandic, assamese, bengali, gujarati, hindi, kannada, malayalam, marathi, or
iya, panjabi, tamil, telugu, indonesian, interlingua, irish, italian, kurmanji,
lao, latin, latvian, lithuanian, mongolian, mongolianlmc, bokmal, nynorsk, pol
ish, portuguese, romanian, russian, sanskrit, serbian, serbianc, slovak, sloven
ian, spanish, swedish, turkish, turkmen, ukrainian, uppersorbian, welsh, loaded
.
(/usr/local/texlive/2011/texmf-dist/tex/latex/amscls/amsart.cls
Document Class: amsart 2009/07/02 v2.20.1
(/usr/local/texlive/2011/texmf-dist/tex/latex/amsmath/amsmath.sty
For additional information on amsmath, use the `?' option.
(/usr/local/texlive/2011/texmf-dist/tex/latex/amsmath/amstext.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/amsmath/amsgen.sty))
(/usr/local/texlive/2011/texmf-dist/tex/latex/amsmath/amsbsy.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/amsmath/amsopn.sty))
(/usr/local/texlive/2011/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/local/texlive/2011/texmf-dist/tex/latex/amsfonts/amsfonts.sty))
(/usr/local/texlive/2011/texmf-dist/tex/latex/geometry/geometry.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/ifpdf.sty)
(/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/ifvtex.sty)
(/usr/local/texlive/2011/texmf-dist/tex/generic/ifxetex/ifxetex.sty))
(/usr/local/texlive/2011/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/local/texlive/2011/texmf-dist/tex/latex/latexconfig/graphics.cfg)
(/usr/local/texlive/2011/texmf-dist/tex/latex/pdftex-def/pdftex.def
(/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)))
(./charts.aux) (/usr/local/texlive/2011/texmf-dist/tex/latex/amsfonts/umsa.fd)
(/usr/local/texlive/2011/texmf-dist/tex/latex/amsfonts/umsb.fd)
*geometry* driver: auto-detecting
*geometry* detected driver: pdftex
(/usr/local/texlive/2011/texmf-dist/tex/context/base/supp-pdf.mkii
) (/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty
(/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/ifluatex.sty))
(/usr/local/texlive/2011/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty
(/usr/local/texlive/2011/texmf-dist/tex/latex/oberdiek/grfext.sty
(/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty))
(/usr/local/texlive/2011/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/local/texlive/2011/texmf-dist/tex/generic/oberdiek/etexcmds.sty)))
(/usr/local/texlive/2011/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
! I can't find file `53/lily-2fb3a572-systems.tex'.
l.30 \input 53/lily-2fb3a572-systems.tex

(Press Enter to retry, or Control-D to exit)
Please type another input file name:
``````

How can I make it work?

-
Why do you think that `cd` doesn't work?. Whatever you can use `pdflatex charts-out/charts.tex`. – Marco Daniel Jul 21 '12 at 13:38
I tried it. It worked, when I entered the command manually, but not with the Makefile. NO, `pdflatex charts-out/charts.tex` DOES NOT WORK! This is the reason why I've asked the question! – Martin Thoma Jul 21 '12 at 13:46
Did you try a small shell script? – Marco Daniel Jul 21 '12 at 13:49
For the `cd` issue see this question. – canaaerus Jul 21 '12 at 14:00
@Marco: You should never start pdflatex like this. This leads to chaos with `\input` file. – Ulrike Fischer Jul 21 '12 at 14:47

Try the following trick (it can have side effects I explain later). The following command is run from the "parent" folder, even if the file `charts.tex` is in a subfolder:

``````TEXINPUTS=.//:: pdflatex charts.tex
``````

The explanation is as follows. `pdflatex` searches all input files (`.sty` loaded via `\usepackage`, `.cls` via `\documentclass`, `.tex` via `\input` or `\include` or command line, etc.) in diffent folders, beginning with those specified in `TEXINPUTS` environment variable. The value of this variable uses a syntax similar to the one for the system `PATH`, but it has some particularities.

If a folder name ends with `//`, then all its subfolders are scanned recursively too. If at some point the "null folder" `::` is specified, then the `texmf` tree used by tex by default is used at this point.

So, in my solution, `TEXINPUTS` can be read as: "search first the current folder with all its subfolders too, recursively, and then in the default texmf search path".

The drawback is that you cannot (or better should not) have files with the same name in different subfolders, because only the first one found by tex will be considered.

-

I use this, which works for me (though it not be the most efficient):

``````%.pdf: %.lytex *.ly songs.ist
lilypond-book --pdf --left-padding=0 --output=out --include=\$(CURDIR) *\$.lytex
cd out ; pdflatex \$*
cd out ; makeindex -s ../songs.ist \$*.idx
``````

`songs.ist` is my list of songs that I abuse `makeindex` to make.

-