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.)

  • Sure, they can be made aware of their input. Can you explain again what they would do with this awareness? May 16 '11 at 9:24
  • @Matthew: Whoops! That wasn't very clear, was it? Is the edited version any better? May 16 '11 at 9:41

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.

  • Um, so I just tried to hack \mathrel to adjust penalties and it caused strange errors. After a long time I figured out it was because \overset went bonkers, and I guess it's because \binrel@ uses \mathrel... Is there a way I can change \mathrel but not affect \binrel@?
    – user21820
    Oct 8 '20 at 20:18
  • @user21820 Please, make a new question specifying the details.
    – egreg
    Oct 8 '20 at 20:51
  • Okay I wrote a new question. Thanks!
    – user21820
    Oct 9 '20 at 6:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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