Skip to content

Commit 6a28d55

Browse files
committed
graphics fix. HT: Justin Esarey.
1 parent c6b782e commit 6a28d55

2 files changed

Lines changed: 75 additions & 15 deletions

File tree

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

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,47 @@
9999
$if(tables)$
100100
\usepackage{longtable,booktabs}
101101
$endif$
102+
103+
% --------------------------------
104+
% Separating this because this no
105+
% longer works as of pandoc 3.2.1
106+
% -------------------------------
107+
%$if(graphics)$
108+
%\usepackage{graphicx,grffile}
109+
%\makeatletter
110+
%\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
111+
%\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
112+
%\makeatother
113+
%% Scale images if necessary, so that they will not overflow the page
114+
%% margins by default, and it is still possible to overwrite the defaults
115+
%% using explicit options in \includegraphics[width, height, ...]{}
116+
%\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
117+
%$endif$
118+
119+
% ---------------------------------
120+
% This works now: HT: Justin Esarey
121+
% ---------------------------------
102122
$if(graphics)$
103-
\usepackage{graphicx,grffile}
123+
\usepackage{graphicx}
104124
\makeatletter
105-
\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
106-
\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
125+
\newsavebox\pandoc@box
126+
\newcommand*\pandocbounded[1]{% scales image to fit in text height/width
127+
\sbox\pandoc@box{#1}%
128+
\Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}%
129+
\Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}%
130+
\ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both
131+
\ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}%
132+
\else\usebox{\pandoc@box}%
133+
\fi%
134+
}
135+
% Set default figure placement to htbp
136+
\def\fps@figure{htbp}
107137
\makeatother
108-
% Scale images if necessary, so that they will not overflow the page
109-
% margins by default, and it is still possible to overwrite the defaults
110-
% using explicit options in \includegraphics[width, height, ...]{}
111-
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
112138
$endif$
139+
140+
% ^ saving this note in case I want some kind of conditional operation thingie.
141+
% Note: I don't think you really need this, but I'll include it here just in case.
142+
113143
$if(links-as-notes)$
114144
% Make links footnotes instead of hotlinks:
115145
\renewcommand{\href}[2]{#2\footnote{\url{#1}}}

inst/rmarkdown/templates/cv2/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+
% --------------------------------
254+
% Separating this because this no
255+
% longer works as of pandoc 3.2.1
256+
% -------------------------------
257+
%$if(graphics)$
258+
%\usepackage{graphicx}
259+
%\makeatletter
260+
%\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
261+
%\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
262+
%\makeatother
263+
%% Scale images if necessary, so that they will not overflow the page
264+
%% margins by default, and it is still possible to overwrite the defaults
265+
%% using explicit options in \includegraphics[width, height, ...]{}
266+
%\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
267+
%% Set default figure placement to htbp
268+
%\makeatletter
269+
%\def\fps@figure{htbp}
270+
%\makeatother
271+
%$endif$
272+
273+
% ---------------------------------
274+
% This works now: HT: Justin Esarey
275+
% ---------------------------------
251276
$if(graphics)$
252277
\usepackage{graphicx}
253278
\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}
279+
\newsavebox\pandoc@box
280+
\newcommand*\pandocbounded[1]{% scales image to fit in text height/width
281+
\sbox\pandoc@box{#1}%
282+
\Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}%
283+
\Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}%
284+
\ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both
285+
\ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}%
286+
\else\usebox{\pandoc@box}%
287+
\fi%
288+
}
261289
% Set default figure placement to htbp
262-
\makeatletter
263290
\def\fps@figure{htbp}
264291
\makeatother
265292
$endif$
293+
294+
% ^ saving this note in case I want some kind of conditional operation thingie.
295+
% Note: I don't think you really need this, but I'll include it here just in case.
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)