Friday, June 08, 2007

Including Figures in LaTeX



Having trouble including figures in your LaTeX document? Here's a procedure I've developed that should work on most computers that have Mathematica on them.

1. Create figure using whatever software you please.

2. Convert the figure to a bitmap file (.bmp). Most photo manipulation software will do this; sometimes the program you used to create the figure will do this.

3. Open Mathematica. Using the File menu, import the bitmap into the current blank notebook. You must import, not open.

4. Select the cell containing the figure.

5. Under the Edit menu in Mathematica, choose Save Selection As...

6. Choose EPS...

7. Save the file in the same directory as the .tex file you are editing.

8. In your LaTeX file, make sure you have the commands

\usepackage{graphics}

and


\usepackage{epsf}

in your header.

9. To include the file, use the following commands:

\begin{figure}
\scalebox{.6}{\epsffile{Filename.eps}}
\caption{Whatever you want to show up in the document explaining the figure goes here.}
\label{Fi:YourLabel}
\end{figure}

This should work. Note that the figure still does not show up in the .dvi file. That's ok. You're going to want to convert your final draft to .pdf. From the Yap dvi viewer, I convert to PostScript (.ps), and then with GhostScript (my postscript viewer), I convert to Portable Document Format (.pdf). The figures show up very nicely in those files, both the PostScript and .pdf files.

Further note: everything from Step 3 on down must occur on the same computer. I tried converting a bitmap to eps on a Mac, and then transferring it to PC. It didn't work.

Further note: Even if you create the figure in Mathematica, you cannot directly save it as a .eps file and expect it to work. You have to "wash" it through the bitmap converter.

Hope this helps. Yes, including figures in LaTeX is a royal pain, but if you follow this procedure, it should work out for you.

Here is a complete document in LaTeX for which this procedure worked.

[begin file FigureExample.tex]
\documentclass{report}

\usepackage{graphics}
\usepackage{epsf}

\begin{document}

Testing the Figure Environment.

\begin{figure}[h]
\scalebox{.4}{\epsffile{Groove.eps}}
\caption{MyLabel}
\label{Fi:Groove}
\end{figure}

Here is a sample document for which this procedure worked.

\end{document}
[end file: FigureExample.tex]

In Christ.


 
Visit Math Help Boards for friendly, free and expert math help.

4 Comments:

At 6/08/2007 02:22:00 PM , Blogger ashley said...

I'm glad you shared this. I would have been pretty lost without it.

;-) Okay couldn't help but tease. :-)

 
At 6/08/2007 11:32:00 PM , Blogger Eltinwe said...

Can you next explain to me which C++ commands you can use in Mathematica, and why? :-D I never could figure that out, I just tried C++ at times because it was so much easier than the Mathematica commands.

 
At 6/11/2007 05:53:00 PM , Blogger Adrian C. Keister said...

Reply to Anna.

Well, I've never used C++ in Mathematica. However, I do have the Mathematica brick - I mean, book. If you're using MathLink (Chapter 12) to do these things, then my book lists the following functions (available in the "mathlink.h" header file):

MLEvaluateString(stdlink, "string") - evaluates a string as Mathematica input.

MLPutInteger(stdlink, int i)
MLPutReal(stdlink, double x)
MLPutIntegerList(stdlink, int *a, long n)
MLPutRealList(stdlink, double *a, long n)
MLPutIntegerArray(stdlink, in *a, long *dims, NULL, long d)
MLPutRealArray(stdlink, double *a, long *dims, NULL, long d)
MLPutString(stdlink, char *s)
MLPutSymbol(stdlink, char *s)
MLPutFunction(stdlink, char *s, long n)
MLGetInteger(stdlink, int *i)
MLGetReal(stdlink, double *x)
MLCheckFunction(stdlink, "name", long *n)
MLGetIntegerList(stdlink, in **a, long *n)
MLGetRealList(stdlink, int **a, long *n)
MLDisownIntegerList(stdlink, int *a, long n)
MLDisownRealList(stdlink, double *a, long n)
MLGetIntegerArray(stdlink, int **a, long **dims, char ***heads, long *d)
MLGetRealArray(stdlink, double **a, long **dims, char ***heads, long *d)
MLDisownIntegerArray(stdlink, int *a, long *dims, char **heads, long d)
MLDisownRealArray(stdlink, double *a, long *dims, char **heads, long d)
MLGetString(stdlink, char **s)
MLGetSymbol(stdlink, char **s)
MLDisownString(stdlink, char *s)
MLDisownSymbol(stdlink, char *s)
MLGetFunction(stdlink, char **s, long *n)

There's more. They're on pages 647 to 691 of The Mathematica Book, Fourth Edition. That would be Chapter 2.12.

Hope that helps.

Love in Christ.

 
At 6/23/2007 12:07:00 PM , Blogger Eltinwe said...

Oh, I don't have Mathematica anymore. That was just how Mr. D decided to ask me to grade his C++ classes for him. He thought it was very inventive to use C++ in Mathematica, and I never could figure out why some worked and some didn't. I guess just some commands were similar.

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home