TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following MWE with some images:

Lorem ipsum dolor sit amet, consectetur adipisici elit:


which compile as expected with pdflatex myfile.tex to pdf output, with one image half of the text width and the other same width as text. Then, using the following config file (needed to obtain images with correct relative sizes):

    {\Picture[pict]{\csname Gin@base\endcsname .jpg
        \space width="\expandafter\the\csname Gin@req@width\endcsname"}}

I compile the same source with htlatex myfile myconfig, in order to obtain an html version of my document. Image sizes are correct among themselves, but they are too small compared to text size. I guess this has something to do with the fact that html has not a fixed page width, so tex4ht has to choose a value to be used has 'page width', and such value is too small, at least for me.

Is there a 'TeX way' to scale all images in html output by a factor?

Of course I could increase the width of images in my latex source, but that would be time consuming and would affect pdf too, which is undesiderable.

Or I could write some external script to parse html output and manipulate image sizes in html source, but I'd prefer a TeX-confined solution.

Someone might like to be informed that the present question arised from this other question.


Given that many days have passed with no answers, I'll open the question to answers which are not TeX-confined. See below for a possible solution.

share|improve this question

Adopting the external script workaround, other issues arised, which luckily found a solution. Basically you have to use a configuration file able to take care of all the image format you have. Here is myconfig.cfg updated in order to take care of jpg, png and eps image formats:

    {\Picture[pict]{\csname Gin@base\endcsname.jpg
        \space width="\expandafter\the\csname Gin@req@width\endcsname"}}
    {\Picture[pict]{\csname Gin@base\endcsname.png
        \space width="\expandafter\the\csname Gin@req@width\endcsname"}}
    {\Needs{"convert -density 110x110 \csname Gin@base\endcsname.eps \csname Gin@base\endcsname.png"}
    \Picture[pict]{\csname Gin@base\endcsname.png
        \space width="\expandafter\the\csname Gin@req@width\endcsname"}}

And here is my post-production Python script able to multiply by a factor width and height attributes of images in html source:

# usage under Ubuntu 12.04 with Python 3.2: python3 fixhtml.py my_html
# requirement: my_html file is expected to be UTF-8 encoded text file

import sys,re
import os.path

if len(sys.argv)!=2:
    print("You need to specify the HTML file you want to process when you call 'fixhtml'. Try again.")
if not os.path.exists(fn):
    print("The file you specified ('"+fn+"')was not found.")

print("Processing HTML file '"+fn+"'...")

def fixall(text,searchpatt,subpatt,factor,factor_group):
    while m:
    return fixed_text+text

factor=2.0 # images enlargement factor
factor_group=2 # factor is found in second group of regex search expression
htmltext=fixall(htmltext,'(?ms)img(.+?)width.*?=.*?"([^"a-zA_Z]+)([a-z]{1,3})"',r'img\1width="%.4f\3"',factor,factor_group) # change the last 3 arguments to suit your needs
htmltext=fixall(htmltext,'(?ms)img(.+?)height.*?=.*?"([^"a-zA_Z]+)([a-z]{1,3})"',r'img\1height="%.4f\3"',factor,factor_group) # each line one passage: add as many you want

import codecs
f = codecs.open("fixed_"+fn,'w',encoding='utf8') # output file name is the same as input with the prefix 'fixed_', file is overwritten if existing
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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