# How to make a \newcommand that acts like \dim?

The \dim command is good at deciding how to space things following it: for example, both $\dim M$ and $\dim_A M$ look right (the subscript immediately follows the dim, whereas the non-subscripted version has a space before the M).

I'd like to make a similarly-acting command \depth. I've been using:

\newcommand{\depth}{\textnormal{depth }}

but this forces a space, so $\depth_A M$ doesn't look good. I tried using \xspace as per this question:

\newcommand{\depth}{\textnormal{depth}\xspace}

but it doesn't seem to do anything (there is no difference between using it and not, in the above command).

How can I get the right behavior?

-
–  Stefan Kottwitz Sep 20 '11 at 21:42