Repository navigation
LaTeX: sync pdftex engine default imageresolution with pxunit - #8760
Conversation
Closes: sphinx-doc#8253 The 'pxunit' key from latex_elements instructs how to handle image dimensions specified in px units. But pdftex has \pdfimageresolution which is used when an image file does not provide readable or legit values for the x and/or y resolution. This commit syncs them: from 'pxunit' the default image resolution in pixels per inch (an integer) is computed. This way an image will behave the same if: - it is loaded with no explicit size set, _and_ no readable image resolution data is readable from the file (or that data matches the 'pxunit' setting) - or a size is set in figure directive using px units and equal to the natural pixel size of the image, This also with 'lualatex' but is ignored by with 'xelatex' and 'uplatex'.
|
For testing this change, one can use this in index.rst: .. figure:: image.png
Caption
.. figure:: image.png
:width: 223px
Captionwhere After |
|
Notice that this is breaking change for png images not providing the x-resolution/y-resolution data (which is in pHYs data chunk although the latter may serve only to specify a deviation of pixel shape from square one, and only optionally uses the meter absolute unit) When included without any size specification and assuming Using ImageMagick convert utility on unixen, one can set the image resolution in a png file this way: allowing to check that when a png file does have the pixels per inch (or rather pixels per meter in the pHYs data chunk), using the figure directive with no size spec will have pdftex insert the image in accordance to the pixel resolution set in the file, independently of the setting of |
|
To recap issue #8253 is caused by a number of factors:
It is possible, at least for pdflatex and lualatex, to set the default it uses for images whose data chunks contain no resolution indication. This pull request does this in a manner that makes 1px used in a width or height specification match with the default dpi used for images with no resolution data. This means that from then on an image file will behave the same, if it has no resolution data, whether included with no size specification or included with a target width expressed in px and matching its natural x-size in px. This will work independently of the Nothing changes for
I don't know how to achieve this with xelatex and uplatex |

Closes: #8253
The 'pxunit' key from latex_elements instructs how to handle image
dimensions specified in px units.
But pdftex has \pdfimageresolution which is used when an image file does
not provide readable or legit values for the x and/or y resolution.
This commit syncs them: from 'pxunit' the default image resolution in
pixels per inch (an integer) is computed.
This way an image will behave the same if:
it is loaded with no explicit size set, and no readable image
resolution data is readable from the file (or that data matches the
'pxunit' setting)
or a size is set in figure directive using px units and equal to the
natural pixel size of the image,
This also with 'lualatex' but is ignored by with 'xelatex' and
'uplatex'.
Bugfix
Relates
It is hard to provide unit test, because one would have to examine logs of a latex build, and the data inthere might change according to latex upgrades.
This will change the size of images loaded with no explicit dimension set, if the graphics file has no x-resolution or no such resolution understood by pdftex. For this reason I make this PR for merge into master.