Putting Visio diagrams into LyX/LaTeX
Today I was again faced with a need to put a Visio diagram into a LaTeX document via LyX. I’ve had this problem before, and I’ve worked it out, but I think I’ve always forgotten to write down how. (If I’m wrong, please give me a link to the entry where I wrote it down, by all means.)
On a side note, I tried using Dia but I just couldn’t bring myself to use it again. I’ve gotten the update version from Dag or FC2 or whatever, compared to the relatively ancient version I used to be running in RH9, but I still can’t get used to it. I can’t seem to transform the rulers from metric into imperial units. I thought there was an option for this, but I can’t find it now. I’m also not sure if it has auto-routing connectors like Visio, but I think it does. Anyway, it generally didn’t seem as easy to use and the little diagram I quickly produced didn’t seem as pretty.
So back to Visio 2003 for me. Here’s how I got my Visio diagram into a LaTeX document through LyX. For starters, my document was only about 3″x3″ so it fit easily on the page. If you need a diagram that takes up the whole page, check on LyX’s site for tips, or maybe the LyX mailing list; I think I saw something about it. Moving on, first you probably want to clip the page size to encompass only your document. Go to File->Page Setup, then the Page Size tab, then “Size to fit drawing contents.” Hit OK and the page size should shrink to the exact size it needs to be. Now save this as a “Windows Metafile (.WMF)” file. WMF is apparently a vector graphics format, as is EPS. I arrived at the need for vector graphics when I wanted to have a graphic at 600 DPI so it would be suitable for printing, but then found that it wasn’t downsampled to whatever resolution LyX/LaTeX/dvips/whatever was using for printing or displaying in a PDF. Sigh.
Here’s the kind of weird part. There’s a libwmf for converting WMF to EPS (among other formats) but it didn’t work very well on my document. So I ended up using wmf2eps which is a Win32 application. Bizarre part: go into its help files and read about how you have to add a printer, and continue reading about how you have to go into the advanced options for the printer and change something or another to “Enhanced Postscript.” In Win2k, the exact setting for that last part is reached through the printer’s properties page, “Advanced” tab, “Printing Defaults” button at the bottom, “Advanced” button again at the bottom of that dialog, then Document Options->PostScript Options->PostScript Output Option from there, and select “Encapsulated PostScript (EPS).” If wmf2eps was running when you made this change, you may need to restart it (I did). Anyway, once you’ve got that set up and selected that “WMF2EPS” printer in wmf2eps, you can tell it to convert your WMF to EPS. This worked fine for me, and then I was able to include the EPS file in LyX. Don’t be super concerned if LyX makes it look like there’s some huge white border around the image: I saw this, but when I did a DVI preview of it (C-d in LyX) everything was right as rain.
wmf2eps (the Win32 application) might have some sort of registration limitation. I notice there’s a pause whenever I start it up. I can’t tell if it’s getting longer. I’m sure if I were to just read the documentation I could find out if there will be further penalties on me if I keep using it. Instead of going to all that trouble, next time I need to do this I’ll seriously consider looking at Adobe Illustrator, which I think I have lying around somewhere. I wouldn’t be surprised if it could open WMF, and I would be surprised if it couldn’t write out EPS.
Update: I tried Illustrator CS and it works like a charm for converting EMF generated by Visio 2003 into EPS. Based on these instructions for embedding an Adobe Illustrator file in LaTeX, I figured out I just needed to turn off thumbnails and set preview to none. (Don’t worry about the ‘version 6 compatibility’ thing there. Also, I had no real success exporting to EPS from File->Export->Adobe Illustrator EPS Legacy.)
Update 2: I have had some problems with going EPS->PDF in LyX. It
uses epstopdf which, in FC2 at least, has some problems with
Illustrator-generated EPS I guess. Really I suspect Illustrator PS
has some problems that epstopdf doesn’t fix. The symptom was gs
hanging around for like six minutes spinning the CPU with nothing in
strace. Then I found a Debian teTeX bug
report
that talks about an apparently substitute/replacement program called
a2ping. So I downloaded a2ping.pl from
http://tug.ctan.org/tex-archive/graphics/a2ping/, stuffed it in my
path, reconfigured LyX’s EPS->PDF translation to use it (slightly
different command line: a2ping $$i pdf: $$o), and all was right.
On a side note, I’ll also note that my old method of going through
ps2pdfwr to get a good looking PDF may not be necessary nor
working on my FC2 box. Now I just use LyX’s pdflatex output path
and I get a nice looking PDF. Look at the curve at the bottom of your
lowercase letter ‘T’ closely and make sure it doesn’t look screwed up,
as happened with everything except pdflatex, I think.
I would not suggest doing it in this way. Its must better, and always gives the correct result if you simply export the diagram as a png with a resolution of 720×720 pixels/in. This gives correct color, shapes, and scaling as apposed to the suggestion you have provided.
There are simply to many problems with most translators today to get the exact output desired. In the end, if you are transforming it into a pdf anyway, take the shortcut, and do what Visio is best at doing. Save the drawing as a normal visio drawing (so that you can always modify it later if needed), then export it as a high resolution png or jpg. Be sure to turn on the transparency feature so you don’t get any wierd results (I always have it to white). And verify that the size of the drawing is set to source.
Let me know what you think.
Greg Pelcha
Comment by Greg Pelcha — Saturday, 28 May 2005 @ 02:17:38
I disagree with Greg; producing PNG files is not much better than a JPG, if you want your figures to look good. After all, you want your figures to look good no matter how they are resized, and PNG fails this basic test, as far as I can tell.
I go through this EPS production through the EMF2EPS (similar to the above mentioned) and though there is some small amount of headache, the output justifies it, I think. The process takes a little longer, but I think if you are taking the time to use LaTeX in the first place, you might as well make your figures look good. Else, you might as well just use Word, and keep your EMF files intact.
Comment by Jonathan Sprinkle — Sunday, 26 June 2005 @ 17:38:42
Visio can export directly to eps - typical M$ that they removed that feature in later versions :-(
Comment by Kenneth Brun — Thursday, 28 September 2006 @ 05:06:38
Why not export to SVG in your diagramming tool, and then use either Inkscape or ImageMagick (both Win32 and Linux versions ought to work) by trying the scripts at: http://wiki.lyx.org/Tips/UseInkscapeSVGImages
Comment by BTreeHugger — Sunday, 03 December 2006 @ 18:04:04
Hey… this saved my life… ok ok… its in danish, but never the less it might be a litle help…
www.hvemerhan.dk/eps.php
well…. combined it with a small bat file in print dir it works like a charm…
_____________________________
@echo off
echo .
echo Based on http://www.hvemerhan.dk/eps.php (install printer WMF2EPS1.32.ZIP
echo and set port to tile + advanced settings set postscriptsettings to EPS
echo and TTfont to kontur). With miktex no need to gosth download
echo .
echo inputfilename: out.eps
echo .
:input
set INPUT=
set /P INPUT=Name of picture (no space): %=%
if “%INPUT%”==”" goto input
echo Your input was: %INPUT%
ps2epsi out.eps %INPUT%.eps
epstopdf %INPUT%.eps
______________________________
I had some problems with the size of my elements were too big and if I just try to rescale in visio all text remains and borders and everything f*** up if you first downscale and the upscale… so i solved this by using the zoom funcion in page propertyes. you have to test a litle bit on the zoom percent. If you have several drawing then remember to do the math based on the widt of THIS drawing… excel is a great helper…
Comment by Mathias — Saturday, 02 February 2008 @ 20:11:36