15

I usually create figures for my articles in Matlab: various plots of numerical and analytical solutions. One thing that I don't like about it is that the font is different in the figure and in the resulting paper. Another thing is that it is a pain to put nicely typeset math into the figure directly.

My solution: psfrag.

psfrag allows text in a postscript file to be replaced by LaTeX so I would put a label AA (for example) where I want it in the figure, and then in LaTeX write \psfrag{AA}{$my formula$}.

This isn't such a great solution because it depends on psfrag (and journals do not like that), so I use fragmaster.pl which creates the modified pdf and eps files locally from the master file and an auxiliary file with the \psfrag commands...I then \includegraphics these generated files in my article.

This solution is a little roundabout, and so I'll repeat my question from the title:

What is your complete solution for generating nice figures using an external program (for example Matlab)?


Added Later:

After several answers were posted I noticed that none specifically addressed the issue of journals. Several times I've had editors come back to me saying something to the effect of "we'd like to publish your paper, please make sure that the figures you give us are in final form and no changes happen to them during typesetting"...

If would be so kind (and if you know the answer) please modify your answer to include information relating to how journals like your solution.

2
  • It depends on the journal editor. Some journals do like the Laprint + Matlab combination (see my answer). Work with eps files (they are resolution independent) and no journal can complain about resolution issues if you give them an eps file. Commented Aug 26, 2010 at 16:57
  • Just don't use Gimp on an eps file. The file afterwards won't truly be an eps. Commented Aug 28, 2010 at 9:44

8 Answers 8

7

One solution is to export your graphics to a LaTeX-friendly format such as TikZ.

If you use MATLAB, there is a project that aims to export MATLAB figures to TikZ code:

http://github.com/nicki/matlab2tikz

If you are using R, I am the co-author of a graphics device that produces TikZ code- it is available on CRAN. Development releases may be downloaded from R-Forge and bleeding-edge source code can be found on GitHub.

Inkscape can be used along with a plugin that exports to TikZ for general graphics conversion tasks.

The advantage of exporting graphics to a format like TikZ is that there are no discontinuities in font usage or typesetting since LaTeX handles all the text. In the case of the R graphics device the user is also allowed to use the full range of LaTeX commands and packages to typeset arbitrary mathematical notation.

Response to Question Update

One nice thing about TikZ is that graphics can be externalized. This means that the code used to create the graphic is separated and used to compile a stand-alone figure. On subsequent runs the stand alone file is included as an image. Using this system you can leverage the full power of TikZ and then provide your document and a handful of static image files to the Journal minimal changes to your TeX source (basically flipping a switch on or off).

See Automagically externalising pdftricks and TikZ pictures and Script to automate externalizing tikz graphics.

3

I use the overpic package, which essentially combines the abilities of the \includegraphics command and the picture environment. It is used very similarly to the picture environment to place arrows, text, math, circles, etc. as if you were drawing a figure manually in LaTeX, but it also accepts an image file as a parameter which it uses as the background on which to place these elements.

So what I do is generate my graphics externally (e.g. with Matlab or Mathematica) in such a way that they don't include any labels or text. I then use those images as the background and place LaTeX-generated labels and other features on top of them.

One particular advantage of this package is that with the [grid] option specified it generates a numbered grid over the background image to help you figure out where to place your elements. Once they're all in the right place, just remove the [grid] option.

1
  • +1 for overpic. Very helpful in these cases. Commented Aug 26, 2010 at 17:48
2

I also use Matlab to create my graphs as well but I use matlabfrag to export psfrag versions of the EPS graphics instead of Laprint.

My solution to the "journal problem" is a little more generic, however. Haven't written any portable code for it yet because it's not easily generalisable, but the outline is:

  • Use endfloat to send all figures to the end of the document

  • Hide the captions with \renewcommand\@makecaption[2]{}

  • Create a new document that only contains the pages with figures (that should now be blank except for the graphics themselves); e.g., using pdfpages or pdftk

  • Use pdfcrop to trim each page down to the exact size of the graphic

I then have some other macros to use these pregenerated figures in subsequent document compilations, but that's only useful if the journal is actually going to use your TeX source.

5
  • Are you the Will Robertson who has been contributing for the PracTeX journal? I remember the name from this journal as I also contributed one article there. I don't think any PracTeX article has really tried to give practical methods to handle figures in LaTeX. There are some articles but they are quite general in nature. Commented Aug 27, 2010 at 17:54
  • A while back, yes. I was one of the production editors in a former lifetime. I don't recognise your name from your username; are you being anonymous on purpose? Commented Aug 28, 2010 at 3:40
  • I'm not being anonymous :). My user name here has my last name in it. Here's the link to the PracTeX article: tug.org/pracjourn/2008-1/calleecharan Commented Aug 28, 2010 at 9:40
  • Oops, sorry for not recognising you :) Cheers for the link. Commented Aug 29, 2010 at 10:12
  • You're welcome. I know that you have written lots of good and helpful documents out there in LaTeX. It'll be hard for me to forget your name :). Commented Aug 30, 2010 at 19:18
1

