# How to make a math mode non-Ord macro?

I want to make a new macro that'll act like its own character. Specifically, I want \macro to expand to a\kern0.5em b, but still act as a Rel character (i.e. 1\macro1 would have a small space around the a b similar to how the = in 1=1 has a space).

I've tried \def\macro{\mathrel{a\kern0.5em b}}, but a problem arises when it's used as an exponent: x^\macro expands to x^\mathrel{ ... }, which TeX doesn't like and throws an error. I know I could just enclose it like x^{\macro}, but I'm looking for a way where you wouldn't have to put braces around it each time. I also know that whether it's a Rel atom or not doesn't matter when used as a lone exponent, but I want it to work in all situations, exponent or not.

Is there any way to make a macro (with a {group} like {a\kern0.5em b}) that's not treated like an Ord character and that works when used as an exponent or subscript?

• I'm not sure I fully follow, but best practice is to employ x^{\test} rather than x^\test. – Steven B. Segletes Apr 4 '18 at 2:50
• I know it would work in its own group like you said, but is there any way to get it to work with or without the braces? – ChristianFigueroa Apr 4 '18 at 2:59
• \def\macro{\bgroup\mathrel{a\kern0.5em b}\egroup} seems to work. – corporal Apr 4 '18 at 3:13
• @corporal - with your definition, \macro is of type math-ord, not math-rel. – Mico Apr 4 '18 at 3:17
• If x^t works, good. But the correct syntax is x^{t}, even if t is a single token like in your example. The same happens with \notin, for instance. – egreg Apr 4 '18 at 6:51

No, that is not possible. As soon as you enclose something in a brace group it becomes an Ord atom. The TeXbook Chapter 26 “Summary of Math Mode” is very specific about this:

{<math mode material>}. A character token of category 1, or a control sequence like \bgroup that has been \let equal to such a character token, causes TeX to start a new level of grouping and also to begin work on a new math list. When such a group ends—with ‘}’—TeX uses the resulting math list as the nucleus of a new Ord atom that is appended to the current list. If the resulting math list is a single Acc atom, however (i.e., an accented quantity), that atom itself is appended.

For the syntax x^\macro to work the contents of \macro have to be a math field.

<superscript><math field>. A <superscript> command is an explicit or implicit character token of category 7. If the current list does not end with an atom, a new Ord atom with all fields empty is appended; thus the current list will end with an atom, in all cases. The superscript field of this atom should be empty; it is made nonempty by changing it to the result of the specified <math field>.

A math field however, is either a single symbol or a brace group

A <math field> is used to specify the nucleus, superscript, or subscript of an atom. When a <math field> is a <math symbol>, the f and a numbers of that symbol go into the atomic field. Otherwise the <math field> begins with a ‘{’, which causes TeX to enter a new level of grouping and to begin a new math list; the ensuing <math mode material> is terminated by a ‘}’, at which point the group ends and the resulting math list goes into the atomic field. If the math list turns out to be simply a single Ord atom without subscripts or superscripts, or an Acc whose nucleus is an Ord, the enclosing braces are effectively removed.

You could however simply exploit the fact, that the spacing around a Rel atom in scriptstyle is zero and use the following definition

\def\macro{{{}\mathrel{a\kern0.5em b}{}}}

$x \macro y$

$z^{x \macro y}$

$z^\macro$ % Brrr...

\bye


• This is I suspect the best answer there is (unless you make ^ math active and read its argument as a macro argument) but you should probably note that \macro doesn't act like a true \mathrel as it always adds space compare $=$ and $\macro$ (which is like ${}={}$) – David Carlisle Apr 4 '18 at 7:14