You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.9 KiB

#!/usr/bin/env zsh
function err(){ print -- $@ >&2; exit 1 }
# scriptdir is the directory of the current executable
if [[ ${0[0]} = '/' ]]; then
scriptdir="${0:h}"
else
scriptdir="$PWD/${0:h}"
fi
# the list of mp files without argument all file in the current tree
typeset -a fics
if (($#<1)); then
err "Usage: ${0:t} FILES"
else
fics=( $* );
fi
(( ${#fics} == 0 )) && err "No .mp files into $scriptdir"
# the tmp directory where compilation occurs with a lot of temporary files
tmpdir=/tmp/mp
[[ ! -d $tmpdir ]] && mkdir -p $tmpdir
for fic in $fics; do
ficname=${fic:t}
tmp=$tmpdir/${ficname:r}-tmp.mp
eps=$tmpdir/${ficname:r}-tmp.1
png=${fic:r}.png
old=$tmpdir/${ficname:r}.old
{
echo -n >&2 "$png"
cat $scriptdir/graph.mp
echo 'beginfig(1)'
echo ' drawoptions (withcolor base01);'
cat $fic
echo 'endfig;'
echo 'bye;'
} | sed 's/base00/baseZeroZero/g' \
| sed 's/base01/baseZeroOne/g' \
| sed 's/base02/baseZeroTwo/g' \
| sed 's/base03/baseZeroThree/g' \
| sed 's/base0/baseZero/g' \
| sed 's/base1/baseOne/g' \
| sed 's/base2/baseTwo/g' \
| sed 's/base3/baseThree/g' \
| sed 's/red/s_red/g' \
| sed 's/blue/s_blue/g' \
| sed 's/green/s_green/g' > $tmp
[[ -e $old ]] && diff $tmp $old >/dev/null && { echo " unchanged (clean $tmpdir if you want to force rebuild)"; continue }
dpi=$(grep '% DPI' $tmp | awk '{print $3}')
[[ $dpi = "" ]] && dpi=600
# addshadow="'(' +clone -background black -shadow 90x4+0+1 ')' +swap -background none -layers merge +repage"
addshadow=""
reducesize=" -colors 254 -quality 75"
cmd="convert -colorspace rgb -density $((4*dpi)) $eps -resize 25% $addshadow $reducesize $png"
cd $tmpdir && \
mpost --tex=latex ${tmp:t} >/dev/null && \
cd $OLDPWD && \
eval $cmd && \
\cp -f $tmp $old && \
echo "updated" && \
done