Previous Next Contents

5. 5. Mixing text and graphics with dvips.

In general, this section applies to any TeX or LaTeX document which mixes text and graphics. TeTeX, like most other TeX distributions, is configured to request Computer Modern fonts by default. Specifically, font and graphics imaging is the job of dvips. Dvips can use either Computer Modern bit mapped or Type 1 scalable fonts, or any combination of the two. First, let's concentrate on printing and previewing some graphics.

In general, you will want to follow this procedure any time a LaTeX source document has the statement


 
\includepackage{graphics}

in the document preamble; that is, the first few lines of text before the \begin{document} statement. This statement tells LaTeX to include the text of the graphics.sty package in the source document. There are other commands to perform graphics operations, and the statements in plain-TeX documents may not clue you in whether you need to use dvips. The difference will be apparent in the output, though, when the document is printed with missing figures and other graphics.

So for now, we'll concentrate on printing documents which use the LaTeX graphics.sty package. You might want to take a look at the original TeX input. It isn't included in the teTeX distribution, but it is available at ~CTAN/macros/latex/packages/graphics/grfguide.tex.

What the teTeX distribution does include is the DVI output file, and it is already TeXed for you. There is a reason for this, and it has to do with the necessity of including Type 1 fonts in the output in order for the document to print properly. If you want to LaTeX grfguide.tex, see the next section. For now, however, we'll work on getting usable output using dvips.

This is where ghostscript comes into the picture. What ghostscript does is translate (actually, render) PostScript code into a form that any bit mapped output device can understand. Even though my HP Deskjet doesn't understand PostScript, ghostscript allows me to scale, rotate, blend, or otherwise alter text, or include graphics or colors, just like the expensive printers. A discussion of color printing is a little beyond the scope of this document, though, along with most other effects. We're going to stick to the basics for the moment.

The file grfguide.dvi is located in the directory

/usr/lib/teTeX/texmf/doc/latex/graphics

The first step in outputting grfguide.dvi is to translate it to PostScript. The program dvips is used for this. It does just exactly what its name implies. There are many options to invoking dvips, but the simplest (nearly) form is


dvips -f -r <grfguide.dvi >grfguide.ps

The -f command switch tells dvips to operate as a filter, reading from standard input and writing to standard output. Dvips output defaults to the lpr daemon. (At least my version does.) In many instances you'll want to use a post processor like ghostscript or a magicfilter. The -f option is generally the first thing I include in a dvips command line, and this form tends to be easier to use in shell scripts. The -r option tells dvips to output the pages in reverse order so they stack correctly when they exit the printer.

Depending on whether you still have the fonts that dvilj generated from the last document, dvips and metafont may or may not need to create new fonts needed by grfguide.dvi. Eventually, though, dvips will output a list of the pages translated to PostScript, and you will have your PostScript output ready to be rendered on whatever output device you have available.

If you're lucky (and rich), you have a PostScript-capable printer already and will be able to print grfguide.ps directly. You can either spool the output to the printer using lpr if it is installed on our system, or simply dump the file to printer, with


cat grfguide.ps >/dev/lp0

or whichever port your printer is attached to.

As for using ghostscript, rendering PostScript to a bit mapped device is among the most basic things it does. You may have noticed other files in the same directory as grfguide.dvi which have the .ps extension. a.ps is used as in grfguide.ps, and epslatex.ps is yet another document related to graphics. It is left as an exercise to you, the reader, to output epslatex.ps, by following the steps below.

The first thing you want to do is invoke ghostscript to view its command line arguments, like this:


gs -help

You'll see a list of supported output devices and sundry other commands. Pick the output device which most nearly matches your printer. On Chanel3, because I generally produce black-and-white text, I use the cdjmono driver, which drives a color Deskjet in monochrome (black and white) mode.

The command line I would use is:


gs -dNOPAUSE -sDEVICE=cdjmono -sOutputFile=/tmp/gs.out grfguide.ps -c quit

This will produce my HP-compatible output in the /tmp directory. It's a good idea to use a directory like /tmp, because gs can be particular about access permissions, and you can't (and shouldn't) always count on being logged in as root to perform these steps. Now you can print the file:
lpr /tmp/gs.out

Obviously, this can all go into a shell script. On my system, I have two simple scripts written, pv and pr, which simply outputs the PostScript file either to the display or the printer. Screen previewing is possible without X, but it's far from ideal. So, it's definitely worth the effort to install XFree86, or TinyX (which is what I did) in order to preview the output on the screen.

The order of commands in a ghostscript command line is significant, because some of the options tell ghostscript to look for pieces of PostScript code from is library.

The important thing to remember is that grfguide.dvi makes requests for both Computer Modern bit mapped and Type 1 scaled fonts. Generally, this works fairly well, but the possibility that the different font sets won't match esthetically is a possibility. This situation has improved in the last several years, though, but font matching is still best left to taste and simplicity. Also, having several different font systems on one machine can seem redundant, and can be an unnecessary waste of disk space. And the Computer Modern fonts can seem, well, a little too _formal_ to be suitable for everyday use. It reminds me sometimes of bringing out the good China to feed the dog. Fortunately, some good Type 1 fonts have become available in the public domain, so you don't need to spend a bundle on good-looking, scalable fonts any more. The trick to get teTeX to use them.

A final, significant note: Combining different versions of ghostscript and the svgalib can quickly become confusing. Version 3.33 of Alladin Ghostscript seems to be the most complete. The version of ghostscript which is included in the Slackware AP set is version 2.6.2 and does not have X support compiled in. You might also have trouble finding the correct svgalib versions for it. There is supposedly a version of ghostscript with X11 support in the Slackware XAP distribution series, though I haven't tried it. It's easiest, it seems to me, to compile ghostscript on your own system. Svgalib support for ghostscript 3.33 is included in a small archive which contains a .diff file. Ghostscript 3.33 for X is also configured for JPEG support, so you should include those sources as well. The relevant archives can be found at any GNU distribution site, like prep.ai.mit.edu or one of its mirrors.


Previous Next Contents