[l2h] \includegraphics with \width=\anewcommand[param]?
Ross Moore
ross@ics.mq.edu.au
Thu, 25 Jul 2002 14:58:31 +1000 (EST)
> Hi:
>
> 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}
> }
This will have trouble, due to the \fitfig command,
as a user-defined macro.
See below for more details.
> It's used like
>
> \insertfigure[0.6]{x-data-flow}{Data Flow in Protocol X}
This is fine, as the parameter data is constant.
> \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 is not fine, as the value to be returned is not knowable
to LaTeX2HTML at the time it substitutes parameters into
user-defined macros.
> 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.
You need to tell LaTeX2HTML about the \fitfig command
before it encounters it in the document itself.
This way it will not be regarded as a user-defined macro.
Do this as follows, within .latex2html-init
or any init-file used by your job:
&ignore_command(<<'_IGNORE_COMMANDS_');
fitfig # {}
#
# other commands can go here, 1 per line
#
_IGNORE_COMMANDS_
Also, you will need to limit the applicability of the
normal LaTeX definition of \fitfig to appear only
within the correct contexts, including images.tex .
\begin{imagesonly}
\newcommand{\fitfig}[1]{......
.....
\end{imagesonly}
%begin{latexonly}
\newcommand{\fitfig}[1]{......
.....
%end{latexonly}
Presumably you are already loading \usepackage{html}
which is needed for the {imagesonly} environment
to be defined for a LaTeX job.
> Any advice on what I can change to fix this?
Try the above.
Hope this helps,
Ross Moore
>
> Thanks,
> Chris <jepeway@blasted-heath.com>.
> _______________________________________________
> latex2html mailing list
> latex2html@tug.org
> http://tug.org/mailman/listinfo/latex2html