TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


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?

share|improve this question
up vote 10 down vote accepted

However, although \depth does not appear to be defined, it's used in some box contexts, so maybe it would be better to change the name:


The space you see between "dim" and "M" is inserted because \dim qualifies as a math operator; and the space is inserted automatically also in \dim_M X, for instance, but not in \dim_M(A+B). The same will be with \Depth that produces an operator named "depth".

The \DeclareMathOperator* variant builds an operator that takes limits above and below in displays (like \min).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.