How change class of a math symbol?

\rightarrow has math symbol class 3, that is, it is a math relation.

How can I define a macro, let's call it \rightinf, to get the same right arrow character, but as an ordinary math symbol (like \infty, say) rather than as a math relation?

Reason for the question: I want to use \rightinf to designate intervals in an ordered set that are not bounded above, as in (0, \rightinf), instead of (0, \infty).

\newcommand{\rightinf}{\mathord{\rightarrow}}


or, more concisely,

\newcommand{\rightinf}{{\to}}


(\to is an alias for \rightarrow.)

Creating a macro called \rightinf in this manner may be unnecessary, though, at least for the use case you laid out: $(0,\to)$ and $(0,{\to})$ produce the exact same output.

Here's a full MWE. It illutrates my point about $(0,\to)$ and $(0,{\to})$ producing the exact same output.

\documentclass{article}
\newcommand{\rightinf}{{\to}}
\begin{document}
$(0,\to)$

$(0,\rightinf)$
\end{document}

• But since \to is an alias for \rightarrow and \rightarrow is a math relation (class 3), doesn't the concise definition \newcommand{\rightinf}{{\to}} keep \rightinf as a math relation? Or does the extra grouping around \to in that definition convert it into an ordinary math symbol (class 0)? – murray Aug 4 '18 at 17:07
• @murray: Indeed, encasing \to (or any other math-mode object, really) in curly braces changes its math status to math-ord. – Mico Aug 4 '18 at 17:53
• @Mico Could you add an image to understand your answer? Thanks. – Sebastiano Aug 4 '18 at 20:05
• @Sebastiano - Done! :-) – Mico Aug 4 '18 at 20:20
• Since \to is of class 3 (math rel), why does the spacing stay the same for the \mathord version (invoked in the form \mathord{\rightarrow}) as for the original math rel form? – murray Aug 4 '18 at 22:24

Since \rightarrow is a \mathchardef token, you can define

\mathchardef\rightinf=\numexpr\rightarrow-"3000\relax


Example:

\documentclass{article}

\mathchardef\rightinf=\numexpr\rightarrow-"3000\relax

\begin{document}

$a\rightarrow b$

$a\rightinf b$

\end{document}


On the other hand,

\newcommand{\rightinf}{\mathord\rightarrow}
`

is simpler.