This question was basically about whether the differential d should be upright or italicized, not about how to achieve that in tex. However, this useful answer did suggest something like the following for typesetting it:
\newcommand{\der}{\operatorname{d\!}}
This is what I've been doing for a while, but I find that there are a few cases where the spacing is wrong. This code
\der(x^7) \quad \der x \quad \operatorname{d} (x^7) \quad \operatorname{d} x
gives output that looks like this:
The negative thin space looks good for typesetting dx, but bad for d(x^7). Is there a good way to define a single \der
macro that automagically gets both cases right, or is my best option to define two macros and pick one or the other as needed?
physics
.\newcommand*\der{\mathop{}\!\mathrm{d}}
.