I am trying to coax LaTeX to wrangle my figures so that they keep their aspect-ratios but fit the image still on the page in terms of maximum width and height. Pandoc spits out LaTeX beamer code that should do this and that looks correct...except it does not work. Consider:
\documentclass[14pt,aspectratio=169]{beamer}
\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
\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
\begin{document}
\begin{frame}{What are my lengths?}
maxwidth = \the\maxwidth
maxheight = \the\maxheight
linewidth = \the\linewidth
textheight = \the\linewidth
\end{frame}
\begin{frame}{Wide}
\fbox{\includegraphics{wide.png}}
\end{frame}
\begin{frame}{high}
\fbox{\includegraphics{high.png}}
\end{frame}
\end{document}
The really high picture is not very suitable for inclusion in tse, so let me just describe them:
$ file high.png wide.png
high.png: PNG image data, 1000 x 10000, 8-bit colormap, non-interlaced
wide.png: PNG image data, 10000 x 1000, 8-bit colormap, non-interlaced
The minor problem is that the output tells me that maxwidth and maxheight are 0pt. Unimportant, but how do I print it?
The major problem is that the high figure is not shrunk, but goes below where it should go. This has nothing to do with \maxwidth and \maxheight, because the same result obtains with \setkeys{Gin}{width=8in,height=4in,keepaspectratio}.
How do I coax figures in beamer to keep their aspect ratios but try to stretch as far as they can without overflowing the page in both x and y direction? (Advice, as always, appreciated.)


\includegraphics[keepaspectratio,width=\linewidth,height=\textheight,]{example-image}might work, Note:\the\maxwidthonly makes sense when\maxwidthis a length, not a\def. – Steven B. Segletes Dec 20 '21 at 23:36\includegraphics, either. – ivo Welch Dec 20 '21 at 23:45\textheight\textheightin maximum height definition by some like.7\textheight.7\textheight(adjust the .7 to your needs) – Fran Dec 21 '21 at 07:35