It seems that I cannot modify \mathrel without breaking \overset, and I do not understand why. The following fails to compile even when the redefinition of \mathrel does exactly the same as the original version.
\documentclass{article}
\usepackage{amsmath}
\usepackage[T1]{fontenc}
\begin{document}
\let\oldmathrel\mathrel
\def\mathrel#1{\oldmathrel{#1}}
$A \overset{X}{\to} B$
\end{document}
The error message is:
Runaway argument?
\relax\@nil \binrel@@ {\mathop {\kern \z@ \to }\limits ^{X}} B$ \end \ETC.
! File ended while scanning use of \@tempb.
<inserted text>
\par
What is going on?

\mathrelin the first place. – daleif Oct 09 '20 at 06:10\mathrel. Anyway it is not relevant to my question; I'm asking why modifying it breaks\overset, and how to modify it without breaking\overset. – user21820 Oct 09 '20 at 06:17\mathreldo wrong? Just because you can change something does not mean you should – daleif Oct 09 '20 at 06:33\xrightarrow{X}– daleif Oct 09 '20 at 06:34\oversetin many other ways; this was just a minimal example. My question is about why the error arises and how to avoid it, not about your opinion on whether I should or should not do something. – user21820 Oct 09 '20 at 06:39\mathrelcan be properly redefined. For example, if we want every relation-symbol to be blue, we can do so for inbuilt symbols like "=", but what if we don't want to repeat code for every single relation-symbol that is created in the document itself? If we can modify\mathrel, we can ensure that every newly created relation-symbol is blue. Another possible use is to allow line-breaking before each relation-symbol (not just after). Just like we can easily style each class in CSS. – user21820 Oct 09 '20 at 07:13\DeclareMathSymbolyou don't need to redefine tex primitives to change their definition. – David Carlisle Oct 09 '20 at 07:14\mathrelwill have no effect on\leq,\sim, and any of the basic relation symbol commands (except\cong,\notinand perhaps a few others) – egreg Oct 09 '20 at 07:30\mathrel" ìs not likely to get you very far -- in no small part because "the designer of TeX" is known not to frequent TeX.SE. It might be more productive if you explained what it is that you're trying to achieve. E.g., do you want to change the spacing around math atoms of typemath-rel? If so, it suffices to change the values of certain length parameters. Or, if you want to change the status of a math-atom from math-rel to, say, math-bin, you can do so without modifying\mathrelitself. – Mico Oct 09 '20 at 07:31\mathrel. As I said, the point is to keep the styling separate from the main document. – user21820 Oct 09 '20 at 07:34\mathrel, as doing so would allow much more than those two example usages. – user21820 Oct 09 '20 at 07:36