Thursday, June 30, 2011

obtain a figure file list from a tex file using grep and sed

tmpfile=`mktemp -p . exttmp.XXXX`

grep includegraphics $1 > $tmpfile
sed -e 's/includegraphics/  /' -e 's/[\\{}]//g' -e 's/\[.*\]//g' -e 's/[^ ]\+//' -e 's/^ \+//' < $tmpfile

if [ -f "$tmpfile" ]
then
    rm "$tmpfile"
fi

#
# the includegraphics must be at the same line with the pdf or other figure files included.