The \DeclareMathOperator
command gives the string \mathop
spacing, like the \log
or \cos
operators.
To get \mathord
(ordinary math atom) spacing, wrap it in braces:
\newcommand{\dderiv}[2]{ \frac{{\dd} #1 }{{\dd} #2 } }
The \mathord{\dd}
command will also work, so it’s up to you whether this overcomplicates things or makes it easier to understand why you are wrapping \dd
.
So, for a MWE:
\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\dd}{d}
% Derivative in Leibniz notation d{#1}/d{#2}
\newcommand{\deriv}[2]{ \frac{\mathrm{d}#1 }{ \mathrm{d}#2} }
\newcommand{\dderiv}[2]{ \frac{{\dd} #1 }{{\dd} #2 } }
\begin{document}
\[ \dderiv{x}{t}
\]
\end{document}

You might, however, want operator-like spacing on the left but ordinary spacing on the right of \dd
, for use cases like \dd x \dd y
For example:
\documentclass{article}
\usepackage{amsmath}
\newcommand\dd{\mathop{}\mathrm{d}}
% Derivartive in Leibniz notation d{#1}/d{#2}
\newcommand{\deriv}[2]{ \frac{\mathrm{d}#1 }{ \mathrm{d}#2} }
\newcommand{\dderiv}[2]{ \frac{\dd #1 }{\dd #2 } }
\begin{document}
\[ \iint 1 \dd x \dd y
\]
\end{document}

ETA:
Several commenters thought the second example added excessive space, so I’ll reprint Henri Menke’s tweak from the comments:
\newcommand\dd{\mathop{}\!\mathrm{d}}
\DeclareMathOperator
makes that space. You can look through the various suggestions at tex.stackexchange.com/q/244109/107497, tex.stackexchange.com/q/14821/107497, and tex.stackexchange.com/q/178946/107497.