Posts tagged ‘parallel’

Parallel LaTeXing with Python Threads

Based on an example from stackexchange I have created a small example on parallel TeX compilation.

# -*- coding: utf-8 -*-
Created on 2016-07-06
Uwe Ziegenhagen
based on
from multiprocessing.pool import ThreadPool
from time import time as timer
import os
files = ['test-01.tex','test-02.tex','test-03.tex','test-04.tex','test-05.tex',
def compile_file(cfile):
		result = os.system('pdflatex -interaction=batchmode ' + cfile)
		return cfile, None
	except Exception as e:
		return cfile, e	
start = timer()
results = ThreadPool(8).imap_unordered(compile_file, files)
for cfile, error in results:
	if error is None:
		print("%r compiled in %ss" % (cfile, timer() - start))
		print("Error compiling %r: %s" % (cfile, error))
		print("Elapsed Time: %s" % (timer() - start,))
print('Gesamtzeit',timer() - start)


Uwe Ziegenhagen has been working with LaTeX for almost two decades. Besides TeX/LaTeX he likes to work with Python, Linux, Rasberry/Arduino and his digital cameras.

More Posts - Website