Compile multiple latex files in parallel using python script

Viewed 48

I'm trying to speed up the pdflatex compilation of a large number of latex files using multiprocessing or multithreading in Python. A simplified example of what I'm trying to do is below.

def do_create(params):
    a = param[0]
    b = param[1]
    c = param[2]
    call(["pdflatex",  "--jobname=pdfs/%s/%s/%s"%(a,b,c), "template.tex"])

for A in ListA:
     for B in ListB:
            paramlist = [(A, B, C) for C in ListC]
            paramlist = iter(paramlist)
            with Pool(8) as p:
                 p.map(do_create,paramlist)

Is it possible to use pdflatex to compile multiple different tex files simultaneously in this way? Would it be better to use a multithreading-based approach instead?

1 Answers

As suggested in the comment by Thomas I'd recommend GNU parallel. You can either use it as command line or in the following I show a script:

script.sh

#!/bin/bash

ListA=(a1 a2) #putting in your values here

ListB=(b1 b2 b3)

ListC=(c1 c2 c3)

parallel pdflatex --jobname=pdfs/{1}/{2}/{3} template.tex\
                   ::: "${ListA[@]}" ::: "${ListB[@]}" ::: "${ListC[@]}"
Related