1

For convenience, I'll often create custom commands for variables I'm using often in a document, for example

\newcommand{\cartPos}{\ensuremath{x}}

This works fine, and I can now do all the usual things like $\dot{\cartPos}$. But if I have something with an underscore, such as

\newcommand{\vectorPos}{\ensuremath{r_x}}

if I now do \dot{\vectorPos}, the dot is applied to the entire object, instead of being aligned above the r only, and on in between the variable and the underscore. Is there a way to deal with this elegantly?

Basically, I would like to get enter image description here instead of enter image description here

1 Answers1

0

If you're defining macros for your vectors, you can redefine \dot to condition on whether you're placing it on a vector macro, or something else.

enter image description here

\documentclass{article}

\NewCommandCopy{\olddot}{\dot} \RenewDocumentCommand{\dot}{ m }{% \ifx\vectorPos#1 \olddot{r}_x \else \olddot{#1} \fi }

\newcommand{\cartPos}{x} \newcommand{\vectorPos}{r_x}

\begin{document}

$\cartPos ~ \vectorPos$

$\dot{\cartPos} ~ \dot{\vectorPos}$

$\dot{r_x} ~ \dot{r}_x ~ \dot{\vectorPos}$

\end{document}

The above option works, but doesn't translate to any general setup easily.

Werner
  • 603,163