Tx · LaTeX & TikZ

How Do I Reset a LaTeX \renewcommand?

Published By the 9to5Science editorial team

At a glance

  1. 1. Limit its scope

    Put the redefinition inside a group or environment when it should apply only temporarily.

  2. 2. Let the group end

    LaTeX restores the previous definition automatically when the local scope closes.

  3. 3. Save and restore

    If the change must remain active temporarily in the same scope, save the original meaning and assign it back.

A \renewcommand changes the meaning of a command; it does not provide a built-in “reset” operation. In ordinary LaTeX use, the simplest way to make a redefinition temporary is to put it inside a group. When the group ends, the earlier definition is restored.

If you need the redefinition to last for part of the current scope and then end before that scope closes, save the old definition first and restore it explicitly.

Use a group for a temporary redefinition

Braces create a group in TeX. Definitions made inside the group are local by default, so they stop applying at the closing brace. LaTeX environments also create groups, which means a redefinition inside an environment usually stays local to that environment.

Here is a complete example you can compile:

\documentclass{article}

\newcommand{\status}{Default status}

\begin{document}

Before the group: \status.

{%
  \renewcommand{\status}{Temporary status}%
  Inside the group: \status.
}

After the group: \status.

\end{document}

The first and last lines using \status print “Default status.” Only the line inside the braces prints “Temporary status.” The % characters suppress unwanted spaces at line endings; they are not what restores the command.

This approach is usually best for a local formatting change. It is also the natural choice in an environment: define the changed command in the environment’s begin code, and the environment’s group limits the change to its body.

Restore the definition before the group ends

Sometimes you need a command to change temporarily, then return to its earlier definition while remaining in the same group. Save its current meaning with \let, then use another \let to restore it:

\let\savedstatus\status
\renewcommand{\status}{Temporary status}

% Material that uses the temporary definition goes here.

\let\status\savedstatus

Place these lines where the change should begin and end. \savedstatus receives the meaning that \status had at the time of the first \let. The final line assigns that meaning back to \status.

Choose a saved-command name that does not conflict with another command. If the command is defined or redefined more than once, save it immediately before the particular change you plan to undo.

Which method should you choose?

SituationSuitable method
The change should apply only within a blockPut the redefinition inside { ... }
The change should apply only within an environmentMake the redefinition inside the environment
The change should end at a specific point in the same scopeSave the old meaning with \let, then restore it

A group is safer when it fits the job: the restoration happens automatically, even if you add more material inside the group later. Explicit saving and restoring is useful when the temporary portion does not match a convenient group or environment.

Common mistakes

Redefining the command outside the intended scope. A definition at the document’s top level remains in effect for the rest of that scope. Put the redefinition inside the braces or environment that should limit it.

Expecting \renewcommand to remember an undo point. It replaces the current definition; it does not create a second version that LaTeX can restore on demand. Use grouping or save the old meaning first.

Restoring the wrong version. If you run \let\savedstatus\status after redefining \status, the saved command contains the new meaning. Save it before the redefinition.

Assuming grouping can undo a global definition. Local grouping restores earlier local meanings when it ends. A definition deliberately made global is not undone by closing an ordinary group; avoid global definitions for temporary changes.

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.