Copyright © 2005 Gene Michael Stover. All rights reserved. Permission to copy, store, & view this document unmodified & in its entirety is granted.
Most of what I do here is discussed in one or more of these sources:
All I'm doing in this essay is trying out what they say, figuring it out now so I can use it when I want it later.
I found two ways to include images. They are:
\epsfig
command. It works except that the HTML version loses
the colour of the original encapsulated Post Script file.
What I'd really like to do is make text in a paragraph flow around a small image in both the printed output & the HTML output. I don't know how to do that yet.
Let's start with a colour JPEG image & put it in a figure so that it displays in both the HTML & the dead tree versions of the document.
Figure 1 shows the figure. The idea is that it looks pretty much the same in the HTML & printed versions of this essay.
Here's how I did that:
\usepackage{epsfig}.
\begin{center}
\begin{figure}
\epsfig{file=04-640.ps}
\caption{My cat, Wordsworth. 2004 December.}
\label{fig-colour-jpeg}
\end{figure}
\end{center}
This technique seems to work for both the PDF output & the HTML output except that in the HTML version, LATEX2HTML converted the encapsulated Post Script image to a Portable Network Graphics (PNG) file & lost the colour in the process.
Some research shows that the loss of colour happens when pstoimg converts the encapsulated Post Script image to a PNG. I experimented with ways to run pstoimg from the command line, & everything I tried lost the colors, so fixing things is not just a matter of correcting how LATEX2html invokes pstoimg. Ideally, it would be a case of improving pstoimg.
Not bad for a first try. I'm surprised & not exactly pleased that, in the printed version, the figure is on the next page, by itself. If a future version of pstoimg preserves colours, this technique will be perfect for figures containing pictures.
I tried using conditional compilation to use the Post Script image in the PDF output & a hyperlink to the JPEG in the HTML output, but no luck. The PDF output is fine, but the HTML output is a great big gray, featureless box. Figure 2 demonstrates.
![]() |
Here is the source code for Figure 2:
\begin{figure}
\htmladdimg{../pho/2004-12/04-640.jpg}
\caption{Using conditional compilation for images in a
figure. Should look fine in {\sc pdf}, but doesn't work
in the {\sc html}.}
\label{fig-conditional-00}
\end{figure}
So that didn't work.
If I don't need the image to be in a figure, conditional compilation works.
Here is an image, outside of a figure, which uses
\epsfig to load an
encapsulated Post Script file
for the PDF output & an hyperlink to the
original image for the HTML version. It switches
between the two commands with conditional compilation.
Here's the LATEX source code which displayed that image:
\begin{latexonly}
\begin{center}
\epsfig{file=04-640.ps}
\end{center}
\end{latexonly}
\begin{htmlonly}
\htmladdimg[ALIGN="CENTER"]{../pho/2004-12/04-640.jpg}
\\
\end{htmlonly}
That's pretty much what I want, though it only works outisde of a figure.
I used \epsfig for the image. For the HTML version, that leads to the problem of lost colours
because LATEX2html must convert it to an image
file. The \includegraphics command should
allow us to use the raw image file for both the PDF
& the html.
Here are some commands I tried from the graphicx package, but they all produce errors at compile-time. I'm not sure, but I think the dvips program may be the one which spews the error.
Here are some things I tried from graphicx:
\includegraphics[width=64mm,height=48]{../pho/2004-12/04-640.jpg}
\includegraphics[bb=0 0 64mm 48mm]{../pho/2004-12/04-640.jpg}
We'll start with a JPEG image. The one I used is at http://cybertiggyr.com/gene/dfx/thumb.jpeg. I got it from Google, & maybe I should make my own to avoid copyright problems.
I saved it as an Encapsulated Post Script file, Post Script level 2, measuring 30 millimeters high by 40 millimeters wide, but I told the Gimp to preserve the aspect ratio, so the actual image might have a slightly differet size.
Here's what I would try if I had the picins package on all my LATEX computers.
\parpic[sr][r]{\includegraphics{thumb.ps}} I used the\parpic command of the picins package to place the image to the right of this paragraph.
I sure don't like the results. In the PDF output file, the image is taller than the paragraph that contains it, & LATEX does not compensate by placing vertical space between that paragraph & the one which follows. What's more, the image is not included at all in the HTML output.
If I want text flow around the image in the
HTML output, but I'll do without the image
in the hard-copy version, I can use the
\htmladdimg
command to achieve it in the HTML version
of the document. The printed version will not show
the image at all, so the text will not flow around
it.
In the HTML version, this paragraph flows around
an image on the right. In the printed version, there
is no image.
(New paragraph) It works fine.
Here's how to put a border around a figure so the reader can more easily see that it's a figure & not part of the text. Such a border is particularly useful for figures whose content is mostly text (such as pseudocode).
This technique doesn't work well, so keep reading until you come to the ``usepackage float / boxed'' technique.
Figure
is a figure
containing pseudocode & without a border.
Table
is an attempt
at a bordered figure containing text by using a
tabular environment inside the figure.
Here is the source code for the figure with the border.
\begin{figure}
\begin{center}
\begin{tabular}{|rl|} \hline
1. & Given: Numbers {\em a} \& {\em b} \\
2. & Let $a^{2} \Rightarrow a \times a$ \\
3. & Let $b^{2} \Rightarrow b \times b$. \\
4. & Let $c^{2} \Rightarrow a^{2} + b^{2}$. \\
5. & Let $c \Rightarrow \sqrt{c^{2}}$. \\
6. & Return {\em c}. \\ \hline
\end{tabular}
\end{center}
\caption{Pseudocode with a border}
\label{fig-pseudocod-borderless}
\end{figure}
Three bummers include:
Here's the best way I know so far to make a figure with a boarder.1
Figure 5 shows a figure with a border. Well, that's what it shows in the LATEX output, such as a DVI, PostScript, or PDF file. As of 2005 November 20, LATEX2HTML does not convert it correctly, so you see a regular figure with ``boxed figure'' before it & ``plain figure'' after it.
boxed figure
plain figureLet's get rid of the ``boxed figure'' & ``plain figure'' garbage in the HTML output. Figure 6 shows the result.
So we get a figure with a border in LATEX & a regular figure (often with a shaded background) in LATEX2HTML. It's not exactly what I wanted, but it's good enough.
Here's the source code for the previous figure:
\ begin{latexonly}
\floatstyle{boxed} \restylefloat{figure}
\ end{latexonly}
\begin{figure}
\begin{center}
\begin{enumerate}
\item Given: Numbers {\em a} \& {\em b}
\item Let $a^{2} \Rightarrow a \times a$
\item Let $b^{2} \Rightarrow b \times b$.
\item Let $c^{2} \Rightarrow a^{2} + b^{2}$.
\item Let $c \Rightarrow \sqrt{c^{2}}$.
\item Return {\em c}.
\end{enumerate}
\end{center}
\caption{Pseudocode with a border in \LaTeX\ output, no
border in {\sc html} output}
\label{fig-pseudocod-boxed2}
\end{figure}
\ begin{latexonly}
\floatstyle{plain} \restylefloat{figure}
\ end{latexonly}
Here are all the instructions about using this technique:
\usepackage{float}. Because it's
only useful to LATEX, I guess you could wrap it in a latexonly environment.
\floatstyle{boxed}
\restylefloat{figure}'' after the
usepackage float. In fact, you could put all three
commands on the same line & wrap them in latexonly.
\floatstyle{boxed}
\restylefloat{figure}'' in front of
the figure & ``\floatstyle{plain}
\restylefloat{figure}'' after the
figure.
Gene Michael Stover 2008-04-20