Putting LaTeX into Xfig figures
Thousands of people, particularly those using UNIX (or LINUX or MAC OS X) computers,
use the Xfig program to produce diagrams to be included in their LaTeX
documents.
Frequently, one needs to put mathematical symbols or expressions in their diagrams.
Instructions found on the internet are often vague on how to do this.
Here is an easy solution, which I make available to you. Please send me a "thank you"
email if this solution has proved helpful, or send me any suggestions or comments.
NOTICE: A much fancier and robust version of this is now available at Sourceforge.
It is called fig2ps.
How to set it up (do this only once):
- Copy the /bin/sh shell script (text file) called fig2eps
(which I made up) into a directory (such as ~/bin)
where you put executable files.
Name the file fig2eps.
- Ensure fig2eps is executable via the UNIX command
chmod u+x fig2eps.
- The script relies on the following programs which are commonly
found in UNIX (or LINUX, MAC OSX) setups:
fig2dev, latex, dvips and ps2eps.
You might need to install them, or modify
the script if your instillation uses alternative, equivalent, programs.
How to make diagram:
How to place diagram into LaTeX document:
- Include the line
\usepackage{graphicx}
in your LaTeX source-file preamble (before "\begin{document}").
- Use something like the following to put the diagram into a figure.
Of course you can change the width to scale the diagram.
\begin{figure}[htb]
\begin{center}
\includegraphics[height=3.0cm]{mydiagram.eps}
\end{center}
\caption{This is my fabulous xfig-generated diagram with embedded LaTeX commands.}
\label{fig:figWithLatexDiagram}
\end{figure}
- Typeset your .tex file using standard latex, NOT pdflatex.
- If you must use pdflatex, be aware that it expects diagrams to be in PDF format.
You must convert mydiagram.eps to mydiagram.pdf using a program like ps2pdf
or pstopdf. You can automate this by uncommenting some lines in the fig2eps script.
However, this can screw up BoundingBox information, resulting in diagrams
which are not well centred or too small. You are on your own here, but
this website
might prove helpful.
Alternatively, try omitting the .eps extension in the .tex file, like
\includegraphics[height=3.0cm]{mydiagram}
You are on your own here!
Problems I have seen
Side Effects
The fig2eps script creates a few temporary files in your /tmp/ directory,
and reports what it is doing in the command window. The script normally deletes these
temporary files during cleanup. If the script fails and the cleanup does not proceed,
then do not worry. The /tmp/ directory is wiped out each time you reboot a UNIX machine.
Disclaimer
The usual disclaimers hold, as detailed in the file fig2eps.
You may have to slightly modify the file, such as the location
of your temporary directory, and program names.
The script is not terribly robust against program errors etc (volunteers?).
Have fun with it!
Modified: 2009.11.25 by goddyn@sfu.ca
(Luis Goddyn)