Programming
compact-slides.sh
#!/bin/bash
############################################################################
# \PURPOSE
# To extract the final slides from those generated by prosper in the
# slide show mode
#
# \USAGE
# from the command line execute the command
# compact-slides.sh filename[.tex]
#
# \DATE
# 02 Jun 2005
#
# \AUTHOR
# Simone Zuccher
#
# \PHILOSOPHY
# Use the output from latex command to figure out how many pages are
# created for a single slide and take the last one.
#
# \INPUT(S)
# One LaTeX file written according to prosper
#
# \OUTPUT(S)
# input-slc.pdf
#
############################################################################
# Check how many arguments are in the line
if [ $# -eq 0 ]
then
echo "Usage: `basename $0` input[.tex] " 1>&2
exit 1
fi
# If there is an input file, get rid of the extension .tex (if there is any)
if [ $# -eq 1 ]
then
infile="$1"
case "${infile}" in
*.tex) base=`basename "${infile}" .tex`;;
*) base=`basename "${infile}"`;;
esac
fi
# Temporary file
TMP_FILE="/tmp/tmp-file-condenseslides"
TMP_PSFILE="/tmp/tmp-file-ps-condenseslides"
# First we need to run LaTeX to get the info
echo 'Running LaTeX... '
latex $base.tex > $TMP_FILE
# Since we have an updated dvi file, let's make a good postscript
echo 'Running dvips... '
dvips -q -Pcmz -Pamz -tA4 -Ppdf -G0 $base.dvi -o $TMP_PSFILE.ps
# initialize counter
i=1
# initialize page number to select
page=0
# be AWARE of infinite loop...
while :
do
# work string
str=\\[$i\\]
# get the number of ps pages correspondint to the i-th slide
slidesl="$(sed s/$str/$str'\n'/g $TMP_FILE | grep $str -c)"
# if there are no more slides... exit the loop
if [ ${slidesl} -eq 0 ]; then
break 1
fi
# this condition is needed to put the comma... :(
if [ $i -gt 1 ]; then
list_of_pages="$list_of_pages,"
fi
# calculate the page to get
page=`expr $page + ${slidesl}`
# echo what it's doing
# echo Slide $i is made of ${slidesl} slides. Taking page $page
list_of_pages="$list_of_pages$page"
# increment the counter
i=`expr $i + 1`
done
# Extract pages
echo Extracting pages...
psselect -q -p $list_of_pages $TMP_PSFILE.ps $base-slc.ps
# Create the PDF file
echo Creating PDF file...
ps2pdf -sPAPERSIZE=a4 $base-slc.ps
# Remove the PS file
#rm -f $base-slc.ps
# total number of slides
nslides=`expr $i - 1`
# remove the temporary file
rm -f $TMP_FILE
rm -f $TMP_PSFILE.ps
# Done!
echo $nslides slides processed, exiting succesfully.
Top
|