Sunday, July 05, 2009

Notes on including Windows screenshots in LaTeX documents

So, the Fundamentals book now has figures. I had to take a few screenshots, and I noticed a few things.

  • If you don't disable font smoothing, then the resulting PDF looks like garbage. The color screenshot is particularly nasty when magnified. Why do we put up with this on monitors? We already have CCD cameras that use stacked color pixels. Can't we make monitors with stacked color pixels too? Please?
  • VisualWorks' topic boxes are drawn in an almost invisible gray under the XP look. I fixed this at a customer site years ago, grr!!! Oh well, back to the Windows 2000 look. In any case, the Windows 2000 screenshots look nicer on the PDF because the layout is simpler and there are less bells and whistles to get distracted with.
  • Using LaTeX and MiKTeX, the behavior of \usepackage{graphicx} depends on the driver you use to compile the document. So, for example, if you want dvi output for fast editing because you are using yap, then you have to write \usepackage[dvips]{graphicx} and include encapsulated postscript files. But, if you want to create a PDF you can send to others, then you need to use the pdflatex driver instead of the dvips driver. Hence, you need to change to \usepackage[pdftex]{graphicx}, and include PNG instead. I wrote some macros that choose to append .eps or .png to filenames depending on the compilation environment so I only have to change things in one place. But why isn't this automatic yet? Is there a way to compile with either dvips or pdflatex and have everything work the same?
  • Of course, you don't include JPG with the graphicx package because of the visual artifacts. Moreover, you don't include PDF because using GhostScript to convert the .eps to .pdf results in a .pdf that thinks it's a whole page and that throws layout off (also, if you use PDF, you also have to be careful to tell GhostScript not to crunch the .eps you made from the .png because otherwise you get visual artifacts just like with JPG). Using .ps instead of .pdf results in more or less the same layout issues. Did I miss something here?
  • Including .png files works great, but including .eps failed at first. The error was cryptic... "TeX capacity exceeded, sorry [.1=200000]". Eventually I figured out that ".1" is shorthand for the "[m]aximum number of characters simultaneously present in current lines of open files and in control sequences between \csname and \endcsname". MiKTeX's configuration file parameter for that amount is conveniently called buf_size. Well, yeah... that makes sense now. The .eps files are about 1.7mb, which is more than 200k. Bumping buf_size by a factor of 100 took care of that problem.
  • Finally, why do dvips and pdflatex appear to work, but the result is a white box with the name of the file instead of the actual screenshot? Because the compilation environment for the LaTeX document is draft, and therefore graphicx decides no graphics should be included. However, I'd rather see what's going on to make sure things look good. Fortunately, you can use draft for the document and final for graphicx, like this: \usepackage[final]{graphicx}. It sounds so simple after you find what's going on...
Ok. Now, back to writing. 332 pages so far.


Damien said...

One for your graphics problem, it should work if you just \usepackage{graphicx} without the driver option (I never put it, and I think it auto detects which tex you're using). Then, omit the extension in the argument to \includegraphics{foo}. PdfTeX will look for foo.pdf, foo.png, etc, and (dvi)TeX for foo.eps.

Andres said...

Thank you! I will try that tomorrow and see what happens.

Andres said...

Damien, perfect! Thank you!

Anonymous said...

I am using pdflatex on OS X via the MacTeX bundle. However when I include a PNG screenshot (taken using the standard Cmd+Shift+4) in my latex document, it is automatically scaled and as a result is rendered like a low-quality image. I think it is related to the DPI settings or something. Any ideas how can I fix this problem?

This isn't a pdflatex problem I guess. Opening the same PNG screenshot using Preview and saving it as PDF will have the same problem. Very frustrating.

Andrés said...

Anonymous, that's something I need to check on. If I look at the PDF and zoom enough, I see every pixel of the screenshot is there. I think the screen scaling is rather coarse (as opposed to, say, lanczos3), but I am not certain. Hopefully this is not the same process used for printing...

Jess said...

I've been having trouble where my graphic is appearing but so is the file name to it...
I've posted a screen shot picture of what I mean on my own blog

I've put \usepackage{graphicx} in the preamble of my root file and I've also tried \usepackage[final]{graphicx} which did not work. And for where I have the image in the actual document I have
\includegraphics[width=5.5in]{figures/Quantum Dot Formation.jpg}
\caption{Quantum dot formation in Ge/Si or SiGe/Si systems}

Please help if you can!

Andrés said...

I am not sure what's going on, and I can't access the URL. Sorry! Maybe somebody else has seen the problem?