Attributes

Writing the attribute group, the implicit :value and bare booleans, how names and aliases match, how a value is parsed by its type, maps, and defaults set for several constructs at once.

On this page

#Writing the group

A construct's attributes are written in parentheses after its body and detail. Each entry is a name, a colon and a value, and entries are separated by a semicolon or a line break. The two separators can be mixed.

point(x: 1; y: 2; colour: orange)

graph{
    curve(expression: x^2)
}(
    x domain: [-3, 3]
    y domain: [0, 9]
    title: A parabola
)

The name is everything before the first colon, and the value everything after it, trimmed. A semicolon or line break inside ( ), [ ] or { } belongs to the value, so a bracketed value can hold either. Anywhere else, \; is a literal semicolon: table(title: Yield at 300 K\; 1 atm) sets one title, where without the backslash the group would hold a second entry named 1 atm. A line in the group starting with // is a comment.

An entry with no colon is a boolean set to true, and ! before it sets it false (Bare and negated booleans). An attribute written twice takes the later value.

#:value, the implicit attribute

Most constructs mark one attribute as implicit, and its value can be written in the head after a colon. Each pair below compiles to the same thing:

image:photo.jpg(caption: The apparatus)
image(source: photo.jpg; caption: The apparatus)

curve:x^2(colour: blue)
curve(expression: x^2; colour: blue)

!h:teal{…}
!h(colour: teal){…}

A reference page marks the implicit attribute in its attribute table. A construct that marks none has no : form, and writing one is an error that names the alternative:

option:correct{Paris}

[parse]node `option` declares no implicit attribute — write `option(correct: …)` (D37)

The value is a single token. It starts after the colon and ends at the first bracket, space or line end, so a value with spaces in it is written in the group. Inside the token # and . are ordinary characters, which is how !cite:#fs1969() passes a reference and @include:overview.part.chalk a file name. Because the #id comes before the colon, curve#c:x^2() names the curve, and curve:x^2#c() reads x^2#c as the expression. An empty value before a bracket, curve:(), is an error, and so is a {{…}} expression in the token: write it in the group, curve(expression: {{…}}).

#Bare and negated booleans

A boolean attribute written as its bare name is true, and with ! before the name it is false:

graph{
    curve(expression: x^2)
    curve(expression: x^3; !endpoints)
}(
    interactive
    !show-grid
)

interactive is interactive: true, and !endpoints is endpoints: false. The negated form is how an attribute that defaults to true is turned off: show-grid, show-axes, show-ticks and show-background on a graph, endpoints on a curve.

Written out, a boolean is true or false, or yes or no, in any case. A boolean may also be a condition, written without braces — hidden: a > 2 beside slider:a — and decided as the page renders where it reads a parameter (Expressions).

A bare name sets true whatever the attribute's type, so curve(colour) is refused because true is not a colour. And ! at the start of an entry negates; inside a value it opens a micronode. hidden: true !cue.to{false}(at: 1) is hidden until the cue at step 1 sets it to false.

#Attribute names and aliases

A name is matched in any case, and each run of spaces inside it reads as one hyphen: x-domain, x domain and X Domain set the same attribute. A name the construct does not declare is an error — weight: 3 on a point: node `point`: attribute `weight` is not declared.

Many attributes also answer to aliases, which each construct declares for itself: color for colour, from and to for segment's start and end, and exp, f, func and function for curve's expression. A construct's reference page lists its aliases beside each attribute.

