\underset {under} {over}

Uncaught ParseError: KaTeX parse error: Expected '}', got '\underset' at position 23: style{\underset̲ {under} {over
Request for help
We've got this formula:
F-1,6-BP \underset {F-1,6-BP} {\longrightarrow} F6P + P_{i}
which renders in MathJax successfully like this:

How can I modify this formula so that it renders successfully in KaTeX?
Hello @lolmaus! Thanks for the report.
It looks like \underset is defined as \underset#1#2{\binrel@ {#2}\binrel@@ {\mathop {\kern \z@ #2}\limits _{#1}}} (and \overset is the same thing but with ^ instead of _). I'm not sure what \binrel@ does, but other than that it's pretty simple, you just make a \mathop and then use \limits to put the first argument under the second. We don't yet support \mathop (see #482), but once we have that you could just do \mathop{\longrightarrow}\limits_{F-1,6-BP}
Then once we have actual macro support (#250), we can actually make \overset and \underset work. I'm gonna close this issue and you can watch those other issues. #482 shouldn't be too hard to implement if someone wants to take it, but #250 is going to be a long ways down the road.
@xymostech So there's no way to render this with current version of KaTeX? 
Correct :(
@xymostech Well, maybe some dirty hack to make it look similar? I'm absolutely not familiar with TeX, can't come up with a workaround on my own.
Hello, I did a similiar hack not too long ago, try
\;{\tiny\begin{matrix}^{\scriptsize overset}\\ \normalsize normal \\ ^{\scriptsize underset}\end{matrix} }\;.
This is what it looks like with your formula:

F - 1{,}6 - BP \;{\tiny\begin{matrix}\\ \normalsize \longrightarrow \\ ^{\scriptsize F - 1{,}6 - BP}\end{matrix}}\; F6P + P_i
Thank you so much @sthoch! :bow:
@sthoch :) Nice hack!
Now that #482 is implemented, is it worth implementing this as a manual function? Or worth waiting for macro support? Maybe a slight extension to #493 will allow us to add macros in the KaTeX source too?
@edemaine wrote:
Now that #482 is implemented, is it worth implementing this as a manual function? Or worth waiting for macro support? Maybe a slight extension to #493 will allow us to add macros in the KaTeX source too?
I'd go for the latter. It would definitely be desirable to express some TeX functions in terms of more elementary ones. I'd do that in the MacroExpander constructor, merging the user-supplied macros with a set of built-in presets, with the user-defined ones taking precedence. I'd put the built-in macros into a separate module, consisting of a single dict, for easier maintainance. I'll try to come up with a pull request to this effect.
As a proof of concept that our elementary functions are already sufficient to handle this, I tried the expanded version:
F-1{,}6-BP\mathop\longrightarrow\limits_{F-1{,}6-BP}F6P+P_i
Looks good to me.
@xymostech wrote:
I'm not sure what
\binrel@does …
In amsmath.dtx I found the following explanation:
\oversetand\undersetput symbols above, respectively below, a symbol that is not a\mathopand therefore does not naturally accept limits.\binrel@@uses information collected by\binrel@to make the resulting construction be of type mathrel or mathbin if the base symbol is either of those types.
Just in case it becomes relevant: I've had a look at \binrel@. It essentially typesets $#1$ into a box, takes the width of that as a negative skip, and types ${}#1{}$ after that skip into another box, so the width of that box is essentially the spacing between #1 and the empty groups. By temporarily setting the various spaces to −1,0,+1, the sign of the width of that box can be used to distinguish these cases, and \binrel@@ wil get set accordingly. Here is the code snippet to go with that, taken from amsmath.sty:
\def\overset#1#2{\binrel@{#2}%
\binrel@@{\mathop{\kern\z@#2}\limits^{#1}}}
\def\underset#1#2{\binrel@{#2}%
\binrel@@{\mathop{\kern\z@#2}\limits_{#1}}}
\def\binrel@#1{\begingroup
\setboxz@h{\thinmuskip0mu
\medmuskip\m@ne mu\thickmuskip\@ne mu
\setbox\tw@\hbox{$#1\m@th$}\kern-\wd\tw@
${}#1{}\m@th$}%
\edef\@tempa{\endgroup\let\noexpand\binrel@@
\ifdim\wdz@<\z@ \mathbin
\else\ifdim\wdz@>\z@ \mathrel
\else \relax\fi\fi}%
\@tempa
}
\let\binrel@@\relax
There is a lot of machinery in the \binrel@ implementation which we likely won't support any time soon: saved boxes, width measurements, case distinctions, scoped assignments, \edef with \noexpand and so on. So I'd suggest we don't try to do this part via macros, but instead define \binrel@ and \binrel@@ as built-in functions.
The @ in these names might cause some trouble. Currently KaTeX is working in \makeatother mode exclusively, with no \makeatletter supported. We could rename those symbols, but that would pollute the user's macro namespace in perhaps unexpected ways, and cause considerable extra work, too. Should we switch to \makeatletter mode when tokenizing macro bodies? As macro expansion uses it's own lexer, that might be feasible. And when we later add support for \def and friends, that would use existing tokens from the main lexer, not a source string, so there would be no conflict.
I'll reopen as solving this should be possible in the near future now. Perhaps without the \binrel@ support at first, but that's better than nothing, right?
Most helpful comment
Hello, I did a similiar hack not too long ago, try
\;{\tiny\begin{matrix}^{\scriptsize overset}\\ \normalsize normal \\ ^{\scriptsize underset}\end{matrix} }\;.This is what it looks like with your formula:

F - 1{,}6 - BP \;{\tiny\begin{matrix}\\ \normalsize \longrightarrow \\ ^{\scriptsize F - 1{,}6 - BP}\end{matrix}}\; F6P + P_i