# Redefine \includegraphics* (starred version)

I have this code:

\setlength{\fboxsep}{0pt}
\let\includegraphicsbak\includegraphics
\renewcommand*{\includegraphics}[2][]{\colorbox{white}{\includegraphicsbak[#1]{#2}}}


How can I make it work with the starred version of \includegraphics?

I get this error if \includegraphics* is used in the file:

! LaTeX Error: File *' not found.

• you could use NewDocumentCommand rather than newcommand and define a * form of your new command that uses the * form of the original, although I'm surprised you need the star form at all, it doesn't do anything very useful in graphicx it was only really for graphics, which essentially no one uses these days – David Carlisle Feb 6 at 0:53
• @DavidCarlisle, I'm a copy editor and I just found \includegraphics* in a paper I'm editing. I didn't even know of the \includegraphics's starred version. I redefine temporarily '\includegraphics to better check the blank margins of the figure (I use also a colored background for the page). – Gabriele Nicolardi Feb 6 at 1:47
• I just found, not tried (sorry). May be an old-style author. – Gabriele Nicolardi Feb 6 at 1:50

The code shown would also disable the second optional argument of \includegraphics

The second optional and the * form are both really for the graphics package interface which is really not used much so one possibility would be to ignore this aspect. (The star form just adds clip to the supplied keys, so it is more natural to use \includegraphics[clip] than \includegraphics* when using graphicx.)

However you can support all the argument parsing by hooking in the box after the arguments are parsed

\makeatletter
\let\old@Ginclude@graphics\Ginclude@graphics
\def\Ginclude@graphics#1{\colorbox{white}{\old@Ginclude@graphics{#1}}}
\makeatother

• I get: Runaway definition? #1->\colorbox {white}{\old@Ginclude@graphics {#1}} \makeatother \par \ETC. ! File ended while scanning definition of \Ginclude@graphics. – Gabriele Nicolardi Feb 6 at 1:55
• Looks like there is a } missing at the end of the \def line? – henryflower Feb 6 at 9:35
• @henryflower fixed thanks (if the OP had provided a test document I would have tested the answer:-) – David Carlisle Feb 6 at 9:59
• @DavidCarlisle Sorry! – Gabriele Nicolardi Feb 9 at 18:34