Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 9 down vote accepted
\usepackage{amsmath}
\DeclareMathOperator{\depth}{depth}

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:

\DeclareMathOperator{\Depth}{depth}

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
add comment

Your Answer

 
discard

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.