# [texhax] derivatives and integrals: math operators

Karl Ove Hufthammer karl at huftis.org
Fri Aug 7 09:33:07 CEST 2009

Natércia Fernandes:

> Already in 1997, there was an article published in TUGboat (Typesetting
> mathematics for science and technology according to ISO 31/XI) by Claudio
> Beccari and available at
> http://www.tug.org/TUGboat/Articles/tb18-1/tb54becc.pdf where he says that
> the "d" of derivatives and integrals should be upright (see item number
> 6). It seems to make sense and I've been using it.
>
> But at the same time, I haven't seen it being followed by other people...
> For example, the work of Lars Madsen Introduktion til LaTeX doesn't.
>
> Can anyone clarify this point to me, please?

I think this is *partially* a UK/US or European/US thing, with the US almost
always using the italic d. Personally, I much prefer the upright d.

Here’s the command I use to type it:

% 'Magical' differential operator, that can be used for everything,
% taken from http://www.tug.org/TUGboat/Articles/tb18-1/tb54becc.pdf.
% Using improved (and much shorter) version from Morten Høgholm
<mh.ctan at gmail.com>.
\newcommand*\diff{
\mathop{}\nobreak
\mskip-\thinmuskip\nobreak
\mathrm{d}
}

You use it like this: \int f(x)\diff x.

There’s also one for \partial:
\newcommand*\pdiff{
\mathop{}\nobreak
\mskip-\thinmuskip\nobreak
\partial
}

One advantage of these commands is that they get the spacing right, both for
integrals and other expressions, such as fractions. But for ‘inline’
fractions, e.g., dy/dx, you need this macro the get the spacing perfect:

% And a 'magical' fraction slash, also from Morten Høgholm:
\providecommand*\ifrac[2]{
\begingroup #1 \endgroup
% A Close / so no space before it (unless a punctuation atom is the
% last item in #1 but unlikely).
\mathclose{/}%
% Followed by an empty Open. Thus no space is inserted before the
% denominator.
\mathopen{}%
\begingroup #2 \endgroup
}

It’s also quite useful in that you can easily switch between a \frac and
\ifrac if you later decide one looks better than the other.

--
Karl Ove Hufthammer