I'm not good at TeX programming. I've looked for the method that detects the subscript or superscript of the argument in macro. Existing relevant answers using the xifthen package (Detecting subscript in command argument) are somewhat verbose for me to understand. Specifically, I want to make a macro such that if the argument has a subscript, \dot{} is applied only to the base character. It would have the form
\newcommand{\rdot}[1]{'code body'}
For example, \rdot{a_{bcd}} will give
instead of
that \dot{a_{bcd}} gives. \rdot should apply to superscripts in the same way.
Edit: I noticed that some macros in the answers yield a different result for boldface letters. For example, consider \rdot{\bf{v}_{abc}}. I didn't know it would make such a difference.




\dot{a}_{bcd}as result? Why not just use it like this? – dexteritas Oct 02 '21 at 13:19\newcommand\rdot[1]{\dot #1}? – David Carlisle Oct 02 '21 at 13:20\dotfor macro characters. For example, I'd like to define\text = v_{abc}and apply\dotto\text. – Hermis14 Oct 02 '21 at 18:29\text, as this command already exists and is pretty important! – Gaussler Oct 03 '21 at 13:21