# Declaring again the same command

I defined a certain command, but now I want to change its definition. I tried to simply change it, but it doesn't compile.

What should I do?

Thank you very much.

EDIT

The former command was

\newcommand{\dt}{\frac{\partial \gamma}{\partial t}}

Then I wanted to change it to

\newcommand{\dt}{\dot{\gamma}}

but it didn't work. Now I tried with

\renewcommand{\dt}{\dot{\gamma}}

but I got this message:

LaTeX Error: \dt undefined.

• Perhaps \renewcommand solves your problem. Please include a minimal working example.showing what you have and what you want if you still need help. – Ethan Bolker Apr 14 '16 at 18:01
• Please be specific as what you mean by "simply chang[ing]" a command. – Mico Apr 14 '16 at 18:04
• Without an example of “before the cure and after the cure” it's difficult to say. – egreg Apr 14 '16 at 18:06

There are several methods:

1. Fresh definition.

\newcommand{\dt}{\frac{\partial \gamma}{\partial t}}

2. LaTeX's \renewcommand requires that the command exists.

\renewcommand{\dt}{\dot{\gamma}}

3. If it is unclear, whether the command is defined, then \providecommand can be used to ensure that the macro is defined.

\providecommand{\dt}{}
\renewcommand{\dt}{\frac{a}{b}}

4. When the macro is assigned to a undefined macro or \relax, then \newcommand thinks that the macro is undefined and does not complain.

\let\dt\relax
\newcommand{\dt}{\mathop{}\!\mathrm{d}t}

5. The TeX primitive \def does not care for a previous definition, it defines and overwrites a previously defined macro.

\def\dt{d^t}


Full example:

\documentclass[a5paper]{article}
\begin{document}

% 1
\newcommand{$$$$$$$$$$\dt$$$$$$$$$$}{\frac{\partial \gamma}{\partial t}}
$$$$$$$$$$\dt$$$$$$$$$$

% 2
\renewcommand{$$$$$$$$$$\dt$$$$$$$$$$}{\dot{\gamma}}
$$$$$$$$$$\dt$$$$$$$$$$

% 3
\providecommand{$$$$$$$$$$\dt$$$$$$$$$$}{}
\renewcommand{$$$$$$$$$$\dt$$$$$$$$$$}{\frac{a}{b}}
$$$$$$$$$$\dt$$$$$$$$$$

% 4
\let$$$$$$$$$$\dt$$$$$$$$$$\relax
\newcommand{$$$$$$$$$$\dt$$$$$$$$$$}{\mathop{}\!\mathrm{d}t}
$$$$$$$$$$\dt$$$$$$$$$$

% 5
\def$$$$$$$$$$\dt$$$$$$$$$${d^t}
$$$$$$$$$$\dt$$$$$$$$$$

\end{document}


• Out of 3-5, is there any way preferrable / "nicer" than the others? I have the feeling that the later ways get "dirtier", is that right? – riddleculous Apr 14 '16 at 18:32
• Thank you very much! But actually I solved my problem just adding two extra brackets, i.e. \newcommand{\dt}{{\dot{\gamma}}} Apparently without those extra brackets I had problems when writing something like $\nabla_\dt$ – Onil90 Apr 14 '16 at 18:47
• @riddleculous 3 is "pure LaTeX", 5 uses the underlying TeX primitive directly and is shorter to write. It is a matter of taste, which style you prefer. – Heiko Oberdiek Apr 14 '16 at 18:59
• @Onil90: this is why you should provide a full example where the error occurred. This is a standard mistake that could have been easily spotted. – riddleculous Apr 14 '16 at 19:01
• @Onil90 Yes, the additional curly braces makes a subformula, which can be used in subscripts and superscripts. In this case is the horizontal spacing not affected. A subformula is set as \mathord in the same way as the "ordinary" \dot{\gamma}. – Heiko Oberdiek Apr 14 '16 at 19:01