2

I have a Latex document split across multiple files (.tex). Considering the main.tex file includes the intro.tex file:

\begin{document}
...
\input{intro.tex}

Both files are side by side in the same folder. I can build this with pdflatex in that directory.

But I'm considering to build (call pdflatex) from a dedicated build folder (which is in the same level). I mean, cd build and then pdflatex ../main.tex.

I've noticed that building from inside it (the build folder) requires a modification in the main.tex, I need to change the path of the inputs to:

\input{../intro.tex}

So, it seems the path is relative to where the build runs from. Instead, I would like the path to be relative to the file which has the \input command. Is it possible?

Also, I would like to point it's mentioned here that "... it is important to note that the paths are relative to the directory in which the main .tex file resides, not to the directory in which the included (or input) file is found. This is likely to be an issue ...", which in my understand isn't correct. As i said above, "it seems the path is relative to where the build (pdflatex) runs from". Right?

6
  • 2
    not really. It's pretty much always best to do cd somewhere; latex file than latex somewhere/file You can of course use TEXINPUTS=..//: latex main then \input{intro} would work Commented Nov 19, 2016 at 12:30
  • The import package might be usefull, repositorios.cpai.unb.br/ctan/macros/latex/contrib/import/…
    – KcFnMi
    Commented Nov 19, 2016 at 18:00
  • @DavidCarlisle, what do you mean by "not really"? I've edit/add something to the question, do you agree?
    – KcFnMi
    Commented Nov 19, 2016 at 18:05
  • 1
    I meant "no" (to the question of is it possible to use paths relative to the main file) except tex is Turing complete, so anything's possible if you complicate the macros enough, but not always feasible. In this case just setting TEXINPUTS to include all your project files then just using \input with no paths seems the simplest thing to do Commented Nov 19, 2016 at 18:22
  • (if I understand it) In Brazil, we call your recommendation as "matar uma mosca com um canhão". It works, but might not be the most elegant/precise solution (in my opinion at the moment). The import package seems to allow relative to relative paths, don't you like it?
    – KcFnMi
    Commented Nov 19, 2016 at 18:25

0

You must log in to answer this question.

Browse other questions tagged .