#\sqrt\frac12 vs \sqrt\sqrt1 and \frac\frac123
1 messages · Page 1 of 1 (latest)
fadaaszhi
$\sqrt\sqrt1$
fad
$\sqrt\sqrt1$
```Compilation error:```! Missing { inserted.
<to be read again>
\let
l.49 $\sqrt\sqrt
1$
A left brace was mandatory here, so I've put one in.
You might want to delete and/or insert some corrections
so that I will find a matching right brace soon.
(If you're confused by all this, try typing `I}' now.)```
$\frac\frac123$
fad
$\frac\frac123$
```Compilation error:```! Missing } inserted.
<inserted text>
}
l.49 $\frac\frac1
23$
I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.```
(i know all of these should in practice use grouping like \frac{\frac{1}{2}}{3} in order to work correctly but i'm curious about the apparent discrepancy between the above cases)
The fact that this works is merely a coincidence with the particular implementation of \sqrt
thanks for responding, do you have a reference to undefined behaviours in (La)TeX?
There's no reference for latex like there is for a standardised language
I was simply appropriating the concept
do you know what's going on behind the scenes that makes \sqrt\frac12 work but not \frac\frac123?
I can give an explanation, but it will not make sense if you haven't read the TeXbook
i've skimmed through the TeXbook before
Sure. First look at the expansion of \sqrt to see that it is essentially \radical "xxxxxx
,,cmeans sqrt,sqrtsign
What's the syntax for \radical? Flip to the TeXbook, Chapter 26, to find
\radical〈27-bit number〉〈math field〉
What's a math field? We find
〈math field〉 → 〈filler〉〈math symbol〉 | 〈filler〉{〈math mode material〉}
OK, since \frac12 certainly isn't a math symbol, it must be { math mode material }. Let's verify this
,,\edef\temp{\frac12} \cmean temp
i'm following so far
Well the explanation is complete
the tldr is just \frac12 happens to expand to something that \radical can accept
ie a braced group
what happens when TeX sees \frac\frac123? does it become {\begingroup \frac\endgroup \over 1}23?
Yes, because \frac is a macro
\frac would take #1 <- \frac, #2 <- 1
which is obviously nonsense
ah, and then the second \frac ends up getting #1 <- \endgroup, #2 <- \over, giving even more nonsense
${\begingroup {\begingroup \endgroup\endgroup \over \over} 1}23$
fad
${\begingroup {\begingroup \endgroup\endgroup \over \over} 1}23$
```Compilation error:```! Missing } inserted.
<inserted text>
}
l.49 ${\begingroup {\begingroup \endgroup\endgroup
\over \over} 1}23$
I've inserted something that you may have forgotten.
(See the <inserted text> above.)
With luck, this will get me unwedged. But if you
really didn't forget anything, try typing `2' now; then
my insertion and my current dilemma will both disappear.```
same output, same error
and when parsing {\begingroup \endgroup\endgroup it expects } instead of the last \endgroup
did i get it right?
when expanding \frac\frac123, the first \frac gets #1 <- \frac and #2 <- 1.
when expanding \sqrt\frac12, why doesn't \sqrt get #1 <- \frac?
yes
\sqrt expands to \radical which is a tez primitive
It has different parsing rules
In particular, it would expand ahead in search of a math symbol or a <general text> construction
ah, so \sqrt is a macro that takes zero parameters