add tag
samcarter
Rmarkdown and/or pandoc have the unfortunate quirk to change the default `Gin` keys for `graphicx` in the preamble. 

This breaks some packages, like `keystroke`. In beamer it can make images vanish.

I know that there are workarounds, I could set the default width and height to some value I like. I could set the height/width of the image instead of using `scale=` and many other possibilities.

However I am wondering if there is a way to undo these global settings. For the aspect ratio, I could do `\setkeys{Gin}{keepaspectratio=false}`, but how to unset the width and height?

---

Here a shortened example of what rmarkdown/pandoc produces:

```
\documentclass{beamer}

% begin nasty stuff from rmarkdown
\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}
% end nasty stuff from rmarkdown

\begin{document}

\begin{frame}
\includegraphics[scale=0.25]{example-image-duck}
\end{frame}

\end{document}

```
Top Answer
Skillmon
In the case of `width` and `height` they have the initial value `!` which we can simply restore by using `\setkeys{Gin}{width=!,height=!}`, together with your `keepaspectratio=false`:

```
\documentclass{beamer}

% begin nasty stuff from rmarkdown
\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}
% end nasty stuff from rmarkdown

% fix nasty stuff (uses knowledge from looking at lines 191 and 192 of
% graphicx.sty:
%   \let\Gin@ewidth\Gin@exclamation
%   \let\Gin@eheight\Gin@ewidth
\setkeys{Gin}{width=!,height=!,keepaspectratio=false}

\begin{document}

\begin{frame}
\includegraphics[scale=0.25]{example-image-duck}
\end{frame}

\end{document}
```

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.