The hard way to print an EPS

Last week, I got an interesting ticket from one of the professors in my department.  An EPS file that she had would not print before I stood up our new print server.  After the new server was set up (eat that, Solaris!) the file would print, but the image was not properly centered on the page, causing much of it to be lost in printing.  My first thought was “oh, I’ll just use the page-left and page-top options to lpr to adjust the margins until it worked”.  Oddly enough, it didn’t shift the image at all.  I checked the image with the Evince document viewer.  Everything looked okay there, so I tried printing from Evince.  No dice.

Fortunately, at the same time I was banging my head against this I was also working on another problem for the same professor.  She had a TeX file that wasn’t properly displaying the EPS files embedded in it.  So once I got that working (the simple solution was to upgrade to RHEL 5), I got a brilliant idea: what if I created a TeX file with the EPS as the only content.

The only difficulty is that I don’t know how to use TeX.  Fortunately, I found Andrew Bennieston’s book Writing Scientific Documents Using LaTeX.  After a few minutes of tinkering, I was able to print the EPS image in the correct size and placement.  Of course, that doesn’t fix the root cause, which still bothers me, but at least there’s a suitable workaround.  I was able to write a Bash script that automates the process into a single command to make life easier on the users.  I document it here because there might be somebody else who is having problems printing EPS files, and because if I post it on my blog someone will come along and tell me all of the ways I could have done it better.


# lpreps
#   A script to wrap EPS file in TeX so they'll print correctly
#  Usage: lpreps filename
#       (If you want to change the default behavior of lpr, use
#         the PRINTER and LPOPTIONS environment variables.)

# Check to make sure we were called correctly
if [ $# -ne 1 ]; then
  echo Usage: lpreps filename
  echo "(If you want to change the default behavior of lpr, use"
  echo "  the PRINTER and LPOPTIONS environment variables.)"
  exit 1

# Check to make sure the file we want to print exists
if [ ! -f $1 ]; then
  echo "File $1 not found"
  exit 2

# Find the commands we need
if [ -f /usr/bin/latex ]; then
  # Take a wild guess, I suppose
  latex=`which latex`

if [ -f /usr/bin/dvips ]; then
  # Take a wild guess, I suppose
  dvips=`which dvips`

cat >lpreps-$$.tex <<EOF




$latex lpreps-$$.tex
$dvips lpreps-$$.dvi

# Clean up afer ourselves
rm -v lpreps-$$*

exit 0
# End script

3 thoughts on “The hard way to print an EPS

  1. John,

    Nope, nobody seems to have come up with a better way yet, or if they have they don’t feel like sharing. The book is pretty helpful, it covers enough LaTeX that I felt like I could do useful things with it if I wanted to. I don’t have a hardcopy of it, but the PDF is available at the link in the article, or I can e-mail it to you if you want.

  2. I see the link now – thank you. You mean there are ways of getting and reading books in electronic form – no paper!?

Leave a Reply

Your email address will not be published. Required fields are marked *