# \converter lyxpreview ${FORMAT} "lyxpreview2bitmap.sh" ""
# where ${FORMAT} is either ppm or png.
+# These four programs are used by the script.
+# Adjust their names to suit your setup.
+LATEX=latex
+DVIPS=dvips
+GS=gs
+PNMCROP=pnmcrop
+readonly LATEX DVIPS GS PNMCROP
+
# Three helper functions.
FIND_IT ()
{
BAIL_OUT ()
{
+ test $# -eq 1 && echo $1
+
# Remove everything except the original .tex file.
- FILES=`ls ${BASE}* | sed -e "/${BASE}.tex/d"`
+ FILES=`ls ${BASE}* | sed -e "/${BASE}\.tex/d"`
rm -f ${FILES} texput.log
echo "Leaving ${BASE}.tex in ${DIR}"
exit 1
REQUIRED_VERSION ()
{
+ test $# -eq 1 || exit 1
+
echo "We require preview.sty version 0.73 or newer. You're using"
- grep 'Package: preview' ${LOGFILE}
+ grep 'Package: preview' $1
}
# Preliminary check.
exit 1
fi
+# We use latex, dvips and gs, so check that they're all there.
+FIND_IT ${LATEX}
+FIND_IT ${DVIPS}
+FIND_IT ${GS}
+
# Extract the params from the argument list.
DIR=`dirname $1`
BASE=`basename $1 .tex`
GSDEVICE=png16m
GSSUFFIX=png
else
- echo "Unrecognised output format ${OUTPUTFORMAT}."
- echo "Expected either \"ppm\" or \"png\"."
- BAIL_OUT
+ BAIL_OUT "Unrecognised output format ${OUTPUTFORMAT}. \
+ Expected either \"ppm\" or \"png\"."
fi
-# We use latex, dvips and gs, so check that they're all there.
-FIND_IT latex
-FIND_IT dvips
-FIND_IT gs
-
# Initialise some variables.
TEXFILE=${BASE}.tex
LOGFILE=${BASE}.log
DVIFILE=${BASE}.dvi
PSFILE=${BASE}.ps
METRICSFILE=${BASE}.metrics
+readonly TEXFILE LOGFILE DVIFILE PSFILE METRICSFILE
# LaTeX -> DVI.
cd ${DIR}
-latex ${TEXFILE} ||
+${LATEX} ${TEXFILE} ||
{
- echo "Failed: latex ${TEXFILE}"
- BAIL_OUT
+ BAIL_OUT "Failed: ${LATEX} ${TEXFILE}"
}
# Parse ${LOGFILE} to obtain bounding box info to output to
# "Preview: Snippet".
grep -E 'Preview: [ST]' ${LOGFILE} > ${METRICSFILE} ||
{
- echo "Failed: grep -E 'Preview: [ST]' ${LOGFILE}"
- REQUIRED_VERSION
- BAIL_OUT
+ REQUIRED_VERSION ${LOGFILE}
+ BAIL_OUT "Failed: grep -E 'Preview: [ST]' ${LOGFILE}"
}
# Parse ${LOGFILE} to obtain ${RESOLUTION} for the gs process to follow.
# not found.
LINE=`grep 'Preview: Fontsize' ${LOGFILE}` ||
{
- echo "Failed: grep 'Preview: Fontsize' ${LOGFILE}"
- REQUIRED_VERSION
- BAIL_OUT
+ REQUIRED_VERSION ${LOGFILE}
+ BAIL_OUT "Failed: grep 'Preview: Fontsize' ${LOGFILE}"
}
# The sed script strips out everything that won't form a decimal number
# from the line. It bails out after the first match has been made in
| bc`
# DVI -> PostScript
-dvips -o ${PSFILE} ${DVIFILE} ||
+${DVIPS} -o ${PSFILE} ${DVIFILE} ||
{
- echo "Failed: dvips -o ${PSFILE} ${DVIFILE}"
- BAIL_OUT
+ BAIL_OUT "Failed: ${DVIPS} -o ${PSFILE} ${DVIFILE}"
}
# PostScript -> Bitmap files
ALPHA=2
fi
-gs -q -dNOPAUSE -dBATCH -dSAFER \
+${GS} -q -dNOPAUSE -dBATCH -dSAFER \
-sDEVICE=${GSDEVICE} -sOutputFile=${BASE}%d.${GSSUFFIX} \
-dGraphicsAlphaBit=${ALPHA} -dTextAlphaBits=${ALPHA} \
-r${RESOLUTION} ${PSFILE} ||
{
- echo "Failed: gs ${PSFILE}"
- BAIL_OUT
+ BAIL_OUT "Failed: ${GS} ${PSFILE}"
}
# All has been successful, so remove everything except the bitmap files
# The bitmap files can have large amounts of whitespace to the left and
# right. This can be cropped if so desired.
CROP=1
-type pnmcrop > /dev/null || CROP=0
+type ${PNMCROP} > /dev/null || CROP=0
# There's no point cropping the image if using PNG images. If you want to
# crop, use PPM.
if [ ${CROP} -eq 1 -a "${GSDEVICE}" = "pnmraw" ]; then
for FILE in ${BASE}*.${GSSUFFIX}
do
- if pnmcrop -left ${FILE} 2> /dev/null |\
- pnmcrop -right 2> /dev/null > ${BASE}.tmp; then
+ if ${PNMCROP} -left ${FILE} 2> /dev/null |\
+ ${PNMCROP} -right 2> /dev/null > ${BASE}.tmp; then
mv ${BASE}.tmp ${FILE}
else
rm -f ${BASE}.tmp