Skip to content

Commit e8877ea

Browse files
committed
graphics fix. HT: Justin Esarey
1 parent 9d8f67b commit e8877ea

1 file changed

Lines changed: 38 additions & 8 deletions

File tree

inst/rmarkdown/templates/article2/resources/template.tex

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,51 @@
248248
\makesavenoteenv{longtable}
249249
$endif$
250250
$endif$
251+
252+
% --------------------------------
253+
% Separating this because this no
254+
% longer works as of pandoc 3.2.1
255+
% -------------------------------
256+
%$if(graphics)$
257+
%\usepackage{graphicx}
258+
%\makeatletter
259+
%\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
260+
%\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
261+
%\makeatother
262+
%% Scale images if necessary, so that they will not overflow the page
263+
%% margins by default, and it is still possible to overwrite the defaults
264+
%% using explicit options in \includegraphics[width, height, ...]{}
265+
%\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
266+
%% Set default figure placement to htbp
267+
%\makeatletter
268+
%\def\fps@figure{htbp}
269+
%\makeatother
270+
%$endif$
271+
272+
% ---------------------------------
273+
% This works now: HT: Justin Esarey
274+
% ---------------------------------
251275
$if(graphics)$
252276
\usepackage{graphicx}
253277
\makeatletter
254-
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
255-
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
256-
\makeatother
257-
% Scale images if necessary, so that they will not overflow the page
258-
% margins by default, and it is still possible to overwrite the defaults
259-
% using explicit options in \includegraphics[width, height, ...]{}
260-
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
278+
\newsavebox\pandoc@box
279+
\newcommand*\pandocbounded[1]{% scales image to fit in text height/width
280+
\sbox\pandoc@box{#1}%
281+
\Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}%
282+
\Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}%
283+
\ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both
284+
\ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}%
285+
\else\usebox{\pandoc@box}%
286+
\fi%
287+
}
261288
% Set default figure placement to htbp
262-
\makeatletter
263289
\def\fps@figure{htbp}
264290
\makeatother
265291
$endif$
292+
293+
% ^ saving this note in case I want some kind of conditional operation thingie.
294+
295+
266296
$if(links-as-notes)$
267297
% Make links footnotes instead of hotlinks:
268298
\DeclareRobustCommand{\href}[2]{#2\footnote{\url{#1}}}

0 commit comments

Comments
 (0)