My Python3 utility has a function that doesn't work (unless it's placed within selected directories, where it can then run the non-python pdflatex
scripts successfully). I want to run the utility from a set location on any of the template.tex files I have, stored in various other locations.
The Python utility prompts the user to select a pdflatex
template file from an absolute path using a tkinter.filedialog GUI, then runs the user's selected pdflatex
script using, for example: os.system("pdflatex /afullpath/a/b/c/mytemplate.tex")
Python's os.system
runs pdflatex
, which then runs its mytemplate.tex
script. mytemplate.tex
has numerous inputs written with relative paths like ./d/another.tex
.
So, the Python utility works fine as long as it's in the exact same path as /afullpath/a/b/c/mytemplate.tex
that the user selects. Otherwise pdflatex
can't finds its own input files. pdflatex
delivers an error message like: ! LaTeX Error: File ./d/another.tex not found
because the execution path is relative to the Python script and not the pdflatex
script.
[pdflatex
needs to use relative paths because the folders with its .tex files get moved around, as needed.]
I found the following similar case on Stack Overflow, but I don't think the answers are geared towards this situation: Relative Paths In Python -- Stack Overflow