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.
Best Answer
Testing for
_
is fragile and likely to fail if the subscript is hidden in a macro or made with\sb
rather than_
or perhaps if it follows^
so the base isn't "everything before_
" .I don't think it is needed as the accent will naturally apply to the first token or brace group.