The following is a document on how to import xfig figures in latex along
with a few tips to make your life easier. 


-------------------------------------------------------------------------

HOW TO IMPORT XFIG 2.1.8 FIGURES IN YOUR LATEX FILES:
-----------------------------------------------------

Filenames
---------

For the figures you create, it is recommended that you use the 
standard extension '.fig' for your figure filenames.

Preparing your Latex file
------------------------- 

There are several formats to which xfig can generate output and 
latex can read. I will only cover three cases:

(A) Export xfig format directly into latex form
(B) Export xfig in encapsulated postscript and import the
    postscript in latex.
(C) Save the figure partly in postscript and partly in latex
    form and superimpose them in your document. 

All three methods have their advantages and are equally simple
to handle. In method (A) the advantage is that all your work 
is in tex form and that your .dvi files will hold all the necessary
information. In (B) you have all the power and fonts of postscript
at your disposal. In (C) you get the drawing power of postscript
and the typesetting of latex for your strings.

----

If you are creating a figure of type (A) or (C) then 
you should have the following alias:

   alias lafig='xfig -specialtext -latexfonts -startlatexFont default'


and then run:

                lafig        

instead of xfig when doing your figures. This will give you the ability
to use tex strings on your figures when you select the LaTeX fonts
from the xfig font menu. You can mix postscript and LaTeX fonts.  You
can also use you usual LaTeX command strings to achieve your desired
output (math mode stuff, bold, etc.)


---

In your latex preamble (the part that preceeds your 
\begin{document} statement) place the following lines:

                \input{psfig}
                \input{transfig}    % only for 2.1.6

You need to place the second line only if you are using xfig 2.1.6.
If you are still using xfig 2.1.6 I strongly recommend you switch over
to the new version. There are many advantages, especially if you inclde 
encapsulated postscript in you documents and if you intend to use
tex strings on your figures. If I haven't managed to convince you
then you can find transfig.tex in

                /usr/X386/lib/X11/transfig

and you should ask your administrator to place it in your default
TeX input file directory. Otherwise you'll have to specify the 
full path to you file.


In 2.1.8 you ahould not place the above command.

So your preamble could look like: 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LaTeX Preamble %%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
\documentstyle[12pt,bezier,amstex]{article}  % include bezier curves
\renewcommand\baselinestretch{1.0}           % single space
\pagestyle{empty}                            % no headers and page numbers
\oddsidemargin -10 true pt      % Left margin on odd-numbered pages.
\evensidemargin 10 true pt      % Left margin on even-numbered pages.
\marginparwidth 0.75 true in    % Width of marginal notes.
\oddsidemargin  0 true in       % Note that \oddsidemargin=\evensidemargin
\evensidemargin 0 true in
\topmargin -0.75 true in        % Nominal distance from top of page to top of
\textheight 9.5 true in         % Height of text (including footnotes and figures)
\textwidth 6.375 true in        % Width of text line.
\parindent=0pt                  % Do not indent paragraphs
\parskip=0.15 true in

\input{psfig}           % Capability to place postscript drawings
%\input{transfig}        % Capability to place transfig pictures,
                        % use only if you are using xfig 2.1.6 (not 2.1.8)
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Document Beginning %%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
\begin{document}
\end{document}



TYPE A - Exporting directly to latex form
-----------------------------------------

Once again, run lafig if you wish to create files 
of this form.

In terms of drawing capabilities this is the weakest form you can use.
Lines in latex can only be drawn at multiples of 30 and 45 degrees. 
And lines with arrows can only be drawn at multiples of 45 degrees.
Several features such as ellipses, splines, etc. are not supported 
(xfig does not take advantage of available LaTeX macro packages 
such as bezier). When drawing lines for type A drawings make
sure you restrict yourself to the proper angle geometry in xfig.
Otherwise when you export your figures to latex format, xfig
will approximate your lines to the nearest angle available in latex.
Usually this has unpleasant results. 

In this mode, you can type any LaTeX string on your 
figure.  Once imported to LaTeX, the string  will be interpreted
properly.  For example:
 
                $\int_0^9 f(x) dx$

would result in a integration from 0 to 9 of the function f(x).
(provided you are in a LaTeX font when typing that string. always
 make sure you are in a latex font in xfig when typing your 
 latex strings).

To create your LaTeX file just choose the export option off the
xfig main menu. And then select LaTeX picture as the language
to export. This will create a file with a .latex extension which
you can then call directly into your latex document. For example
this code would import the file yourfile.latex directly into latex
format:
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Figure 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
\begin{figure}[htbp]
\begin{center}

\input{yourfile.latex} 

\caption{The caption on your figure}
\label{figure:yourreferencename}
\end{center}
\end{figure}



TYPE B - Exporting to Encapsulated postscript
---------------------------------------------

Run xfig if you choose this option. 

There are no limitations in drawing figures of this type. Except that 
one cannot use latex command strings in this format. However all
of the many fonts of postscript are available when this format 
is selected. Once you are done drawing your figure simply choose the 
export menu off of the xfig main menu and select encapsulated postscript 
as your output language. This will create a .eps file which you can then
include into you latex ducument in the following way:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Figure 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{figure}[htbp]
\begin{center}
\ \psfig{file=yourfile.eps}
\end{center}
\caption{Your caption}
\label{figure:yourreference}
\end{figure}
 
TYPE C - Postscript/Latex format 
--------------------------------
 
Run lafig if you choose this option. 
 
You can draw any lines or curves when using this format. 
In this type of export, latex strings are permitted 
you also have the postscript fonts available to you. Therefore
you can type in strings such as

                $\int_0^9 f(x) dx$

and they will be processed by latex. You will need to export
your file twice when using this format: once to the 
combined ps/latex (ps part) language and once to the combined
ps/latex (latex part) language. The first will create a .pstex
file and the second will create a .pstex_t file. The .pstex_t
file automatically calls the .pstex file and you do not need
to include it explicitely in your tex file (users of the previous
version please take note of this.) To include your figure
just use something similar to this if you are using xfig 2.1.8:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Figure 3 of Lecture %%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{figure}[htbp]
\begin{center}
 
\input{yourfigure.pstex_t}
 
\caption{Your figure}
\label{figure:example}
\end{center}
\end{figure}

N.B. You might want to edit the .pstex_t files created by xfig.
     When it refers to the other file (.pstex) it automatically 
     gives the full path specification to the .pstex file. This
     can be an inconvenience if you move your files to another directory
     If so, your latex processing will fail. I personally prefer to 
     remove the full path specification and only keep the filename. 


SOME OTHER NOTES
----------------

You can import encapsulated postcript files into your latex files.
This is useful if you want to doodle on top of outputs from other
programs. For example you could include a MATLAB drawing and identify
points of interest with strings, lines, circles, etc. Starting from
version 2.1.7 of xfig there is a hook to ghostscript which permits 
you to view the postscript in your drawing. A neat feature. 

If you are stuck with some postscript files and wish to turn them into 
encapsulated postscript then there is a program called ps2epsi which is 
distributed with ghostscript.


