# How to store the definition of a command? Or, how to disable locally a command?

## what?

I would like to "store" the definition of `\includegraphics` into `\something` so that the following logics will work:

``````% the following line is what I am looking for
store(\includegraphics, \something)
% and then I want to achieve what follows

\renewcommand\includegraphics}[2][]
{}

\doalotofstuff

\renewcommand\includegraphics}[2][]
{%
get_the_definition_from(\something)
}

% now I can again use \includegraphics with its usual definition
``````

Is it possible and easily achievable?

## but why?!

I want to disable the command `\includegraphics` in some parts on my document and be able to get again the usual `\includegraphics` after. This question is related to this post (the solution does not work if the `\includegraphics` command is active.

-
To store it: `\let\savedincludegraphics\includegraphics` and then to restore it `\let\includegraphics\savedincludegraphics` –  Dan Mar 20 '14 at 17:52
Can we assume the local 'place' can form a group (defined scope, not definitions need to 'escape')? –  Joseph Wright Mar 20 '14 at 17:54
@JosephWright I don't understand all the terms of your question, but I think, more or less: YES. –  Colas Mar 20 '14 at 18:11

You want something like

``````\usepackage{letltxmacro}
``````

and

``````\LetLtxMacro\colassavedincludegraphics\includegraphics
\renewcommand\includegraphics[2][]{}
``````

for disabling the command; for reenabling it

``````\LetLtxMacro\includegraphics\colassavedincludegraphics
``````

For the specific command `\let` might be sufficient, but `\LetLtxMacro` is safer for commands that accept optional arguments.

See When to use \LetLtxMacro? for more information about `\LetLtxMacro`.

For environments it depends on how they are defined, but the `comment` package may reveal useful.

-
Thanks! I have asked another question for `environements`, see tex.stackexchange.com/q/166724/8323 –  Colas Mar 20 '14 at 18:28

It seems that you are looking for `\let`:

``````\let\something=\includegraphics
``````
-
Is it possible to do the same with environments??? –  Colas Mar 20 '14 at 18:14
–  Colas Mar 20 '14 at 18:26