[l2h] \includegraphics with \width=\anewcommand[param]?

Chris Jepeway jepeway@blasted-heath.com
Wed, 24 Jul 2002 15:25:38 -0400


Hi:

I'm trying to get a very old LaTeX 2.0.9 doc up on the
web using latex2html.  It's pretty clear that I first
should convert it to a native LaTeX2e doc, and that's
been going well enough.  My biggest problems have been
with images, but I think I've got them licked, at least
in the print version.  Getting them right in the HTML
version, though, has me stumped.

Here is a macro defn I use to wrap \includegraphics.
It gets me labels, captions, and with help from
another macro, \fitfig, scaling.

    \newcommand{\insertfigure}[3][1.0]{
      \begin{figure}[htbp]
	\centering
	\includegraphics[width=\fitfig{#1}]{#2.ps}%
	\vspace{.2in}
	\caption{#3}
	\label{fig:#2}
      \end{figure}
    }

It's used like

    \insertfigure[0.6]{x-data-flow}{Data Flow in Protocol X}

\fitfig handles the scaling factor, here, 0.6.  It returns
the lesser of

    o  the image's natural width scaled by the factor or
    o  the current horizontal width.

As I said, it works fine in the print version (dvips's PostScript,
if that matters).  Here's the defn for \fitfig:

    \makeatletter
    \newcommand{\fitfig}[1]{
      \ifdim#1\Gin@nat@width<\textwidth
	#1\Gin@nat@width
      \else
	\textwidth
      \fi
    }
    \makeatother

This doesn't work at all, though, in the HTML version.
>From images.tex, here's the expansion of \fitfig and
\insertfigure:

    \makeatletter

    %
    \providecommand{\fitfig}[1]{
      \ifdim#1\Gin@nat@width<\textwidth
	#1\Gin@nat@width
      \else
	\textwidth
      \fi
    }
    \makeatother

    %
    \providecommand{\insertfigure}[3][1.0]{ 
      \begin{figure}[htbp]
	\centering
	\includegraphics[width=
      #1\Gin@nat@width<\textwidth
	#1\Gin@nat@width
      \else
	\textwidth
      \fi
    ]{#2.ps}%%

    \vspace{.2in}
	\caption{#3}
	\label{fig:#2}  
      \end{figure}
    }

That's...not right.  The inline expansion of \fitfig
inside \insertfigure breaks things.  Figs in the HTML
look like typeset "@nat@width@natwidth" and so forth.

Any advice on what I can change to fix this?

Thanks,
Chris <jepeway@blasted-heath.com>.