#\sqrt\frac12 vs \sqrt\sqrt1 and \frac\frac123

1 messages · Page 1 of 1 (latest)

inner veldt
#

why does the first compile but not the second and third?

#
$\sqrt\frac12$
timber pebbleBOT
#

fadaaszhi

inner veldt
#
$\sqrt\sqrt1$
timber pebbleBOT
#

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.)```
inner veldt
#
$\frac\frac123$
timber pebbleBOT
#

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.```
inner veldt
#

(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)

stray island
#

It is simply not supported

#

You are invoking undefined behaviour here

stray island
inner veldt
stray island
#

There's no reference for latex like there is for a standardised language

#

I was simply appropriating the concept

inner veldt
#

do you know what's going on behind the scenes that makes \sqrt\frac12 work but not \frac\frac123?

stray island
#

I can give an explanation, but it will not make sense if you haven't read the TeXbook

inner veldt
#

i've skimmed through the TeXbook before

stray island
#

Sure. First look at the expansion of \sqrt to see that it is essentially \radical "xxxxxx

#

,,cmeans sqrt,sqrtsign

timber pebbleBOT
stray island
#

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

timber pebbleBOT
inner veldt
#

i'm following so far

stray island
#

Well the explanation is complete

#

the tldr is just \frac12 happens to expand to something that \radical can accept

#

ie a braced group

inner veldt
#

what happens when TeX sees \frac\frac123? does it become {\begingroup \frac\endgroup \over 1}23?

stray island
#

Yes, because \frac is a macro

#

\frac would take #1 <- \frac, #2 <- 1

#

which is obviously nonsense

inner veldt
#

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$

timber pebbleBOT
#

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.```
inner veldt
#

same output, same error

#

and when parsing {\begingroup \endgroup\endgroup it expects } instead of the last \endgroup

#

did i get it right?

inner veldt
stray island
#

It has different parsing rules

#

In particular, it would expand ahead in search of a math symbol or a <general text> construction

inner veldt
#

ah, so \sqrt is a macro that takes zero parameters