[next] [prev] [prev-tail] [tail] [up]

7.4 Graphics 

TeX has been developed with the idea that it should run on any operating system (MS-Dos, vms, vm-cms, Unix etc.). Another feature of TeX is that documents can be freely exchanged between operating systems, because documents are written in standard ascii. Graphics, however, are often machine dependent, so the possibility to include graphics in TeX or LaTeX depends on the operating system and the DVI-driver you are using. This means that including graphics in TeX or LaTeX is often not an easy job.

The solution often adopted for the inclusion of graphics is the incorporation of PostScript pictures in the document using the \special command. The \special command is ignored/passed on by the TeX compiler but the PostScript DVI-driver will use the \special command to insert the PostScript picture at the right place and in the right size in your document. The advantage of this method is that for all operating systems there are PostScript DVI-drivers and that PostScript files are usually also written in standard ascii, therefore you can transfer both text file and graphics to any operating system. The disadvantage of this method is that you can only include PostScript pictures in your document and that you need a PostScript printer to produce output, or Ghostscript, a PostScript interpreter. The standard emTeX screen previewer will not display PostScript pictures.

If you have a PC there are other ways to incorporate pictures in TeX documents. Before we discuss them, we will explain different types of pictures. In principle there are two types of pictures, namely bitmap and vector pictures. A bitmap picture is a matrix with the entries corresponding to points with a color. The dimension of the matrix specifies the height and width of the picture. Because of the fixed matrix, manipulating the picture is difficult and resizing the picture often leads to less satisfactory results. However, many graphic packages produce pictures in a bitmap format. These bitmap files come in many different types, mostly as a result of different compression and color encoding techniques. Examples of bitmap pictures are: GIF (Compuserve), TIFF, PCX (PC Paintbrush), BMP (MS-Windows), IFF (Amiga), LBM (Amiga), IMG (Ventura), CUT (Dr Halo), PCL (Hewlett Packard) and JPEG (Joint Photographic Experts Group).

A vector picture is specified as a device-independent mathematical description and is therefore easy to manipulate/resize. However, the problem with vector pictures is that most DVI-drivers cannot handle them. Examples of vector pictures are: HPGL (Hewlett Packard Graphics Language), PS (PostScript), and EPS (Encapsulated PostScript).

In the sequel of this section we will discuss the programs Graphic WorkShop, Paintshop Pro, HP2xx, BM2Font, PCLtoMSP, and Ghostscript. We will end this section by describing how 4TeX combines the strength of all these programs to incorporate graphics in TeX documents.

7.4.1 emTeX and the \special command 

When the TeX compiler encounters a \special command, it will expand its parameter and pass it as such to the DVI file. Nothing else will happen. The DVI-driver is supposed to understand the meaning of the command when it reads the DVI file. DVI-drivers may support different \special commands. Therefore the \special command is output device dependent and it should be ignored if the DVI-driver does not support that specific function. The advantage of the \special command is that you can use device-dependent instructions to produce output, e.g., you can use a PostScript printer to include PostScript pictures in your TeX document.

emTeX defines some \special commands to include PCX (PC Paintbrush), MSP (Microsoft Paint), black and white BMP (MS-Windows) bitmap pictures and PCL (Hewlett Packard) pictures. The syntax of the \special command is:
\special{em:graph  [path]<bitmap file>}
where [path] is an optional path and <bitmap file> is a PCX, MSP, or black and white BMP bitmap file. The upper left corner of the graphic file is located at the reference point of a character. Run length encoded BMP files and 4 color CGA-mode PCX files cannot be used. All non-white pixels of a PCX file are printed (assuming the standard palette). The width of the graphic must not exceed 32760 pixels, the height must not exceed 32766 pixels. The viewer and the printer drivers of the emTeX package will show and print the bitmap. However, it is not possible to manipulate the picture. This means that different drivers will produce different sized pictures (as a result of the resolution of the device driver and the fixed resolution of the bitmap graphic). For a detailed discussion about \special commands see Mattes (1991).

When you want to manipulate the picture (e.g., resizing the picture or color reduction), you can for instance use the shareware program Graphic Workshop. If you us MS-Windows 95 or NT we suggest you use the shareware program Paintshop Pro to do the operations described below.

Graphic Workshop is a program for working with bitmapped graphic files. It will handle most of the popular bitmap formats. Graphic Workshop is a simple, menu driven environment which will let you perform the following operations on graphic files:

