I have defined a differential command in this way
\let\underdot\d
\renewcommand{\d}{\ifmmode\mathop{}\!\mathrm{d}\else\expandafter\underdot\fi}
so that I don't loose the text accent (I don't know how expandafter works, I put it there just after trial and error). But I have a problem, if I use \d as the first command in a substack, it gives me the text \d. Here is an example code:
\documentclass{scrartcl}
\usepackage{mathtools}
\let\underdot\d
\renewcommand{\d}{\ifmmode\mathop{}\!\mathrm{d}\else\expandafter\underdot\fi}
\begin{document}
\[
\substack{\d x = \sigma \d y}
\]
\end{document}
I don't know why this happens, may be my command is bad defined, or may be there is a bug in \substack (subarray). I can solve it with {}\!\d x = … but I would like to fix it globally.
\underdotwould be the (admittedly complicated) incantation\expandafter\let\expandafter\underdot\csname\encodingdefault\string\d\endcsname– egreg Feb 10 at 13:11\let\underdot\dby the one you provided (if I haven't misunderstood you, this is what you say, isn't it?). – Manuel Feb 10 at 13:22\let\underdot\dmight, under some circumstances, lead to infinite loops, because the expansion of\drefers to\ditself. When you redefine\din terms of\underdotyou could fall into one of those (rare) circumstances. – egreg Feb 10 at 13:51\dis exactly the same as before; the\expandafterin it is for getting rid of\fi; in the complicated\letinstruction it is for making\csnameact before\letis executed. – egreg Feb 10 at 14:58