linux and windows tips, mathematics, and some recipes

Sunday, July 23, 2006

Using Xfig with LaTeX

Xfig is a program used to create drawings with lines, arcs, and splines. LaTeX is a document preparation tool. How do you use them together? I'll discuss a technique which allows you to use LaTeX strings within your figures (for mathematics, Greek text, etc). The first thing you'll need is the following entries in your LaTeX preamble:
The first package is essential for working with graphics in LaTeX, the second is needed because Xfig enters colouring commands into its LaTeX output (even if all the output is black). Fire up Xfig with the following options:
xfig -specialtext -latexfonts -startlatexFont default
If you don't want to do this every time, just add the following entries to your .Xresources file:
Fig.latexfonts: true
Fig.specialtext: true
Go ahead and make your figure. You can enter LaTeX strings as text, these will later be converted by LaTeX into beautiful mathematics.

When you're done with the figure, save it in the same directory as your LaTeX file, let's suppose you name the figure myfig.fig. Export the file as "Combined PS/LaTeX (both parts)". This will make two new files, myfig.pstex and myfig.pstex_t. When you need to use the file in your LaTeX document, enter something like:
\begin{figure} [ht]
\caption{My figure}
You might not be able to see the effects in the dvi file, but you should be able to see your figure if you run dvips mytexfile.dvi to create a PostScript file.

Working with PDFLaTeX

Similar principles apply if you want to end up with a pdf. Of course one simple solution is to run ps2pdf on your ps file from the previous section, but you may end up losing some pdf-specific features, such as hyperlinks. The recommended alternative is to run pdflatex instead of LaTeX. You'll need some changes to the preamble:
You use Xfig much as before, but this time you export the figure to "Combined PDF/LaTeX". This will produce files myfig.pdftex and myfig.pdftex_t. The latter file replaces myfile.pstex_t in the body of your LaTeX document. When using pdflatex, make sure that your Xfig is in the correct orientation (usually portrait).

Most of the information is this post was gleaned from the Xfig website, which contains much more information on using LaTeX with Xfig.


  • At 5:16 am, Blogger Miller said…

    You have saved me from 8 hrs of agony.Thank you very much.

    is such a life saver.

  • At 9:03 am, Blogger Bintu said…

    Can across you blog? i have one problem using in Latex: package color

    when am my xxx.tex file with figures (using package graphicx) am able to comple ang get the PDF doc.

    But when i want to use package color to mahe come text coloy it not porceding hange with message:
    LaTeX Warning: Reference `fig:Radtransfer' on page 1 undefined on input line 29

    ! Too many }'s.
    \color@endbox ->\color@endgroup \egroup

    l.40 \end{figure}

    can to help me what is this problem.

    thanks bintu

  • At 5:37 pm, Anonymous Anonymous said…

    Hi, bintu:

    have you solved your problem yet? I am running into the exact problem as yours. If you can offer some solution, I would really appreciate it.



  • At 1:38 am, Anonymous Hossein said…

    I had the same problem and, after a long search, found out that if I delete the definition of the "\x@float" from my stuff, everything works fine. For me, it was in the thesis style file that I'm borrowing from colleagues. Check to see where it's for you... :)

  • At 1:41 am, Anonymous Hossein said…

    I had the same problem. After a long search, I found out that if I remove the definition of "\x@float" in my stuff, everything works fine. For me, this was in the thesis style file that I'm borrowing from a colleague. See where that's for you...

  • At 6:04 pm, Blogger Mary H-B said…

    HELP similar error of
    ! Too many }'s.
    \color@endbox ->\color@endgroup \egroup

    l.40 \end{figure}

    I went through and checked all my style files---no "\x@float"

    Now what?? I cannot include color and need to. any assistance is appreciated, MHB


Post a Comment

<< Home