5

I am using htlatex (or as many people call it tex4ht) to generate html and I have included some graphics. Htlatex seems to ignore all the size arguments I give the image size. I've tried specifying:

width=\textwidth
width=2in
width=1024px
width=1024pt

All of these have been ignored. Can you specify a size for the image when using htlatex to generate an html version of your document? If yes how does one specify the image size?

Right now I am editing each picture to be the correct size but this is bothersome... I would much rather have one high res picture and then specify a smaller size.

6
7

Following code will help you to grab the width and height dimensions of the graphic provided with your \includegraphics command:

 \makeatletter
    \Configure{graphics}
     {\bgroup
         \Configure{IMG}
            {\HCode{<img src="}}
            {\HCode{" alt="}}
            {" }
            {\HCode{" }}
            {}%
      \Picture+[PIC]{}}
     {\EndPicture
       \HCode{ width="\expandafter\the\csname Gin@req@width\endcsname"
       height="\expandafter\the\csname Gin@req@height\endcsname"
        />}%
      \egroup}
 \makeatother
7
  • how do I use this Latex code? (is it a one time bit that goes in the preamble? is it a macro definition that I use each time I include a graphic? does it go in the options for includegraphics?) – Trevor Boyd Smith Sep 18 '12 at 19:56
  • It is a one time bit to be entered in the preamble. – CV Radhakrishnan Sep 19 '12 at 15:06
  • Sorry, I am unable to make this work. I put the above code into a working .cfg file, and in my tex file, the image is used as \includegraphics[width = 2in]{figs/test.png}, but the image still appears in fullresolution in the generated html. – M-V Sep 23 '12 at 7:11
  • You need to keep *.eps versions of your figures. Since tex4ht relies on .dvi and hence dvips driver of graphicx package is made use of, only .eps files will provide all the functionality of \includegraphics. Also, remove the extension .png from your your included graphic file names. – CV Radhakrishnan Sep 24 '12 at 7:06
  • With TeXLive under Ubuntu I get the error (I report just a small portion) l.134 --- TeX4ht warning --- \Configure{graphics}? --- l.134 --- TeX4ht warning --- \Configure{IMG}? --- and ...such style files MUST BE UPDATED to use Current Standard LaTeX: LaTeX2e.... – mmj Dec 2 '13 at 10:46
0

Since htlatex seems to generate a DVI first, the following answer helped me: Cannot determine size of graphic

So for setting the displayed size of a 530x260 JPG image in HTML, I did:

\includegraphics[width=0.5\textwidth,natwidth=530,natheight=260]{image.jpg}
1
  • 1
    A screenshot of the output would help and we appreciate full examples, not just one-line-code samples ;-) – user31729 Aug 5 '14 at 12:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.