[tex-k] bug in syntax of <numeric primary> in The METAFONTbook

胡亚捷 (Hu Yajie) 2500418497 at qq.com
Mon Jul 13 17:50:54 CEST 2020


The syntax for primaries solves the ambiguity of `-.5[a,b]' by restricting
what can occur in the `t' part of the `t[a,b]' notation: single-token things,
"literal" fractions like 2/3, parenthesized and grouped expressions can occur,
while things with an operator at the left, like -.5, sqrt3, 2/3x etc., cannot.
Therefore, the interpretation `(-.5)[a,b]' is ungrammatical, and it must be
parsed as `-(.5[a,b])'. However, the real reason MF chooses the latter is:

1.  Parsing is done from left to right.
2.  METAFONT makes each primary as long as possible. In other words, a
    <primary> is always extended if it is followed by `[<exp>,<exp>]'.

Thus, you cannot put `-.5' before something like `[a,b]' because `-.5' ends
with an unfinished primary and `[a,b]' happens to finish it, not because
`-.5' begins with an operator. Now, what's the problem if the the two
interpretations explain the same phenomena? The problem is that some `t' parts
begin with an operator and end with a finished primary, such as `-.5[a,b]'
itself occurring before another set of brackets! Try it, and you'll find that

    *show -.5[a,b][0,100];
    >> -50b-50a

is perfectly grammatical, even though `-.5[a,b]' does not meet the syntax of
<numeric atom>. Thus the syntax rules should be rebalanced to something like

    <numeric atom> ::= <numeric variable> | <numeric argument>
        | <numeric token primary>
        | <internal quantity>
        | normaldeviate
        | ( <numeric expression> )
        | begingroup <statement list> <numeric expression> endgroup
        | length <numeric primary> | length <pair primary>
        | length <path primary> | length <string primary>
        | ASCII <string primary> | oct <string primary> | hex <string primary>
        | <pair part> <pair primary> | <transform part> <transform primary>
        | angle <pair primary>
        | turningnumber <path primary> | totalweight <picture primary>
        | <numeric operator> <numeric primary>
        | directiontime <pair expression> of <path primary>
    <numeric primary> ::= <numeric atom> [ <numeric expr> , <numeric expr> ]
        | <numeric atom not followed by `[ <numeric expr> , <numeric expr> ]'>

Not sure if I got the new syntax right, but it's definitely cleaner if it is.
(You might also want to change the explanation of `sqrt 100(100)' on page 64.)

---------------------------now for some suggestions---------------------------

Page C127, line 19
Concatenation of strings isn't introduced yet for first-time readers.

Page C171, line 4
The parentheses in `round(n)' are superfluous (cf. `round a' and `round x' on
page C66, `round u' and `round 3u' on page 200, etc.)

Page C191, line 2
The `currentpicture' feature isn't introduced yet for first-time readers.



More information about the tex-k mailing list.