If the picture has more than 32 colors and you use the emTeX special command to include a graphic an error will appear when viewing or printing the picture. Too many colors will result in too dark and unfocussed pictures. In that case it is much better to use BM2Font to incorporate the picture into a TeX document.

The problem with bitmap files is their fixed dimension, i.e. the size of the picture will depend on the DVI-driver used. Suppose the bitmap file golfer.pcx has dimensions 550 × 770 dots. Using the picture and a 300 dpi DVI-driver the picture will have a width of 550/300 = 1.83" = 47mm and a height of 770/300 = 2.57" = 60mm. Other DVI-drivers will result in different sizes. The bitmap file is now printed using:

 \begin{figure}[htbp]               %1
 \begin{center}                     %2
  \setlength{\unitlength}{1mm}      %3
  \begin{picture}(47,65)            %4
   \put(0,65){%                     %5
   \special{em:graph golfer.pcx}}   %6
 \caption{This is an example how to
          use pictures in \emtex}   %7
 \label{fig:emtexexample}           %8
 %1 For the figure environment see Lamport (1986) pages 59, 176
 %  [htbp] lists admissible locations:  h=here, t=top of page,
 %  b=bottom of page, p=on separate page
 %  With here.sty you have the extra option H=forced here
 %2 Center the picture horizontally
 %3 We use millimeters as the unit of measurement
 %4 For the picture environment see Lamport pages 101-111
 %5 Normally the picture golfer.pcx will be printed from the
 %  left upper corner of the picture box, but it should be printed
 %  from the left lower corner, therefore we need \put(0,65)
 %6 \special{...} is the emTeX special command to include a
 %  bitmap picture
 %7 Produces a numbered caption on the place where it is issued
 %8 Label the figure for future referencing Lamport (1986)
 %  pages 71, 186
The result is shown in figure 7.3.  


Figure 7.3This is an example how to use pictures in emTeX

There are many macro packages that can help you insert PostScript files in your document, e.g., Psfig, a macro package written by T.J. Darrel (see Section 7.4.5). With the help of a PostScript DVI-driver, figures are automatically scaled and positioned on the page, and the proper amount of space is reserved.

LaTeX users are advised to use the graphics or the graphicx package. These packages provide a more or less unified interface for incorporating several kinds of graphics. See the LaTeX Companion (Goossens et al. (1994)) or the LaTeX Graphics Companion (Goossens et al. (1997)) for an in depth discussion of its features, or see the on-line documentation.

7.4.2 BM2Font 

BM2Font is a program written by F. Sowa and is used to convert bitmap pictures to TeX fonts. These TeX fonts can be read by the DVI-drivers and are used to view and print pictures. BM2Font can convert the following bitmap pictures: PCX, GIF, BMP, IFF, LBM, TIFF, IMG, and CUT. For a detailed discussion on how BM2Font works and all the possible parameters we refer to the manual. Note that BM2Font can produce several TeX fonts (i.e. bitmap fonts (extension .pk) and TeX font metric files (extension .tfm)) and that the bitmap fonts are resolution dependent. Therefore, the TeX file becomes resolution dependent.

The program BM2Font can be found in the ?:\emtex\utils directory. Its command syntax is
BM2FONT <bitmap file> [options]
The result of bm2font example.pcx is one or more font files, plus a file called example.tex.

