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.

I define a macro as follows:

\newcommand{\abs}[1]{{#1}^{\sharp}}

But I realize that $a \abs{\sqcup} b$ is not exactly same as $a \sqcup^\sharp b$: The first one does not leave enough space between the operator and the operands.

Does anyone know how to amend the macro to make it a real binary operator in terms of spacing?

share|improve this question
add comment

2 Answers

up vote 10 down vote accepted

If you define

\newcommand\abs[1]{#1^\sharp}

the spacing will be inherited by the nature of #1; so

\abs{\sqcup}

will be spaced as a binary operator and

\abs{=}

will be spaced as a binary relation.

With you definition you get {\sqcup}^{\sharp} that's treated as an ordinary symbol.

Some detail

When one tries the input $a+^{\sharp}b^2\showlists$, the .log file will report

### math mode entered at line <line number>
\mathord
.\fam1 a
\mathbin
.\fam0 +
^\fam1 ]
\mathord
.\fam1 b
^\fam0 2

The \mathord and \mathbin lines tell what type of math atom TeX is analyzing. Every atom has three fields: the nucleus (represented by .), the superscript (represented by ^) and the subscript (represented by _).

Since + is defined to be a \mathbin atom, such type is reported. This atom has as nucleus the character + taken from family 0, and a superscript taken from family 1 (cmsy10 font in the default setting, where the slot usually occupied by ] has the "sharp" symbol).

If instead we say $a{+}^{\sharp}b\showlists$, the response is

### math mode entered at line <line number>
\mathord
.\fam1 a
\mathord
.\mathbin
..\fam0 +
^\fam1 ]
\mathord
.\fam1 b

The braces around a subformula tell TeX to treat the whole subformula as a \mathord atom; this atom has a nucleus formed by a \mathbin atom (at an inner level, represented by the two periods ..), but this would have consequences only for the typesetting of the subformula, not with respect to the "outer" level. The braced \mathord atom has a superscript atom as before.

This is only the first step in typesetting a formula. When TeX has determined all the atoms it has to typeset, it applies its rules about spacing; for example it inserts a medium space between \mathord and \mathbin atoms (I'll skip over some subtlety), but it never inserts spaces between two \mathord atoms (unless, of course, such a space has been explicitly specified by the user).

Note that it's the same as with \sqcup instead of +, since also this symbol is declared as a \mathbin atom.

share|improve this answer
add comment

You can force it to be a bin atom using \mathbin:

 \newcommand{\abs}[1]{\mathbin{{#1}^{\sharp}}}
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.