#!/bin/bash
# Copyright 2024 Massimo Girondi massimo@girondi.net - GNU GPL v3


TEXS=$(find . -iname \*.tex)
EPSS=$(find . -iname \*.eps)
SVGS=$(find . -iname \*.svg)

# Just in case
git commit -a -m "Automatic commit: before figures renaming in tex"

for F in $TEXS; do
        # First, we remove extensions from includegraphics
        sed -e "s/\(\\includegraphics.*\)\({.*\).pdf/\1\2/g" -i $F
        sed -e "s/\(\\includegraphics.*\)\({.*\).eps/\1\2/g" -i $F
        sed -e "s/\(\\includegraphics.*\)\({.*\).svg/\1\2/g" -i $F
done

# Then we apply the conversion accordingly to what we need.
# Warning! This would convert all files, not only what has been replaced above!


git commit -a -m "Automatic commit: before figures conversion"


# We crapply rely on inkscape to convert
for F in $SVGS; do
        FF="${F%.*}"
        inkscape $F --export-type=pdf $FF.pdf
done

for F in $EPSS; do
        FF="${F%.*}"
        inkscape $F --export-type=pdf $FF.pdf
done

git commit -a -m "Automatic commit: after figures conversion"
