What's the reason there is a mandatory trailing comma in table syntax?

The following example, with minor changes, is from https://typst.app/docs/guides/table-guide.

#rotate(
  -90deg,
  reflow: true,

  table(
    columns: (1fr,) + 5 * (auto,),
    inset: (x: 0.6em),
    stroke: (_, y) => (
      x: 1pt,
      top: if y <= 1 { 1pt } else { 0pt },
      bottom: 1pt
    ),
    align: (left, right, right, right, right, left),

    table.header(
      [Student Name],
      [Assignment 1], [Assignment 2],
      [Mid-term], [Final Exam],
      [Total Grade]
    ),
    [Jane Smith], [78%], [82%], [75%], [80%], [B],
    [Alex Johnson], [90%], [95%], [94%], [96%], [A+],
    [John Doe], [85%], [90%], [88%], [92%], [A],
    [Maria Garcia], [88%], [84%], [89%], [85%], [B+],
    [Zhang Wei], [93%], [89%], [90%], [91%], [A-],
    [Marina Musterfrau], [96%], [91%], [74%], [69%], [B-]
  )
)

What is the reason that if we remove a comma after 1fr or after auto, there is an error? How to avoid it?

columns: (1fr,) + 5 * (auto,),  // ok
columns: (1fr) + 5 * (auto),    // error

This is because parentheses have two functions in Typst.

One is to change the order of operations, for example, the calculation order of (a + b) * c and a + b * c is altered by the parentheses.

The other function is to represent a list, for example, (a, b, c).

The problem is, when you want to input (a), Typst interprets it as changing the order of operations rather than a list. Therefore, (1fr) and 1fr are exactly the same, and (auto) and auto are also exactly the same.

Obviously, 5 * auto is not valid, so it causes an error. In contrast, the purpose of the comma in (1fr, ) is to indicate to Typst that this is a list.

4 Likes