@preset

Declares a group of attribute values that constructs take by type or by name.

@presetDirectiveExplained in Modularity
On this page

#Attributes

nodeImplicit
The construct type the preset is for, written as the implicit value: @preset:curve. Without an id the preset applies to every construct of that type after it; with one, @preset#accent:curve, only to a curve that names it.
Can be written as shorthand: @preset:value

#Examples

@preset:text(text size: 24)
@preset#accent(colour: orange; width: 4)

graph{
    curve(expression: x^2; preset: #accent)
}
@preset#faint:curve(colour: grey; width: 1)

graph{
    curve(expression: x^2)
    curve(expression: x^2 + 1; preset: #faint)
}

#Notes

  • A preset with an id is applied by name, preset: #accent, or several at once, preset: #faint, #accent, a later one over an earlier.
  • An attribute written on the construct wins over a named preset, which wins over a preset by type, which wins over the attribute's default.
  • A preset by type reaches the constructs after it inside the construct that holds it; a second one for the same type replaces it from there.
  • A named preset is declared before use: unknown preset #accent — presets must be declared before use.
  • Presets apply to block constructs only, cannot name other presets, and do not apply to a @define use.
  • A preset with neither a type nor an id is refused: @preset: missing target: use @preset:node, @preset#id, or @preset#id:node.
  • A preset with a body is refused: @preset: takes attributes only.
  • An attribute the type does not have is refused: @preset: node curve does not declare an attribute nosuch.
  • A micronode as the type is refused: @preset: bold is a micronode — node presets apply to block nodes only.
  • preset: inside a preset is refused: @preset: presets cannot reference other presets.
  • A typed preset applied to another type is refused: preset #accent is scoped to curve nodes and cannot apply to node point.
  • An id already taken is refused: duplicate id #apple — already declared by a preset at line 7.
  • A preset's id used as a reference is refused: id #a names a preset — references target nodes and micronodes.

Last updated