Consider the following document:
Code: Select all
\documentclass{article}
\usepackage{amsmath}
\makeatletter
\providecommand*{\diffoperator}%
{\@ifnextchar^{\diff}{\diff^{}}}
\def\diff^#1{%
\mathop{\mathrm{\mathstrut d}}%
\nolimits^{#1}\gobblespace
}
\def\gobblespace{%
\futurelet\diffarg\opspace}
\def\opspace{%
\let\DiffSpace\!%
\ifx\diffarg(%
\let\DiffSpace\relax
\else
\ifx\diffarg\[%
\let\DiffSpace\relax
\else
\ifx\diffarg\{%
\let\DiffSpace\relax
\fi\fi\fi\DiffSpace}
\makeatother
\begin{document}
Consider the following examples:
\begin{equation*}
\int_{a}^{b}\text{foal}(t) \operatorname{d}t = \text{horse}
\end{equation*}
versus
\begin{equation*}
\int_{a}^{b}\text{foal}(t) \diffoperator t = \text{horse}.
\end{equation*}
\end{document}
Thank you in advance!
PS. The code for creating the second differential operator was found in the article ``Typesetting mathematics for science and technology according to ISO31/XI'' in TUGBoat 18:1.