1This description was written by Eric Masson (ericm@kirk.ee.mcgill.ca)
2
3
4The following is a document on how to import xfig figures in latex along
5with a few tips to make your life easier. I wrote this quite a while
6back but it still applies.
7
8Salut,
9
10Eric
11
12HOW TO IMPORT XFIG FIGURES IN YOUR LATEX FILES:
13--------------------------------------------------------------
14
15Getting Started
16---------------
17
18When you call xfig use the following command line:
19
20xfig -specialtext -latexfonts -startlatexFont default
21
22If you want ALL of your figures to be started with special text and
23latex fonts, you can set the following resources in your .Xresources
24or whatever resource file you use:
25
26Fig.latexfonts: true
27Fig.specialtext: true
28
29There are several formats to which xfig can generate output and
30latex can read. I will only cover three cases:
31
32(A) Export Fig format directly into latex form
33(B) Export Fig in encapsulated postscript and import the
34    postscript in latex.
35(C) Save the figure partly in postscript and partly in latex
36    form and superimpose them in your document.
37
38All three methods have their advantages and are equally simple
39to handle. In method (A) the advantage is that all your work
40is in tex form and that your .dvi files will hold all the necessary
41information. In (B) you have all the power and fonts of postscript
42at your disposal. In (C) you get the drawing power of postscript
43and the typesetting of latex for your strings.
44
45---
46
47In your latex preamble (the part that preceeds your
48\begin{document} statement) place the following lines:
49
50                \usepackage{graphicx}
51
52So your preamble could look like:
53
54%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LaTeX Preamble %%%%%%%%%%%%%%%%%%%%%%%%%
56%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57
58\documentstyle[12pt,bezier,amstex]{article}  % include bezier curves
59\renewcommand\baselinestretch{1.0}           % single space
60\pagestyle{empty}                            % no headers and page numbers
61\oddsidemargin -10 true pt      % Left margin on odd-numbered pages.
62\evensidemargin 10 true pt      % Left margin on even-numbered pages.
63\marginparwidth 0.75 true in    % Width of marginal notes.
64\oddsidemargin  0 true in       % Note that \oddsidemargin=\evensidemargin
65\evensidemargin 0 true in
66\topmargin -0.75 true in        % Nominal distance from top of page to top of
67\textheight 9.5 true in         % Height of text (including footnotes and figures)
68\textwidth 6.375 true in        % Width of text line.
69\parindent=0pt                  % Do not indent paragraphs
70\parskip=0.15 true in
71\usepackage{color}		% Need the color package
72\usepackage{epsfig}
73
74\usepackage{graphicx}           % Graphics package
75
76%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
77%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Document Beginning %%%%%%%%%%%%%%%%%%%%%
78%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
79
80\begin{document}
81\end{document}
82
83
84TYPE A - Exporting directly to latex form
85-----------------------------------------
86
87In terms of drawing capabilities this is the weakest form you can use.
88Lines in latex can only be drawn at multiples of 30 and 45 degrees.
89And lines with arrows can only be drawn at multiples of 45 degrees.
90Several features such as ellipses, splines, etc. are not supported
91(xfig does not take advantage of available LaTeX macro packages
92such as bezier). When drawing lines for type A drawings make
93sure you restrict yourself to the proper angle geometry in xfig.
94Otherwise when you export your figures to latex format, xfig
95will approximate your lines to the nearest angle available in latex.
96Usually this has unpleasant results.
97
98In this mode, you can type any LaTeX string on your
99figure.  Once imported to LaTeX, the string  will be interpreted
100properly.  For example:
101
102                $\int_0^9 f(x) dx$
103
104would result in a integration from 0 to 9 of the function f(x).
105
106To create your LaTeX file just choose the export option off the
107xfig main menu. And then select LaTeX picture as the language
108to export. This will create a file with a .latex extension which
109you can then call directly into your latex document. For example
110this code would import the file yourfile.latex directly into latex
111format:
112
113%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Figure 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116
117\begin{figure}[htbp]
118\begin{center}
119
120\input{yourfile.latex}
121
122\caption{The caption on your figure}
123\label{figure:yourreferencename}
124\end{center}
125\end{figure}
126
127
128TYPE B - Exporting to Encapsulated postscript
129---------------------------------------------
130
131There are no limitations in drawing figures of this type. Except that
132one cannot use latex command strings in this format. However all
133of the many fonts of postscript are available when this format
134is selected. Once you are done drawing your figure simply choose the
135export menu off of the xfig main menu and select encapsulated postscript
136as your output language. This will create a .eps file which you can then
137include into you latex ducument in the following way:
138
139%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Figure 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142
143\begin{figure}[htbp]
144\begin{center}
145\ \includegraphics[width=4in]{yourfile.eps}
146\end{center}
147\caption{Your caption}
148\label{figure:yourreference}
149\end{figure}
150
151TYPE C - Postscript/Latex format
152--------------------------------
153
154You can draw any lines or curves when using this format.
155In this type of export, latex strings are permitted
156you also have the postscript fonts available to you. Therefore
157you can type in strings such as
158
159                $\int_0^9 f(x) dx$
160
161and they will be processed by latex. You will need to export your file to
162the "combined ps/latex (both parts)" language.  This will create both a
163.pstex file and a .pstex_t file. The .pstex_t file automatically calls
164the .pstex file and you do not need to include it explicitely in your
165tex file (users of the previous version please take note of this.)
166To include your figure just use something similar to this:
167
168%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Figure 3 of Lecture %%%%%%%%%%%%%%%%%%%%%
170%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171\begin{figure}[htbp]
172\begin{center}
173
174\input{yourfigure.pstex_t}
175
176\caption{Your figure}
177\label{figure:example}
178\end{center}
179\end{figure}
180
181N.B. You might want to edit the .pstex_t files created by xfig.
182     When it refers to the other file (.pstex) it automatically
183     gives the path specification to the .pstex file. This
184     can be an inconvenience if you move your files to another directory
185     because your latex processing will fail. I personally prefer to
186     remove the full path specification and only keep the filename.
187
188
189SOME OTHER NOTES
190----------------
191
192xfig
193----
194
195You can import encapsulated postcript files into your latex files.
196This is useful if you want to doodle on top of outputs from other
197programs. For example you could include a MATLAB drawing and identify
198points of interest with strings, lines, circles, etc. Starting from
199version 2.1.7 of xfig there is a hook to ghostscript which permits
200you to view the postscript in your drawing. A neat feature.
201
202Use ps2epsi in ghostscript to encapsulate your postscript if you only
203have .ps files.
204
205
206--
207=================================================================
208  Eric Masson - ericm@finnegan.ee.mcgill.ca - FAX: 514 398 4470
209=================================================================
210
211Notes:
212
213	Sometimes one may get "mn" in your LaTeX text.  Here is what one
214	user did to work around that problem:
215
216	The problem was in the \smash part of a command that was generated in
217	the latex part of the export.  If the \mddefault and \updefault are
218	not set properly on your system you need to define them to do nothing.
219
220=================================================================
221Some more notes from Stephen Eglen <stephene@cogs.susx.ac.uk>
222
223* changing the size of pictures in pstex_t
224
225If you just include the picture using
226\input{file.psttext_t}
227you have no way of specifying the size of the picture. There are two
228solutions to this.
229
2301. Draw it the right size in xfig to start with.  Or, when you are
231   exporting the figure, change the magnification of the picture by
232   using the magnification box in the export window.  Either way you
233   have to go back into xfig if you dont like the size of the image in
234   your latex document.
235
2362. Get latex to change the size of the picture, using either \scalebox
237   or \resizebox.  These are general functions for scaling text or
238   pictures from the graphics package:
239
240   \scalebox{factor}{object}
241   Will scale the object by any factor.
242   Factor is just a number (<1 = reduction; >1 = enlargement)
243   Object is normally some text or graphics
244
245   eg: \scalebox{2}{ \input{file.pstex_t} }
246   will scale the picture by 2, dependent on driver (.ps works, but xdvi
247   wont).  Scaling bitmap fonts may produce ugly results, so try and
248   avoid them!
249
250   \resizebox{width}{ht} {stuff}
251
252   will resize "stuff" to be of size width x ht.  Using "!" as an argument
253   retains the aspect ratio of the box.
254   eg \resizebox{5cm}{!}{fat cat} will make "fat cat" appear 5 cm wide,
255   and suitably high.
256   (From p129, Lamport)
257
258=================
259xfig and PDFLaTeX
260=================
261(written by Josselin Mouette <jmouette@ens-lyon.fr>)
262
2631. A STANDARD PDF FILE
264   In xfig, select the "PDF" export filter, which will generate a
265   foo.pdf file.  In your document, put in the preamble :
266    \usepackage[pdftex]{graphicx}
267    \DeclareGraphicsRule{.pdftex}{pdf}{.pdftex}{}
268   and insert your picture with \includegraphics{foo.pdf}
269   You may use all the includegraphics options as well.
270   Pros: Very easy to use.
271   Cons: The text in your figure will appear as is on your document,
272	 using postscript fonts; you cannot put some TeX code in it.
273
2742. A COMBINED PDF/LaTeX FILE
275   This is the method I would recommend in most cases. It may be
276   difficult for the beginner at the first time, but it is really
277   powerful.  If you choose this method, you'll have to set the xfig
278   fonts to LaTeX ones, and to set the "special" attribute of your
279   text boxes. To do this automatically, you can add these 2 lines in
280   your .Xresources or .Xdefaults (depends on your system):
281    Fig.latexfonts: true
282    Fig.specialtext: true
283   Then, when exporting, select the "Combined PS/LaTeX" format. Until
284   there is a "Combined PDF/LaTeX" export filter, you'll have to do an
285   extra manipulation: just launch the script "pstex2pdf" following
286   here (requires epstopdf to work), it will convert the foo.pstex to
287   foo.pdf, and foo.pstex_t to foo.pdftex:
288--- CUT HERE ---
289#! /bin/sh
290for i in `ls *.pstex`; do
291    AZE=`basename "$i" .pstex`
292    if [ -r "$AZE".pdf ] && [ "$AZE".pdf -nt "$AZE".pstex ]; then
293        echo Nothing to do for "$i".
294    else
295        echo -n Converting "$i".
296	epstopdf "$AZE".pstex > "$AZE".pdf
297	echo -n .
298	sed "s/$AZE.pstex/$AZE.pdf/" "$AZE".pstex_t > "$AZE".pdftex
299	echo .
300    fi
301done
302--- CUT HERE ---
303
304   Then, in your LaTeX file, put in the preamble:
305    \usepackage[pdftex]{graphicx,color}
306   The color package is required whenever you put some text in colors.
307   Then include the picture with_
308    \input foo.pdftex_t
309   You can also resize it:
310    \resizebox{3cm}{!}{\input foo.pdftex_t}  % sets the width to 3cm
311   Pros: Whatever is put in your text boxes is treated just as your
312	 document's code; that means you can use your own macros,
313	 which is really cool.
314   Cons: When putting big formulas on your figure, it is sometimes
315	 difficult to predict what place they will take.
316
3173. METAPOST
318   There is nothing special to do in xfig to use MetaPost. All the
319   text you type will be treated as plain TeX code - note, this will
320   be not compiled within your document, so you don't have acess to
321   packages like AMS-TeX, neither have you to your macros.
322   In xfig, export your file with the MetaPost filter, it creates
323   foo.mp.  Then, type mpost foo.mp, it will generate foo.0 (or foo.1,
324   sometimes).  In your document, put this in the preamble:
325    \input supp-pdf.tex
326    \usepackage[pdftex]{graphicx}
327   And to include your figure :
328    \convertMPtoPDF{foo.0}{1}{1}
329   That's it. Quite simple, and you can put a bit TeX inside.
330   Pros: Can be easily included in a dual-output (pdf/dvi) file: for
331	 including it as PS, just put a \includegraphics{foo.0} in the
332	 document.
333   Cons: Not adapted to big formulas, as AMS-LaTeX is not
334	 accessible. Long phrases may look bad as well, if your
335	 document is not in English (babel cannot be used).
336
3374. MULTI-METAPOST
338   This method is designed to be used in PDF presentations. Using the
339   \pause command, it will display step by step the layers of your
340   figure as you click on the button, which can look very nice (and
341   can even be useful sometimes).  All that have been told about
342   MetaPost inclusions is true, but there are a few extra things to
343   know:
344   When creating your figure, be careful with the depth of your
345   objects. When exporting your figure in the MultiMetaPost format,
346   transfig will treat the consecutive depth levels where is an object
347   as a single layer, for example:
348   Circle at depth 51 \__first displayed layer
349   Text at depth 50   /
350   *** Nothing at depth 49
351   Square at depth 48 \
352   Text at depth 48    > Second displayed layer
353   Curve at depth 47  /
354   ... and so on.
355
356   After exporting, mpost foo.mmp will create a set of files named
357   foo.0, foo.1...
358   To include them in the document, you will need the mpmulti.sty
359   provided with the latest version of PPower4 (still in Beta stage at
360   the time of writing).
361   The preamble of your document should look like this:
362    \input supp-pdf.tex
363    \usepackage[pdftex]{graphicx}
364    \usepackage{pause,mpmulti}
365   And to include your animation, just put:
366    \multiinclude{foo}
367   You can adjust it to a defined size by using:
368    \multiinclude[graphics={width=5cm}]{foo}
369   Compile your document, then ppower4 it. Nifty, isn't it?
370   Pros: The only way to insert automatically animations. Benefit of
371	 the existing xfig's depth system.
372   Cons: Are there some ?
373
374