Commits

Georg Brandl committed 19bd5f3

#38: fix behavior with unitless image dimensions.

Comments (0)

Files changed (3)

 Bugs fixed
 ----------
 
+* Fix "illegal unit" error when using pixel image widths/heights.
+
 * Support table captions in LaTeX output.
 
 * Work around a bug in Jinja that caused "<generator ...>" to be
 subdirectory of the output directory on building (e.g. the ``_static`` directory
 for HTML output.)
 
+Interpretation of image size options (``width`` and ``height``) is as follows:
+if the size has no unit or the unit is pixels, the given size will only be
+respected for output channels that support pixels (i.e. not in LaTeX output).
+Other units (like ``pt`` for points) will be used for HTML and LaTeX output.
+
 Sphinx extends the standard docutils behavior by allowing an asterisk for the
 extension::
 

sphinx/latexwriter.py

             return width_str
         res = width_str
         amount, unit = match.groups()[:2]
-        if unit == "px":
-            # LaTeX does not know pixels but points
-            res = "%spt" % amount
+        if not unit or unit == "px":
+            # pixels: let LaTeX alone
+            return None
         elif unit == "%":
             res = "%.3f\\linewidth" % (float(amount) / 100.0)
         return res
             pre.append('\\scalebox{%f}{' % (attrs['scale'] / 100.0,))
             post.append('}')
         if attrs.has_key('width'):
-            include_graphics_options.append('width=%s' % (
-                            self.latex_image_length(attrs['width']), ))
+            w = self.latex_image_length(attrs['width'])
+            if w:
+                include_graphics_options.append('width=%s' % w)
         if attrs.has_key('height'):
-            include_graphics_options.append('height=%s' % (
-                            self.latex_image_length(attrs['height']), ))
+            h = self.latex_image_length(attrs['height'])
+            include_graphics_options.append('height=%s' % h)
         if attrs.has_key('align'):
             align_prepost = {
                 # By default latex aligns the top of an image.