How to Use Xfig Graphics and LaTeX Together
At a glance
- 1. Choose an export mode
Use combined PDF/LaTeX or PostScript/LaTeX when labels need TeX fonts or mathematics.
- 2. Mark TeX labels
Enter the TeX markup in an Xfig text object and mark it as special text.
- 3. Export both files
Export the graphic and its companion LaTeX file to the same directory.
- 4. Include the companion
Load the companion file with input so LaTeX typesets the labels over the graphic.
Title: How to Use Xfig Graphics and LaTeX Together Category: latex
Short answer: Xfig and LaTeX work best through Xfig’s combined graphic-and-LaTeX export: the drawing is stored as PDF or PostScript, while LaTeX typesets the labels. Mark TeX-formatted labels as special text, export both companion files, and input the LaTeX file in your document. Arbitrary TeX documents cannot be imported into Xfig as fully editable drawings.
---- ARTICLE BODY ----
Xfig is a vector drawing program, not a general TeX editor, so the two programs do not exchange documents symmetrically. The most reliable workflow is to draw shapes in Xfig and let LaTeX typeset the labels when the figure is included. This keeps mathematical notation and fonts consistent with the surrounding document.
Use a combined export
A combined export produces two files: one containing the graphic and another containing LaTeX instructions for placing the graphic and typesetting its text. Xfig and its fig2dev exporter support paired formats such as PDF/LaTeX and PostScript/LaTeX. Choose PDF/LaTeX for a typical pdflatex workflow; choose PostScript/LaTeX when your document uses a DVI-to-PostScript workflow.
In Xfig, create the drawing, add text objects, and mark any text that should be interpreted as TeX as special text. Export the drawing using the corresponding combined format. Keep the graphic and companion LaTeX file together, since the latter refers to the former.
For example, if the export creates diagram.pdf and diagram.pdf_t, a document can include them like this:
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{figure}[ht]
\centering
\input{diagram.pdf_t}
\caption{A diagram exported from Xfig.}
\end{figure}
\end{document}
Compile with pdflatex. The companion file supplies the placement instructions and LaTeX text; the PDF supplies the drawing. The graphicx package is needed because the companion file typically uses graphic inclusion commands. The exact filenames depend on the export settings, so inspect the generated companion file if your names differ.
Put TeX in an Xfig label
A special text object is the way to pass TeX markup through the export instead of treating it as ordinary text. For example, a label might contain $\alpha_i + \beta$ or \emph{Input}. Type the markup in an Xfig text object and set its text type to special before exporting.
There is a practical limitation: Xfig’s canvas preview is not the same as a full LaTeX compilation. A command can look different in the editor, or may not be previewed as it will appear in the final document. The compiled LaTeX output is the authoritative result. Keep special labels simple and test the export early, especially if you use custom macros, unusual fonts, or complicated math.
What “TeX into Xfig” can and cannot mean
If you mean placing a short TeX expression in a figure, use a special text object and the combined export described above. If you mean opening an arbitrary .tex document in Xfig and turning its contents into editable drawing objects, there is no general, faithful conversion. TeX is a programming and typesetting language: a document may depend on macros, packages, fonts, and layout rules that Xfig does not understand.
For a finished equation or page that only needs to appear in a drawing, render it separately to a format that your Xfig version supports, such as EPS or a supported raster format, and import it as an image. If you have a PDF, convert it first if necessary. That preserves its appearance, but usually not as editable text or vector objects within Xfig. If you need the label to match the document’s fonts and macros, keep it as TeX and use the combined export instead.
Why the older LaTeX drawing export can be awkward
Xfig also offers LaTeX picture-style export formats. These represent supported drawing elements using LaTeX picture commands rather than a separate PDF or PostScript graphic. This can be convenient for simple diagrams, but the picture environment has limited drawing capabilities compared with a vector format. Some Xfig objects or effects may be approximated, omitted, or exported differently than expected.
Combined export avoids asking LaTeX to reproduce every line and shape. The graphic format handles the drawing, while LaTeX handles the text. It is usually the better choice when you want both detailed graphics and consistent document typography.
Common mistakes
- Exporting only one file: The companion LaTeX file needs its matching PDF or PostScript graphic. Export both, and do not rename one without updating references.
- Using the wrong compiler: A PDF/LaTeX pair is intended for a PDF-producing workflow; a PostScript/LaTeX pair is intended for a PostScript-based workflow. Do not assume every pair works unchanged with every engine.
- Leaving TeX markup as ordinary text: Ordinary text is exported as text, not necessarily interpreted as TeX. Mark markup that needs TeX processing as special text.
- Expecting a TeX import to remain editable: Imported rendered output is generally an image, not a collection of Xfig text and drawing objects.
- Trusting only the canvas preview: Compile the document and inspect the result. TeX fonts, spacing, and special commands are resolved during compilation.
When the main goal is a clean figure with labels matching the document, use Xfig for geometry and LaTeX for typesetting. Treat the exported pair as one unit and verify it by compiling the document.
References
- Xfig User Manual
- fig2dev(1) manual page
Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.