All these files can be found in the directories specified by the environment variables TEXINPUT, TEXFONTS and DIRPXL. With the environment variable TEXINPUT we specify the path where BM2Font searches for the bitmap file. The TEXFONTS specifies the path where BM2Font stores the .tfm files. The environment variable DIRPXL specifies the path for the .pk files, i.e. if DIRPXL=?:\EMTEX\TEXFONTS\PXL and we have specified a resolution of 300 dpi the .pk files are stored in the directory ?:\emtex\texfonts\pxl300. If these environment variables do not exist the files are written to the current directory. The file example.tex (written to the current directory) uses the picture fonts and defines a macro called \setexample (i.e. consisting of the the word `set' and the filename `example' (without file extension)). The picture is now produced simply by giving the command \input{example.tex} and the command \setexample on the location where you want the picture.

We will end this section with an example. Suppose we have a BMP bitmap file kitten.bmp and we want to convert this bitmap to TeX fonts for a 300 dpi printer. Running BM2Font 

will result in one TeX font metric file (kittena.tfm), one font (kittena.pk), and the TeX file kitten.tex containing the macro \setkitten. The parameters -h and -v are the horizontal and vertical resolution of the printer, the parameters -m and -n are the width and height you want the picture to be in millimeters. To produce the picture in the TeX document we can use, e.g.:
 % the file kitten.tex defines the macro \setkitten
 \caption{This is the file kitten.bmp converted to \TeX\ fonts}
Figure 7.4This is the file kitten.bmp converted to TeX fonts

BM2Font gives excellent results and is easy to use. A disadvantage howerver is that you need to generate picture fonts for every printer you use. For example when you use a 300dpi laserprinter as well as a 600dpi PostScript printer, BM2Font will give you .pk and .tfm files with the same name but for different printers. To avoid name clashes and wrong picture sizes 4TeX does some bookkeeping: the font files produced by BM2Font are stored in directories named after the printer for which they were generated.

Note: If the length of the filename of the picture file is eight characters, the last character will be omitted for the construction of the .tfm and .pk files (because of the addition of the font numbers a, b, ...). For instance scrndump.pcx will produce scrnduma.tfm, scrnduma.pk, and scrndum.tex and the macro is called \setscrndum.

Note: No digits are allowed in the picture filename. E.g., screen1.pcx has to be renamed to screeni.pcx. This, of course, is the result of the LaTeX macro name constructed by BM2Font using the filename, i.e. in TeX it is not allowed to use digits in macro names.

Note: JPEG pictures are not supported by BM2Font, so 4TeX converts them first to GIF format, using e.g., Graphic Workshop or Paintshop Pro.

Note: If you have an (Enhanced) Windows Metafile (.wmf or .emf) you can use a program like PaintShop Pro or IrfanView to convert the Windows Metafile to one of the graphic formats as described above.

If you have a PCL bitmap file (Hewlett Packard LaserJet and DeskJet graphic output) you can convert this file to a MSP or a PCX bitmap. The conversion can be done by E. Mattes's conversion program pcltomsp. After conversion you can use the special command to include the graphic (see Section 7.4.1) or the program BM2Font to generate TeX fonts. By entering e.g.,

you convert the PCL file graph17.lj to the PCX file graph17.pcx, suppressing the program title and any warnings.

7.4.3 HPGL files and HP2xx 

Some graphics programs produce graphic files in the HPGL format (Hewlett Packard Graphic Language). These are vector pictures specifically made for Hewlett Packard plotters. Because we can only use PostScript and certain bitmap pictures in TeX documents we need to convert such files. The extensions often used for HPGL files are .hpp, .plt, and .hpg and are produced by, e.g., the programs Matlab, Gauss, and Harvard Graphics. To convert HPGL plotter files 4TeX uses the program HP2xx.

HP2xx is a free software program written by H. Werntges that can be used to print, view and convert HPGL plotfiles. It can be found in the ?:\emtex\utils directory. We refer to the documentation for a detailed discussion of all the possibilities (e.g., rotation, picture size, pen color, magnification etc.). 4TeX uses HP2xx to convert HPGL files to PCX bitmap files and EPS (Encapsulated PostScript) files. HP2xx uses no environment variables, it reads and writes the files from the current directory. HP2xx can also display graphs on the screen. It supports super VGA modes. HP2xx is easy to use and its output is of excellent quality. You can convert HPGL pictures to MF (Metafont format), CAD (to be used with TeXcad), EM (emTeX specials), EPIC (the Enhanced Picture style), IMG-, PBM-, PCL- and PCX-bitmaps and EPS pictures.

Suppose we have a file example.hpg. We can convert this file to a PCX bitmap file example.pcx with height 100 mm (the width is automatically calculated, preserving the aspect ratio) using the command

example.pcx can now be used on a 300 dpi output device. Instead of converting the picture to a PCX bitmap we can also convert it to an Encapsulated PostScript file (use -meps and -f example.eps instead of -mpcx and -f example.pcx). After conversion you can proceed as discussed in Section 7.4.5.

As an example we show a Lotus 1-2-3 picture that is generated as a HPGL file and then converted to a PCX bitmap and an EPS picture using the commands described above. After conversion we used the style file figures.sty (see Section 7.4.5) to print the picture in Figure 7.5.  


Figure 7.5An HPGL picture converted to PCX or EPS

7.4.4 PostScript and Ghostscript 

If you want to view, print and manipulate PostScript files and you do not have a PostScript printer (or commercial software), we suggest you use the free software program Ghostscript from Aladdin Enterprises. Using Ghostscript you can view and print .ps and .eps files on almost any screen or printer. Ghostscript also supports the Tseng ET-4000 and the Trident graphics card for viewing in super VGA mode. You can resize the picture to any height and width. You can also calculate the BoundingBox and convert the PostScript picture to a bitmap in e.g., PCX format. This PCX bitmap can be used by the emTeX DVI drivers to view and print the picture in TeX documents on non-PostScript output devices (see Section 6). Ghostscript looks for the specified files in the current directory. If it cannot find a file it will look in the directory specified by the GS_LIB environment variable. For a detailed discussion how Ghostscript works we refer to the Ghostscript documentation. Ghostscript with all its files takes a lot of disk space and is placed in a separate directory ?:\emtex\utils\gstools\gs. Windows 95/NT users are advised to use GsView to view/print .ps, .eps, and .pdf files.

Note: Ghostscript is free software, is regularly updated and gives good results. The only disadvantage is perhaps that it is not very user friendly and poorly documented for beginners.

7.4.5 The FIGURES and PSFIG style files 

Psfig is a macro package written by T.J. Darrell to incorporate PostScript figures in a TeX document. With the help of a PostScript DVI driver, figures are automatically scaled and positioned on the page, and the proper amount of space is reserved. To include a PostScript picture, simply input Psfig at the top of your plain TeX document:
 \input psfig
LaTeX users will include Psfig as follows:
and, when you wish to include a figure, invoke the macro with, e.g., (in LaTeX):
 \caption{The use of PSFIG to insert a PS picture}
The result is shown in Figure 7.6.

Note that spaces in the arguments of the macro are not allowed. For a detailed discussion of all possibilities (e.g., rotation, scaling etc.) we refer to Darrel (1992) and Goossens (1993). The Psfig-macro will generate some \special commands to claim the correct space and size, and with a PostScript DVI driver the picture will be printed correctly.  


Figure 7.6The use of PSFIG to insert a PS picture

The Psfig files can be found in the directory ?:\emtex\inputs\misc. Psfig will look for the specified picture files in the current directory, if not found it will look in the directory specified by the TeX command \psfigurepath. Psfig will first check if the specified file is a PostScript file, i.e. it will check whether the file starts with %!. If not it will generate a warning message. Then it will look for a BoundingBox (i.e. the PostScript command that specifies the location and size of the picture) in the specified picture file, e.g., example.ps. If not found it will look for the BoundingBox in the file example.bb, and if it does not contain a BoundingBox, an error message is displayed. The Psfig-macro will generate some \special commands to claim the correct space and size, and with a PostScript DVI driver the picture will be printed correctly.

The style file Figures is a modification of the Psfig style file and is used in 4TeX. It combines the possibility to print/view PCX pictures with the emTeX special commands, and to print PostScript files as with Psfig. By default (or when using the command \pcx) Figures will try to use PCX picture files. If not found or if you used the TeX command \postscript, Figures will look for PostScript files (.eps and .ps). This makes it possible to view/print pictures using the emTeX special commands and to print the pictures in a TeX document on any printer. To include a picture include the Figures package at the top of your document:
and, when you wish to include the figure (example.pcx or example.eps), call the macro like this:
Note that the extension of the picture file is not specified. All commands defined in the style file Psfig are also available (see e.g., Goossens (1993)). Some names of the macros of Psfig are changed, e.g., \psfig is changed in \putfigure and some extra macros are added, e.g., \pcx (use PCX files), \figurefull (the same as \psfull); \figuredraft (the same as \psdraft).

LaTeX users who prefer to use the graphics or graphicx package might write the following code:
Note that here the file extension (eps in this case) must be supplied.

7.4.6 TeXcad 

TeXcad is a drawing program written by G. Horn for producing drawings in LaTeX documents. It allows the objects available in the LaTeX picture environment to be drawn and edited. Its output is a sequence of LaTeX picture commands which can be inserted into a LaTeX document to generate the drawing. A mouse is not required but strongly recommended. If used, the mouse driver must be loaded before starting TeXcad.

The program can be found in the directory ?:\emtex\utils. When started it will read the parameter file texcad.opt. It will first look in the current directory for this parameter file and if not found it will look in the directory containing texcad.exe. TeXcad supports the special commands of emTeX for line drawing (very useful for drawing lines at any angle) but you should not forget to include the style file emlines2.sty in your document. Likewise, if you use bezier curves, you must include the style file bezier.sty. For a detailed discussion how to install and use TeXcad we refer to Horn (1990).

7.4.7 LaTeXcad 

For LaTeX users the program LaTeXcad by John Leis might be interesting. It is a powerful drawing program that can output a LaTeX picture environment, that can be included in any LaTeX document with little effort. Note that the latexcad.sty is required to compile such a picture.

7.4.8 Mayura Cad 

This MS-Windows program is another fine drawing program, written by Mayura Software. It can output ("export") pictures in EPS, TIFF, Adobe Acrobat PDF, Adobe Illustrator, BMP bitmap and Windows Metafile WMF. Note that if Adobe Type Manager is not installed on your system, the program will warn you that you will not be able to use text in your pictures. All other drawing tools will work, though.

7.4.9 GNUplot 

GNUplot is a general plotting program written by C. Kelly and T. Williams that comes in both an MS-Dos and an MS-Windows version. It is capable off plotting curves from mathematical expressions, or from data files. It can export pictures in a variety of ways. Most important for TeX users are eps (PostScript), LaTeX picture environment (with or without emTeX specials to allow for lines at any angle).

7.4.10 QFig 

QFig is a drawing program written by T. Iwakuma for producing drawings in TeX or LaTeX documents.

Its output is either in PicTeX, eePic, or eePicEmu format. In order to use such a picture you must load the appropriate package before including the picture.

A mouse is not required but strongly recommended. If used, the mouse driver must be loaded before starting QFig. Remember that you can exit the program only by pressing [Ctrl][Q].

The program can be found in the directory ?:\emtex\utils.

7.4.11 Metafont 

Metafont can not only be used to produce fonts. By loading the MFtoEPS package created by B. Jackowski, P. Pianowski and M. Ry´cko you can generate PostScript output (Encapsulated PostScript), readable by e.g., CorelDRAW! and Adobe Illustrator.

See also Section 4.11.

7.4.12 Metapost 

The Metapost system implements a picture-drawing language very much like Knuth's Metafont except that it outputs PostScript code instead of bitmaps. Metapost is a powerful language for producing figures for documents to be printed on PostScript printers. It provides easy access to all the features of PostScript and it includes facilities for integrating text and graphics. The output is in Encapsulated PostScript format. We recommend that you read J. Hobby's Metapost manual.

See also Section 4.12

7.4.13 Summary 

In the preceding sections we have discussed several ways to incorporate graphics in TeX documents.

The main problem when including a picture is to know which program to use and which parameters and commands are needed to get reasonable output. The 4TeX workbench tries to shield you from these dirty bits.

4TeX's Graphics utility helps you incorporate pictures. All the programs discussed above are used, but a user does not need to remember all the (program specific) parameters. Simply choosing from an options list you can specify the parameters. In many cases this is not necessary because most parameters are set automatically (e.g., the printer resolution). The user need only specify the size of the picture and then convert the picture. Converting means that the correct programs are called and that the result is a TeX file that can be used to insert the picture in your document. When for instance you want to include the picture acad.hpp, 4TeX will take care of the necessary conversion and tell you when it is finished that the picture can be inserted simply by adding the style file figures.sty and using the statements:
   \caption{your title}
This way a uniform approach of inserting pictures is reached, i.e. it does not matter if you use HP2xx, BM2Font, PCLtoMSP, or Ghostscript. After conversion only one simple input statement will suffice.

4TeX also makes it possible to view and manipulate the picture. Viewing is also possible in super VGA modes. For instance a PostScript picture can be rotated, a BoundingBox can be calculated and 4TeX magnifies the picture so that it will fit the specified size exactly. The same holds for HPGL pictures. Bitmap pictures can be manipulated using e.g., Graphic WorkShop or Paintshop Pro.

All the necessary bookkeeping is done by 4TeX. For instance the fonts (*.pk and *.tfm) are stored in the correct directories and the conversion file is stored in the current working directory.

The conversion of pictures is done in such a way that it allows you to view and print the TeX document with the pictures on any screen or printer. When you want to use a PostScript printer you need to include the command \postscript in the document.

[next] [prev] [prev-tail] [front] [up]