Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Ugly wrapper around pygmentize to speed up pdflatex using the minted package for syntax highlighting

View pygmentize
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#!/bin/bash
# An ugly hack to speed up pdflatex using the minted package
# place this file with the name 'pygmentize' somewhere on your
# path before the 'real' pygmentize, such that this file gets
# executed and can act as a wrapper around the 'real' pygmentize.
# This script computes a hash-value (md5sum) of the input file
# from minted and caches the output of pygmentize.
# The working directory is used to store the cached files (it's an ugly hack...)
 
# The real pygmentize command, may need customization to work on your system.
# Use 'whereis pygmentize' to found the location on your system.
real_pygmentize=/usr/bin/pygmentize
 
# find the output file used by minted
take_outfile=0
for arg in $@
do
if [ $take_outfile -eq 1 ]
then
outfile=$arg
take_outfile=0
fi
if [ $arg = -o ]
then
take_outfile=1
fi
done
 
# the last parameter is the input file
infile=${@: -1}
 
# compute the hash value of the input
hash=$( md5sum $infile | cut -d' ' -f1 )
if [ -f "$hash" ]
then
# we have cached output from pygmentize
cp "$hash" "$outfile"
else
# call 'real' pygmentize and cache the result
$real_pygmentize "$@"
cp "$outfile" "$hash"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.