Warning
Outside a group a space ends the name, so a reference or an expression writes the hyphen: {{#c.text-size}}, never {{#c.text size}}.

#Values parsed by type

A value is text until the attribute it is written in parses it with the attribute's type. Text the type cannot read is a compile error; nothing is coerced, and nothing falls back to the default: endpoints: 3 on a curve is refused with curve.endpoints: the value: `3` gives a number where bool is wanted.

The types a value is read by are built on a small set of bases: text, numbers, booleans, complex numbers, colours, dates, datasets, expressions, lists, intervals, maps and references among them. Some have one written form everywhere:

  • A colour literal is rgb(255, 0, 0) or hex(FF0000), six digits; hex(fff) is refused. Where an attribute takes a colour it also takes a hue's name (Colours).
  • A date is 2026, 2026-10 or 2026-10-18, and is checked against the calendar.
  • A dataset is its id, #islands.
  • A list is written bare, red, blue, or in parentheses, (red, blue). One item alone is a list of one; (red,) is the spelling where that must be plain. Square brackets are not a list: [red, blue] is one item.
  • An expression is written bare, as the whole value: hidden: a > 2, colour: #tea.cup -> (open: blue; otherwise: grey).

A type may be narrowed for one attribute: a number to whole values or to a range, a list to a length, text to a pattern. A value outside the narrowing is refused with an error that names it: question#q(marks: 0) is refused because `0` is below the minimum of 1. The value types page lists what each type accepts, and a construct's reference page gives each attribute's type and default. An attribute left out takes its default; a required one left out is an error.

#Maps

A map is a table of keys to values, written as an attribute group is but in parentheses: (Labor: red; Liberal: blue; Greens: green). Its keys are all names or all intervals, (..<0: purple; 0..: pink), and every value is read by the type of the attribute the map is used on. A name may be several words, and names are matched ignoring case and spacing, so a map that keys both Labor and labor is refused: map key `labor` repeats `Labor` — keys are matched loosely, so these are one key. Two names that are both plain numbers are one key too, 1 and 1.0, while a code with a leading zero, 0800, keeps its spelling. An interval key that an earlier one already holds whole, (0..5: teal; 1..2: grey), could never be chosen and is refused, as is one that is no interval at all: .. alone is an interval needs at least one end.

A map's last entry may be otherwise, the value for anything no key holds: (Labor: red; Liberal: blue; otherwise: grey). It is not a key, so it sits beside names or intervals alike, and its value is read by the same type as the others. It must come last and appear once, since a key after it could never be chosen. otherwise is matched loosely like any name, so a category spelled otherwise cannot be a key. A map of only (otherwise: grey) is always that value.

A map on its own does nothing. Applied to a value with ->, it gives the value of the first key that holds (Expressions). Each key is read as a value of the value's own type, and that type says whether it holds: a key holds when the value equals it, as = compares in a condition, so the number 33 holds the key 33.0 and a date 2026-10-01 holds the key 2026-10, which stands for the first day of the month; an interval key holds when the value is a number lying in it, as in tests. A key that is not a value of that type is refused: {{7 -> (open: x)}} is map key `open` is not a number as `7` is. A dataset cell or a constant takes the type its own written form has — a date, a number or a boolean — so @let(year: 2026) against a key 2026-01 is refused as a number against a date; write 2026-01 on the left. Only a bare word takes its type from the keys: a boolean if they read as booleans, a number if they read as numbers, a date if they read as dates, and otherwise text, compared ignoring case and spacing. A value no key holds takes the map's otherwise. Without one the application chooses nothing, and the attribute is left as if it were not written: its default applies, and a required one is an error. One interval key is a band and holds nothing outside it: (0..2: teal) holds 0 to 2 only.

Applied to a column, a map gives one value per row, which is how a mark's style follows its data:

@data#votes{
    party   | margin | seat
    Labor   | 3.1    | 12
    Liberal | 1.4    | 30
    Greens  | 6.0    | 4
    Nats    | 2.2    | 21
}

graph{
    scatter(x: #votes.margin; y: #votes.seat; colour: #votes.party -> (Labor: red; Liberal: blue; Greens: green; otherwise: grey))
}

The left of -> may also be a reading the mark publishes for itself, read with #self — a scatter's #self.value, a vertex table's #self.degree — or an expression over either: colour: #self.value -> (..<0: purple; 0..: pink). A column written in the document is decided as the internote compiles; a map on a reading that moves is decided as the page draws it. Styling marks from data covers each style attribute.

A value known while the internote compiles — a constant, a template's attribute, a loop's binding, or a condition over those — is applied there, in braces, and the attribute takes the chosen value as if it had been written in its place. That is how one value is chosen from two: colour: {{k > 2 -> (true: red; false: blue)}}. A map given as a template's attribute, declared !map(value: paint), is applied like a written one, its otherwise included, so a template can let its caller choose the colours: colour: #self.value -> look.

#Defaults for several constructs

A group written after a bare { }, with no name before it, sets defaults for everything inside the braces. The constructs compile in place, as if the braces were not there.

graph{
    {
        curve(expression: x^2)
        curve(expression: x^3; colour: blue)
        point(x: 1; y: 1)
    }(
        colour: red
        stroke-style: dashed
    )
}

Both curves are dashed. The first curve and the point are red; the second curve keeps its own colour: blue. The point declares no stroke-style, so that default passes it by. Each default is parsed by the type of the attribute it lands on. The braces take no detail.

#Values from elsewhere

A value can also be read from another construct, with #id (Identifiers & references), or computed, with {{…}} (Expressions). Some constructs publish attributes that are computed while they render and can only be read (Derived attributes).

Last updated