Using xfig and jfig with LaTeX

xfig and jfig are fairly intuitive WYSIWYG drawing packages. Below are some of the subtleties of these packages, as well as special instructions for using them with LaTeX. Besides this guide there is a fairly extensive man page for xfig on unix, and there is limited (but important) information under the Help menu in jfig.

Mouse usage

One of the first things you will notice about these programs is that the mouse is not used in the typical "drag-and-drop" fashion. Instead, the program relies on the clicking of specific buttons to indicate the first, intermediate, and last points of a figure. In xfig, there is a box, typically in the upper right-hand corner, that always indicates the function of each mouse button, whatever the context. In jfig, there is a message area at the top which indicates either the function of the button on which the mouse is currently located, or the function of each mouse button if the mouse is located in the canvas.

For example, move the mouse to the button that looks like the outline of the letter "P" (usually found at the far left, near the top). In xfig, a tool tip will indicate "POLYGON drawing", and the "Mouse Buttons" box will indicate that the left mouse button will invoke "Change Mode". In jfig, the message area will read, "create a polygon". Click the left mouse button on this button and move the mouse to the canvas. Both programs will now indicate that the left mouse button is to be used to select the first point. Click the left mouse button somewhere on the canvas. Both programs indicate that the left button selects the next point and that the right button cancels. However, jfig also indicates that the middle button selects the final point; i.e., jfig allows the drawing of a "polygon" consisting of just two points and one line segment. Click the left button somewhere else on the canvas. Now both programs indicate that the middle button selects the final point. You may continue selecting intermediate points with the left mouse button until you are ready to select the last point of the polygon (this is different from the first point). When you are ready for the last point, click the middle button to finish the polygon.

If you are using Windows, you may not have a middle mouse button (at least as far as Windows can tell). If this is the case, holding down the "Alt" key while clicking the left mouse button (in jfig, not xfig) is equivalent to a middle mouse button click. See the "Mouse Buttons..." entry in the Help menu for more details.

Text

xfig and jfig each provide two mechanisms for incorporating text into figures. The first is (nearly) WYSIWYG. Although this method allows you to see more quickly how your figure will look, it suffers from the fact that it can be very difficult to incorporate mathematical text. Furthermore, the software doesn't always render the text exactly like it will appear in the final PostScript output. This particularly the case in jfig on some JVMs which do not render all of the fonts available. Therefore, a second method, allowing you to generate text with LaTeX commands, is also available. Both of these methods may be used in the same figure.

In xfig, when text input is selected, there is a window near the bottom right that shows the current font. If you click on this window, a menu of fonts will appear. By default, this menu will contain the PostScript fonts, which are the font used for WYSIWYG text generation. If you click on the entry, "Use LaTex Fonts", the menu will change to a shorter list of fonts to be used for LaTeX text entry. If you choose one of these fonts, you may include LaTeX commands within your text, and it will later be formatted by LaTeX. However, within xfig you will see only raw LaTeX. To switch the font menu back to PostScript fonts, click the "Use PostScript" entry.

In jfig, when text input is selected, there is a choice box at the bottom containing the choices, "normal" and "special". When "normal" is selected, WYSIWYG text entry is enabled. When "special" is selected, LaTeX text entry is selected.

Generating LaTeX and PostScript

Normally when a figure is saved from either xfig or jfig, it is saved in "fig" format, an ASCII description of the drawing. However, it is possible to convert this format to a variety of formats using fig2dev, which is typically installed on unix systems, and is available for Windows (see Installing jfig on Windows).

xfig interfaces with fig2dev via the "Export" dialog. Although several of the options in its "Language" menu may prove useful, I recommend using the "Combined PS/LaTeX (both parts)" option. Exporting using this option generates two files: a PostScript file with a suffix of pstex and a LaTeX file with a suffix of pstex_t. Most of the graphics will be converted directly to PostScript and saved in the first file. However, any text using LaTeX fonts will be included in the second file as LaTeX commands. The second file will also contain the LaTeX commands necessary to import the first file into the document.

jfig also has an "Export" menu, but don't try to use it - there are too many bugs. Instead, you can use fig2dev directly. Here is a bat file containing the fig2dev commands needed to produce the PostScript and LaTeX files as described in the above paragraph. Assuming you have a file "name.fig" in your current directory and that both pstex.bat and fig2dev.exe are in your search path, the command

pstex name
will produce files name.pstex and name.pstex_t.

Putting everything together

In order to incorporate PostScript into your LaTeX document, you will need to include the following command in the preamble:
\usepackage[dvips]{graphicx}
You can then include a figure contained in the files, "name.pstex" and "name.pstex_t" by using the command:
\input{name.pstex_t}
where you want the figure to appear. The DVI file produced by running latex on this file will contain references to any PostScript files used. Most DVI previewers will import these PostScript files and render the graphics correctly. Running dvips on the DVI file will then produce a single PostScript file containing the entire document.

Copyright 2000, Rod Howell. The syllabus and all lectures for this course are copyrighted materials. During this course, students are prohibited from selling notes to or being paid for taking notes by any person or commercial firm without the express written permission of Rod Howell.

Last updated July 8, 2000.