diff options
| author | John MacFarlane <[email protected]> | 2024-04-17 22:55:27 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2024-06-23 16:12:37 -0700 |
| commit | 26b25a4428815b04c255e33e95ee86ca7b6ee30e (patch) | |
| tree | c163d151c95dd67fa49e287d78d163d9510cdece /data | |
| parent | 965de61edbd41b4bebea76c557afc99199cf08eb (diff) | |
LaTeX writer: new method for ensuring images don't overflow.
Previously we relied on graphicx internals and made global
changes to Gin to force images to be resized if they exceed
textwidth. This approach is brittle and caused problems
with `\includesvg` (see #9660).
The new approach uses a new macro `\pandocbounded` that is
now defined in the LaTeX template. (Thanks here to Falk Hanisch in
https://github.com/mrpiggi/svg/issues/60.)
The LaTeX writer has been changed to enclose `\includegraphics`
and `\includesvg` commands in this macro when they don't explicitly
specify a width or height.
In addition, the writer now adds `keepaspectratio` to the
`\includegraphics` or `\includesvg` options if `height` is specified
without width, or vice versa. Previously, this was set in the preamble
as a global option.
Compatibility issues:
- If custom templates are used with the new LaTeX writer, they will have
to be updated to include the new `\pandocbounded` macro, or an error
will be raised because of the undefined macro.
- Documents that specify explicit dimensions for an image may render
differently, if the dimensions are greater than the line width or
page height. Previously pandoc would shrink these images to fit,
but the new behavior takes the specified dimensions literally.
In addition, pandoc previously always enforced `keepaspectratio`,
even when width and height were both specified, so images with
width and height specified that do not conform to their intrinsic
aspect ratio will appear differently.
Closes #9660.
Diffstat (limited to 'data')
| -rw-r--r-- | data/templates/default.latex | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/data/templates/default.latex b/data/templates/default.latex index 24d078a39..00e6d4ccf 100644 --- a/data/templates/default.latex +++ b/data/templates/default.latex @@ -302,15 +302,17 @@ $endif$ $if(graphics)$ \usepackage{graphicx} \makeatletter -\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi} -\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi} -\makeatother -% Scale images if necessary, so that they will not overflow the page -% margins by default, and it is still possible to overwrite the defaults -% using explicit options in \includegraphics[width, height, ...]{} -\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio} +\newsavebox\pandoc@box +\newcommand*\pandocbounded[1]{% scales image to fit in text height/width + \sbox\pandoc@box{#1}% + \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}% + \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}% + \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both + \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}% + \else\usebox{\pandoc@box}% + \fi% +} % Set default figure placement to htbp -\makeatletter \def\fps@figure{htbp} \makeatother $endif$ |
