Skip to content

Commit

Permalink
LaTeX: sync pdftex engine default imageresolution with pxunit
Browse files Browse the repository at this point in the history
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'.
  • Loading branch information
jfbu committed Jan 25, 2021
1 parent 0ad3290 commit a786f73
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -68,6 +68,8 @@ Bugs fixed
``:unknown:doc:``)
* #8711: LaTeX: backticks in code-blocks trigger latexpdf build warning (and font
change) with late TeXLive 2019
* #8253: LaTeX: Figures with no size defined get overscaled (compared to images
with size explicitly set in pixels) (fixed for ``'pdflatex'/'lualatex'`` only)

Testing
--------
Expand Down
3 changes: 3 additions & 0 deletions sphinx/templates/latex/latex.tex_t
Expand Up @@ -13,6 +13,9 @@
\ifdefined\pdfpxdimen
\let\sphinxpxdimen\pdfpxdimen\else\newdimen\sphinxpxdimen
\fi \sphinxpxdimen=<%= pxunit %>\relax
\ifdefined\pdfimageresolution
\pdfimageresolution= \numexpr \dimexpr1in\relax/\sphinxpxdimen\relax
\fi
<% if use_xindy -%>
%% turn off hyperref patch of \index as sphinx.xdy xindy module takes care of
%% suitable \hyperpage mark-up, working around hyperref-xindy incompatibility
Expand Down

0 comments on commit a786f73

Please sign in to comment.