What does square brackets after function calls mean?

I’ve just finished reading Typst as a Language, by Justin Pombrio.

Under § Content he writes

Typst has a lot of builtin functions from content to content. For example, underscores are a shorthand for a call to the function emph, which (by default) italicizes the content it’s given:

[example]

So emph is a function from content to content. Notice that its argument is passed in square brackets [...] to mark the argument as markup.

From what I understand, he means that when you pass an argument inside square brackets it means that the text should be interpreted as content and not string? I.e. square brackets works similar to the dollar signs using to go into math mode, but the markup-square-brackets need to be used for giving an argument to a function?

But Justin later say under § Functions (not allowed to add > 2 links in a post) that

If you put brackets [...] after the arguments passed to the function, the content in the brackets is passed as the function’s last positional argument.

First off, I’m a bit confused about the wording here. If you put the brackets “after the arguments passed to the function” (implicit that you have given all arguments you want to give to the function), why does the function take yet another argument if it already have received all its arguments?

I’m assuming here that he simply meant “you can give an argument as content in [...], and the content will be passed as the function’s last positional argument.”

But if that’s true, doesn’t that contradict the first thing I quoted? I’m a but confused here. It is more probable that I’ve misunderstood something, or the semantics are clear and you just have to know how many args you’ve given in square brackets, and how many not, and keep a count.

Thank you!

I don’t think that’s implicit. You have given some arguments to the function call.

The description you are quoting is technically wrong on one point I think. The markup brackets don’t fill the last positional argument, just the next positional parameter that didn’t get an argument yet. You can use multiple square brackets to pass multiple such arguments.

Like this, here are two equivalent results, the first of which are using the trailing markup block argument feature:

#table(columns: 2)[a][b]
// Equivalent to:
#table(columns: 2, [a], [b])

2 Likes