[Tex/LaTex] How to renew \includegraphics to always use \shadowbox

graphicsshadows

I want to enclose all \includegraphics into \shadowbox. Therefore I thought to re-define \includegraphics:

\renewcommand{\includegraphics}{\shadowbox\includegraphics}

so that each time \includegraphics is called, actually the graphic is enclosed in a \shadowbox. But the above does not work:

Missing { inserted.
\do@VerbBox l.80 \includegraphics
{0_home_rkrug_Documents_Publications_2012_handbook_Mana… A left
brace was mandatory here, so I've put one in. You might want to delete
and/or insert some corrections so that I will find a matching right
brace soon. (If you're confused by all this, try typing `I}' now.)

Any suggestions how I can redefine \includegraphics ?

Best Answer

I assume you're using \shadowbox from the fancybox package. You need to save the definition of \includegraphics and to pass it to \shadowbox:

\documentclass{article}
\usepackage{graphicx,fancybox,letltxmacro}

% save the meaning of \includegraphics
\LetLtxMacro\latexincludegraphics\includegraphics

% pass the image to \shadowbox
\renewcommand{\includegraphics}[2][]{%
  \shadowbox{\latexincludegraphics[#1]{#2}}}

\begin{document}
\includegraphics[width=1cm]{try}
\end{document}

In this particular case \LetLtxMacro is not really needed and the primitive \let would have sufficed, but this approach is safer whenever commands with optional arguments are redefined.

Note that you lose the possibility of using the *-form, use the clip option instead.