I like to define a macro with an optional parameter. As an example, consider a macro for the differential:
\documentclass[11pt]{article}
\usepackage{amsmath}
\usepackage{bm}
\newcommand\drm{\mathop{}\!\mathrm{d}}
\newcommand\Drm[1]{\mathop{}\!\mathrm{d^#1}}
\begin{document}
\begin{equation}
\int\limits_0^\infty \drm t \, f(t)
\end{equation}
\begin{equation}
\int\limits_0^\infty \Drm{3} r \, g(\bm{r})
\end{equation}
\end{document}
The macros for the differentials are taken from an earlier post. Apart from my own question, why is there a \mathop{}
in the definition of the differentials? But second, how can I achieve a macro that puts both of them together? Like it is with \sqrt
, where you can do \sqrt{x}
or \sqrt[3]{x}
. I like to do \drm
or \drm[3]
.
\Drm{3}
instead of\drm^{3}
? I see none. – egreg Dec 13 '13 at 13:27