How can I check if a macro is already defined? I want to make a command \dd
. However, if the physics
package is loaded I need to do \renewcommand
and if it is not loaded I need to do \newcommand
. So I want some sort of way to check if the macro \dd
is defined or not.
Here is some pseudocode which showes what I want:
if <\dd> is defined:
\renewcommand ....
else:
\newcommand ...
Here is a MWE:
\documentclass{article}
\usepackage{physics} % may or may not be loaded
% Definition of \dd
% \newcommand*{\dd}{\mathop{}\!{\operator@font d}}
% or
% \renewcommand*{\dd}{\mathop{}\!{\operator@font d}}
\begin{document}
Hello $\dd f$
\end{document}
\providecommand{\dd}{}\renewcommand{\dd}{<what you want>}
\dd
as\mathop{}\!{\operator@font d}
in both cases, you don't have to check whether it's defined, you can just use\def\dd{\mathop{}\!{\operator@font d}}