I have two solutions:

  1. Some packages, like xfig, allow you to put labels on your figures using LaTeX fonts so it doesn't look too bad. This has the disadvantage that the font size changes when you scale the image, which can mean that you have to do it several times to do it right.
  2. Convert the output of your external program into an .eps or .pdf file without any labelling. Then use the picture environment to place the labels on the figure. This looks something like:

    \begin{figure}
      \begin{picture}(100,100)
        \put(0,0){\includegraphics[scale = 0.7]{myfigure.eps}}
        \put(20,30){My $x$ axis label}
        \put(50,40){Some other label $E = mc^2$}
      \end{picture}
      \caption{The Pope is Catholic}    
    \end{figure}
    

    This has the advantage that it is easy to change the labeling, but of course one has to experiment a bit to get the placement right. I've never had any problems with journals objecting to this usage of the picture environment (although some don't want you to use it to actually draw pictures as they prefer to have the figures in separate files). If they do object then you can always just make a small LaTeX document with just the picture in it and convert the output to .eps or .pdf.

2
  • The nice thing about placing the labels in Matlab and changing them later is that I can place them according to the data...this possibility is lost if one places the labels manually. Xfig....hmmm I never liked that program. Commented Aug 7, 2010 at 16:32
  • If you don't to try xfig, you may want to try Ipe (ipe7.sf.net). It comes with programs that converts pdf figures into Ipe. It messes up text in the figure most of the time, but you want to remove that anyway, and replace it with LaTeX text in Ipe. Commented Aug 8, 2010 at 1:32
1

Use TikZ ;-) Okay, I know that's dodging the question a bit, but I create essentially all the graphics for my documents in TikZ these days, including simple function plots. Elementary functions can be directly plotted by the \plot command in TikZ, and if that doesn't work, TikZ is able to generate a plot using data in an external text file, so you can export the raw numeric data from Matlab and create the plot in TikZ.

For more complicated things like 2D shadings and 3D plots, I've done something like exporting to PStricks and manually editing the output to replace the labels generated by the program with LaTeX labels. For programs that don't have a PStricks exporter (which I think might include Matlab), I can usually export my graphics as SVG (or PS) files, import them into Inkscape, and from there export as PStricks - although I've recently discovered that there is a plugin for Inkscape that can export directly to TikZ, which should make things easier. (At least easier to modify the generated LaTeX source)

1

I use Laprint with Matlab. It is a very robust combination. An eps file is generated together with a tex file in which there are psfrag commands. So in your main LaTeX document, you end up with an eps figure with LaTeX fonts.

Nothing works more perfect! For other types of drawings, I use Adobe Illustrator and in LaTeX I can use psfrag labels on the Adobe Illustrator figure very easily. Maybe Inkscape can be an alternative for those who don't have AI.

The good thing is that you can choose whatever size (and name) of font you want for your labels/tickmarks and this independently of the scale of your diagrams in your LaTeX document.

2
1

I use lpic.

It convenient way to put LaTeX on top of included graphics, in particular the text on your pictures have the same style/size as in the main text --- this is a big advantage.

1
  • Your link gives me a 404 error.
    – lblb
    Commented Sep 30, 2017 at 14:57
0

gnuplot has the epslatex terminal. This allows you to add normal LaTeX commands in labels, titles, and the key. Plus, the output will be a nice .eps file along with a .tex file containing the text. Via epstopdf you can easily compile this for PDFs, too. No journal could possible object to that because no external software is required for them to process your figures.

5
  • Gnuplot is a very good tool. However, the epslatex terminal doesn't have the LaTeX computer modern fonts. Also you can't control the text size of the labels set with this terminal in your main LaTeX document. But the metapost terminal allows this. However the output is not as nice as Laprint with Matlab. This is why I'm sticking to Laprint/Matlab. The diagrams are very neat and one can adjust the text sizes in LaTeX at any time. Commented Aug 26, 2010 at 18:19
  • I had a case where the eps files generated with Gnuplot were much larger than those generated by Laprint/Matlab. I got some help from the Metapost community to reduce the eps filesizes but still they were larger than the Laprint/Matlab solution. Commented Aug 26, 2010 at 18:24
  • @yCalleecharan: I was not aware of any font restrictions. As I said, you can simply write any LaTeX markup in there and the current font will be used. You can even use modifiers such as \textbf{} if you want. I never did compare the file sizes, though, because I always converted to PDFs anyway. Commented Aug 27, 2010 at 12:51
  • I don't remember exactly but with the epslatex terminal once you set a font size it's fixed. If you scale the diagram in LaTeX, then you won't have control over the new size of the fonts and you don't have a possibility in LaTeX to specify the font size you want. This problem is eliminated by the Metapost terminal but I found that the resulting eps files were rather much bigger than the ones produced with the Laprint/Matlab combination. Commented Aug 27, 2010 at 15:52
  • The positive thing with Gnuplot remains of course its variety of options and tools available to get exactly the plot that you want. You can control practically anything on the plotting area. Matlab doesn't seem to have all these options and thus if you are using Laprint/Matlab, you have to play a little in Matlab and then in LaTeX if you need to do some changes. Commented Aug 27, 2010 at 15:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .