Archive for the 'Latex' Category

Reason for Images not appearing in YAP (DVI viewer) for LaTex

I’ve just sorted out why some images wouldn’t appear in a LaTex document I’ve been working on. The old hands will probably laugh at his (I’m a newbie to LaTex) but there weren’t any errors, just a big hole were the picture should be. This was the latest version of MikTex (2.7.2).

This doesn’t work:

\begin{figure}
  % Requires \usepackage{graphicx}
  \center{
      \includegraphics[width=0.7\textwidth]{"pictures/Factors.eps"}
      \caption{Randomly generated schemes}
      \label{ScatterplotOfFFactors}
  }
\end{figure}

Whereas this is fine:

\begin{figure}
  % Requires \usepackage{graphicx}
  \center{
      \includegraphics[width=0.7\textwidth]{pictures/Factors.eps}
      \caption{Randomly generated schemes}
      \label{ScatterplotOfFFactors}
  }
\end{figure}

What’s the difference? It’s the quotes around the filename ( {pictures/Factors.eps} vs {pictures/Factors.eps} ) – in the first one. I’d been thinking of the filename as a string – but in LaTex it’s not.

If I add quotes the file compiles without error and displays in the DVI viewer not a gap is left where the image should be – remove the quotes and the image displays correctly.

Initially I thought that it was having problems with images in a subdirectory (they’re in a directory called “pictures”) but that was only one of many dead-ends.

This might save someone some time (and sanity). When you’re writing a thesis, the last thing you want is to waste time figuring why the tools won’t work.

This is another example of something that happens so often when programming – seeing what you expect to see. None of the examples had quotes, mine did, and I just didn’t see them.

IMG2PNG – a BMP/JPG/GIF to PNG Batch Converter

I’ve modified a Python program I found on the net to batch-convert a folder of images to PNG format and also create the bounding boxes needed by Latex – a text formatting system wonderful (once you get used to it) for large documents.

The original program JPG2PNG was from
http://www.akehrer.com/wiki/code:jpg2png

I’ve modified it to find and convert BMP & GIF images as well and so called it img2png.py

Put img2png.py in the folder full of images and run it. It will find all the JPG/BMP/GIF images and output PNG versions. I’ve tested the BMP/JPG parts, but not the GIF conversion, but (like all untested code) it should work :-)

    The code should appear here but WordPress
    chokes when I try to upload the Python code
    so here's a download link ...

Download: img2png.py

This work is licenced under a Creative Commons Licence

Creative Commons License Giovanni Moretti – 2007
summarised as: anything that may go wrong is not my fault!