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.

Here is a little example that illustrates this strange behaviour:

\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator\foo{\mathbf{l}}
\begin{document}
baseline$\mathbf{l}$baseline$\mathop{\mathbf{l}}$baseline$\mathop{l}$baseline$\foo$baseline
\end{document}

baselines

Note that the explict call to \mathop shifts the baseline of the l. But if you use \DeclareMathOperator this doesn't happen. Is this a bug or a feature?

I personally think that the shifted baseline looks really weird if you're discussing an operator in text, so I'd like to shift it up again. Do I have an alternative to endless use of \DeclareMathOperator?

share|improve this question
    
Is \DeclareMathOperator not about functions like sin, cos, etc., and \mathop about operators like +, -, etc.? –  Martin Scharrer Jan 16 '12 at 15:23
    
@MartinScharrer if that's the case, the terminology is confusing! there's \mathbin and \mathrel, I thought they were the ones for the infix notation symbols… –  Seamus Jan 16 '12 at 15:27
    
Ok, yes \mathbin is for binary operators! \mathrel is for relations, i.e. = etc. I don't have The TeXBook handy right now, otherwise I would look it up. –  Martin Scharrer Jan 16 '12 at 15:29
1  
\mathop is also about \sum and friends, which is why it centers single glyphs vertically on the math axis. –  barbara beeton Jan 16 '12 at 15:58
add comment

3 Answers

up vote 14 down vote accepted

it's a feature. here's an excerpt from amsopn.dtx:

In the interior of the \mathop we need a null object (we choose a zero kern for minimum waste of main mem) in order to guard against the case where #3 is a single letter; TeX will seize it and center it on the math axis if there is nothing else inside the \mathop atom.

and here's the definition of \qopname which underlies \DeclareMathOperator:

\DeclareRobustCommand{\qopname}[3]{%
\mathop{#1\kern\z@\operator@font#3}%
\csname n#2limits@\endcsname}
share|improve this answer
    
\operatorname? –  egreg Jan 16 '12 at 15:33
    
@egreg -- \operatorname is also defined in amsopn, but it's defined in terms of \qopname. i'm pretty sure that michael preferred \DeclareMathOperator as being more descriptive; he also limited its use to the preamble, and i know that he felt strongly that all such commands should be defined only in the preamble. his documentation (texdoc amsopn) is pretty clear, even to a non-guru. –  barbara beeton Jan 16 '12 at 15:46
    
I was just pointing to \operatorname that's the "user level" version of \qopname (which requires three quite mysterious arguments) and is available also in document`. –  egreg Jan 16 '12 at 15:50
    
Why is it considered a feature to have single letter operator names centre on the math axis? –  Seamus Jan 20 '12 at 12:18
1  
@Seamus -- it's not single letter but single glyph operators, in particular \sum, \prod, \int, etc., that are responsible for this. in the cm extension font, most, if not all, glyphs are positioned entirely below the baseline, and the \mathop mechanism used to position them correctly. i don't know for sure, but it's likely that knuth didn't need single-letter operator names, and didn't think it worth the "cost" of checking for them. (remember that when tex was written, computers weren't nearly as fast as they are now, and tremendous effort went into making tex efficient.) –  barbara beeton Jan 20 '12 at 14:57
add comment

The "shifting" obeys TeX rules: when the argument of \mathop consists of one character only it is centered with respect to the math axis (where the fraction line sits); this is laid down in the TeXbook, Appendix G, Rule 13.

For "one shot" operators you can use \operatorname, that cures the problem (and chooses automatically \mathrm.

$\operatorname{l}$ is different from $\mathop{\mathrm{l}}$

The command is available as soon as amsopn is loaded (the same package that supplies \DeclareMathOperator); it is loaded automatically by amsmath.

The *-variant has a similar effect to \DeclareMathOperator*, so defines a math operator with limits.

If the input \operatorname{\mathnormal{l}} for getting a "normal italic l" is too much, then

\mathop{\kern0pt l}

is shorter.

share|improve this answer
    
If you use \newcommand\foo{\kern0pt l} then \foo still has the baseline shifted. I assume this is some expansion magic, but how might one fix that? –  Seamus Jan 28 at 11:16
    
@Seamus Sorry, but I don't get it: \mathop{\foo} will not shift l from the baseline, while \foo simply prints l. –  egreg Jan 28 at 11:51
    
\documentclass{article} \newcommand\foo{\kern0pt \mathop{l}} \begin{document} $l\foo l$ \end{document} Note baseline is shifted. That is, the solution you suggest doesn't work when mathop is used in defining a new command with only one glyph. –  Seamus Jan 29 at 12:08
    
@Seamus Exactly what's expected: if the list given as argument to \mathop consists of a single character, the character is shifted, as I wrote in the first paragraph of my answer. –  egreg Jan 29 at 12:13
1  
@Seamus Sorry, but I don't get it: \kern0pt must go inside the argument to \mathop. –  egreg Jan 31 at 12:09
show 2 more comments

Fixes for \mathop are inserting empty space within the argument, such as by \hspace, \kern, or \mbox.

This has the correct baseline:

\mathop{\mathbf{l}\mbox{}}

Ant this too:

\mathop{\mathbf{l}\hspace{0pt}}

amsmath does it similar, here you can see it in within \operatorname, which is called by \DeclareMathOperator via \@declmathop:

\DeclareRobustCommand{\qopname}[3]{%
  \mathop{#1\kern\z@\operator@font#3}%
  \csname n#2limits@\endcsname}
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.