@@ -125,13 +125,23 @@ $endif$
125125$if(graphics)$
126126\usepackage{graphicx,grffile}
127127\makeatletter
128- \def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
129- \def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
130- \makeatother
131- % Scale images if necessary, so that they will not overflow the page
132- % margins by default, and it is still possible to overwrite the defaults
133- % using explicit options in \includegraphics[width, height, ...]{}
134- \setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
128+
129+ % Updating our template following changes to Pandoc
130+ % https://github.com/jgm/pandoc/pull/9666/files
131+
132+ \newsavebox\pandoc@box
133+ \newcommand*\pandocbounded[1]{% scales image to fit in text height/width
134+ \sbox\pandoc@box{#1}%
135+ \Gscale@div\@tempa{\textheight}{\dimexpr\ht\pandoc@box+\dp\pandoc@box\relax}%
136+ \Gscale@div\@tempb{\linewidth}{\wd\pandoc@box}%
137+ \ifdim\@tempb\p@<\@tempa\p@\let\@tempa\@tempb\fi% select the smaller of both
138+ \ifdim\@tempa\p@<\p@\scalebox{\@tempa}{\usebox\pandoc@box}%
139+ \else\usebox{\pandoc@box}%
140+ \fi%
141+ }
142+
143+ % End update
144+
135145$endif$
136146$if(links-as-notes)$
137147% Make links footnotes instead of hotlinks:
@@ -220,28 +230,6 @@ $endif$
220230\usepackage{float}
221231\floatplacement{figure}{H}
222232
223- % Centre images
224- \usepackage{etoolbox} % For toggle functionality
225-
226- \newtoggle{infigure} % Create toggle to track if we're inside a figure environment
227- \togglefalse{infigure} % Initialize as false
228-
229- \pretocmd{\figure}{\toggletrue{infigure}}{}{} % Set toggle when entering/exiting figure environments
230- \apptocmd{\endfigure}{\togglefalse{infigure}}{}{}
231-
232- \let\oldincludegraphics\includegraphics % Save the original includegraphics command
233-
234- \renewcommand{\includegraphics}[2][]{ % Redefine includegraphics to check if it's already in a figure
235- \iftoggle{infigure}{%
236- \oldincludegraphics[#1]{#2}%
237- }{%
238- \begin{figure}
239- \centering
240- \oldincludegraphics[#1]{#2}
241- \end{figure}%
242- }%
243- }
244-
245233% Remove "Figure X." prefix from captions
246234\usepackage{caption}
247235\captionsetup[figure]{labelformat=empty}
0 commit comments