Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a series of TikZ figures which I need to include in Word document (conference requiring Word submissions). Allowed format as EPS and TIFF. The figures are obviously vector graphics; they are

  1. exported into separate .pdf files with pgfplots.external library and \tikzexternalize;

  2. converted to eps using pdftops -eps foo.pdf

  3. import into Word 2003, getting uninformative error (error loading file or such).

I found this this thread on the topic, but it is not conclusive. Curiously, EPS files converted from PDFs created with IPE are imported just fine.

What do I need to change to make the import work?

share|improve this question
    
Is it really required to import EPS files? Aren't PDF files as good? –  egreg Dec 1 '11 at 11:56
2  
I'd just load the PDF in IrfanView (this needs GhostScript installed and a suitably high-resolution setting for the conversion to bitmap) and paste from there. Word's EPS inclusion is patchy at best, and with later versions does not even embed the EPS in the Word file, so there is a loss of vector format whatever approach you take. (I do this routinely for both TikZ graphics and EPS files from other sources. 600 dpi resolution usually does the job without making the Word files too big.) –  Joseph Wright Dec 1 '11 at 11:56
    
@egreg: they require all images to be EPS or TIFF (don't ask me why). –  eudoxos Dec 1 '11 at 11:58
2  
Also, why not use the dvips route to make EPS files directly? –  Joseph Wright Dec 1 '11 at 12:01
1  
I have used this link in the past for the recalculation of the bounding boxes of .eps figures –  percusse Dec 1 '11 at 12:56
show 3 more comments

3 Answers

I summarize my findings. Hopefully others will find it useful.

  1. Since EPS and TIFF figures were allowed, opening the EPS file in Gimp with 600dpi (with antialiasing and color/bw depending on the figure) and saving as TIFF with LZW compression made an importable figure. Despite the bitmap size of 4000x1600 and such, the file size was comparable to that of the EPS figure and looks nice.

    For some reason, trying to achieve the same with ImageMagick's convert -density=600 resulted in weird files, sometimes with monstrous sizes.

  2. As @JosephWright suggested, I tried going via dvips to produce the eps. The problem is that dvips sets wrong bounding box: either it produces non-EPS file, thus having entire page as bbox, or, with -E, the bbox is too small (according to the man page, it computes the boox only from glyphs, but not from lines and other graphics which might show up in the figure).

    The solution was to use dvips -E to produce EPS file with a wrong bounding box, and then fix it with epstool (in Debian, package epstool), as suggested by @percusse. It requires a temporary EPS file (I used the .foo.eps suffix), and the setting for tikz looks like this:

    \usetikzlibrary{pgfplots.external}
    \tikzexternalize[]
    \tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource" && dvips -E -o "\image".foo.eps "\image".dvi && epstool --copy --bbox "\image".foo.eps "\image".eps && rm "\image".foo.eps "\image".dvi }}
    

    The resulting EPS is indeed importable into Word, but it is ugly (probably due to no antialiasing) and rather unusable.

Verdict:

  1. EDIT - gold winner: open in IrfanView, copy, paste into Word directly (thanks to Joseph for the suggestion; I could not do that in my case)

  2. silver winner: have Gimp (ghostscript) do the rendering, save as TIFF and import to Word as bitmap; word is not able to render the EPS nicely, even if it is able to load it.

  3. avoid conferences where submissions must be in Word.

share|improve this answer
2  
As I said, I'd use IrfanView (in my area, there are some operations which have to be done using Word on Windows, and even Word on the Mac is no good, so Windows is a must). –  Joseph Wright Dec 1 '11 at 13:40
    
You can alter the bounding box of an EPS after it's been created, so the auto-generated bounding box is not really a problem. –  Joseph Wright Dec 1 '11 at 13:40
    
I edited the answer to mention IrfanView. –  eudoxos Dec 1 '11 at 14:09
add comment

I had a problem with generating EPS files for Word too (not with TikZ content, but whatever) some time ago. Don't remember the target version (possibly 2003 or 2007), but it took me some time to figure out a successful workflow. In the end I was doing it by:

$ pdf2ps file.pdf - | ps2eps | eps2eps - file.eps

Hope it will work in your case too.

share|improve this answer
add comment

To create TIFFs I would recommend generating a PDF about twice the size of your desired figure, then viewing the PDF in IrfanView and saving as a TIFF so you can produce a high quality image. Note that whey you produce a large figure you will need to vary the marker size, text size, line thickness and tick thickness so the scaled image in Word results in a desirable figure (see code samples below). This is very similar to @JosephWright's method, but saves an image file which is required by some journals separate from the image in the text.

Generate a PDF of your figure with your LaTeX front end, I use a .tex file such as the one here:

\documentclass{article}
\newlength\paperSize
\newlength\figureheight
\newlength\figurewidth
\newlength\markSize

\setlength{\paperSize}{6in}
\usepackage[paperheight=1\paperSize,paperwidth=1.25\paperSize,margin=0in]{geometry}

\usepackage{siunitx}

%for .tikz figures:
\usepackage{pst-all}
\usepackage{pstricks-add}
\usepackage{pgf}
\usepackage{pgfplots}

\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
\usetikzlibrary{plotmarks}

\begin{document}
    \setlength\figureheight{0.65\paperSize}
    \setlength\figurewidth{0.65\paperSize}
    \tikzstyle{every node}=[font=\huge] %vary font size in figure
    \setlength\markSize{5pt} %vary marker size
        \begin{figure}
            \input{sample_figure.tikz}
        \end{figure}
\end{document}

The input file looks like this, where variables are automatically included using mat2tikz (Matlab function file to produce .tikz):

\begin{tikzpicture}

\begin{axis}[%
major tick style={draw=black, thick},
width=\figurewidth,
height=\figureheight,
scale only axis,
xmin=0,
xmax=2,
xtick={0,0.5,...,2},
xlabel={x label text},
ymin=0,
ymax=2,
ytick={0,0.5,...,2},
ylabel={y label text},
legend style={at={(1.03,0.5)},anchor=west,draw=black,fill=white,legend cell align=left}
]
\addplot [
color=black,
only marks,
mark=triangle*,
mark options={mark size=1\markSize,solid}
]
table[row sep=crcr]{
0 0.75\\
1.5 1.25\\
};
\addlegendentry{Legend entry 1};

\addplot [
color=black,
only marks,
mark=square*,
mark options={mark size=0.85\markSize,solid}
]
table[row sep=crcr]{
0.25 1.0\\
0.75 1.75\\
};
\addlegendentry{Legend entry 2};

\end{axis}
\end{tikzpicture}

This is what the PDF looks like: Unaltered PDF

Once you have a PDF of your figure, open with IrfanView and do the following:

  1. Convert to grayscale (ctrl+G)
  2. Auto-crop (ctrl+shift+Y)
  3. Change image resolution to 300 dpi (ctrl+R, 96>300)
  4. Save as TIFF (S, change "Save as type" to "TIF")

Right-clicking and viewing properties should show 300 dpi instead of 96 dpi.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.