[Tex/LaTex] LaTeX compilation failure on Mac OS X from Python Script

compilingmactexscripts

I wrote a Python script to automate some LaTeX builds. Currently I develop/test on Mac OS X (did not try it on other UNIX flavors).

The particular execution function which should compile the LaTeX into a pdf document looks like:

def execute(texinputs, params, proj_dir):
    latex_cmd = '/usr/texbin/xelatex'

    params=shlex.split(params)
    if params is None or len(params)==0:
        params = [latex_cmd]
    else:
        params.insert(0, latex_cmd)

    environment = os.environ
    oldenv = environment.get('TEXINPUTS', '')
    prepand = ':'.join([input for input in texinputs])
    environment['TEXINPUTS']=prepand+':'+oldenv
    ptoken=subprocess.Popen(params, env=environment, cwd=proj_dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    with ptoken.stdout as stdout:
        with ptoken.stderr as stderr:
            for _i in range(1,10):
                if ptoken.poll() is None:
                    time.sleep(1)
            ret=ptoken.returncode 
            if ptoken.returncode is None:
                ret = -1000
                ptoken.kill()
            outlines, errlines = stdout.readlines(), stderr.readlines()
            return ret, outlines, errlines 

What I do here is passing the paths to some generated sources which should be pre-pended to TEXINPUTS to resolve relative paths inside my LaTeX template as well as some additional tex processor parameters.

A typical shell command call (which works fine) is:

TEXINPUTS=/Users/ovanes/Documents/some_path/content:$TEXINPUTS /usr/texbin/xelatex -shell-escape main.tex

This produces a main.pdf which is fine. However, running this shell command from the script I see the following output and no main.pdf is written.

Error 32512 (driver return code) generating output;
file main.pdf may not be valid.

Any ideas?

Best Answer

Ok, I found out the problem. I overlooked that LaTeX processer could not start xdvipdfmx due to path problems. Finally, appending '/usr/texbin' to the PATH environment of the child process worked fine.

Related Question