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

By "maths adornments" I mean things like \widehat (from the ams) and their ilk. Perhaps the following best illustrates what I mean:

widehat spacing

Code to reproduce:


A \widehat{\otimes} B \\
A \otimes B \\
A \mathbin{\widehat{\otimes}} B

Would it be possible to make \widehat (and others) "aware" of the type of their input? By "type" I mean whether the argument is a relation, operator, alphanumeric character, or ... are there any more? What it would do is to set itself to be the corresponding type. Thus, in my example above, \widehat{\otimes} would result in \mathbin{\widehat{\otimes}} whilst \widehat{A} would result in \mathalpha{\widehat{A}}.

I realise that there's a potential issue in that the input might be many characters, but for a single character it should be reasonably safe (and one could supply an optional argument to the augmented \widehat to override its choice if one disagreed).

(I just noticed this due to a fairly obvious spacing jump in a beamer presentation where I want to add a hat to a character on a slide. In the end, my transition command looked like:


if one isn't bothered about spacing, one can write \only<3->{\widehat}\otimes.)

share|improve this question
Sure, they can be made aware of their input. Can you explain again what they would do with this awareness? – Matthew Leingang May 16 '11 at 9:24
@Matthew: Whoops! That wasn't very clear, was it? Is the edited version any better? – Loop Space May 16 '11 at 9:41
up vote 4 down vote accepted

One can exploit the macros used by ambsy:


$a\otimes b_{a\otimes b}$

$a\iwidehat\otimes b_{a\iwidehat\otimes b}$


The package bm uses a similar approach in order to distinguish more types; this macro recognizes only relations and operations, the rest is treated as an ordinary symbol.


Here's the definition of \math@atom:


The first macro \binrel@ does a measure and sets the meaning of \binrel@@; since this is used in a group, the original meaning of \binrel@@ is restored at the end of the group.


    \medmuskip\m@ne mu\thickmuskip\@ne mu
    \ifdim\wdz@<\z@ \mathbin
    \else\ifdim\wdz@>\z@ \mathrel
    \else \relax\fi\fi}%

Here's what \binrel@ does. First of all it opens a group and sets box 0 with 0 \thinmuskip, negative \medmuskip and positive \thickmuskip. In the box it sets box 2 to the simple argument (\m@th is used to avoid the insertion of the \mathsurround kern). Then it backs up by the width of box 2 and sets the argument preceded and followed by (empty) ordinary atoms.

Case 1: #1 is an ordinary symbol or an operator.
The width of box 0 will be zero.

Case 2: #1 is an operation symbol.
\medmuskip glue will be inserted between {} and #1, and between #1 and {}, so the width of box 0 will be negative.

Case 3: #1 is a relation symbol.
\thickmuskip glue will be inserted between {} and #1, and between #1 and {}, so the width of box 0 will be positive.

The final trick is to do


that will do \let\binrel@@\relax in case 1, \let\binrel@@\mathbin in case 2, \let\binrel@@\mathrel in case 3.

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.