Skip to content

Polygons

Two keywords draw polygons, and which one to reach for depends on where the figure's shape comes from:

  • rect{} draws a rectangle. Its shape is settled in advance — four right angles — so nothing has to be said about it, and how big it is drawn is a matter of layout alone.
  • poly{} draws a polygon you hand the vertices of. Use it where the shape is what the exercise is about: a figure carrying a length on every side, with tick marks saying which of them are equal.

As for the other keywords, values are separated by ;, and options follow a | separator; multiple options are separated by ;.

Rectangles

The values are the side labels — the dimensions the exercise talks about. Give none, two (the length and the width) or four (one per side); _ leaves a side bare.

rect{unit{7 cm}; unit{4 cm}}

Sides and vertices are numbered from the bottom side, turning anticlockwise:

        D ────── 2 ────── C
        │                 │
        3                 1
        │                 │
        A ────── 0 ────── B

so with two values the length is written below the figure and the width to its right, and the two opposite sides are left bare rather than repeating them. With four values, the labels follow the sides in that order.

Drawn size and labelled size

The labels say nothing about how big the rectangle is drawn: a rectangle labelled 7 cm × 4 cm is not drawn seven units by four. The construction size is a matter of layout, and build=auto (the default) picks one in a range that depends on what the page is:

  • in a worksheet grid, where a dozen questions share the height of the page, figures stay small and lie flat — about half a centimetre tall printed, which is what keeps a line of the grid to a line's height;
  • on a plain exercise sheet, they have more room;
  • on a slide, one figure has the screen to itself.

Each of the three has its own range and its own band of width/height ratios (rendering.polygons.build in the configuration): a grid figure is flat by design, where a page or a slide one is only kept plausible.

Which of the three applies is decided by the render, not by the expression: the same wording is drawn from the same snapshot on a sheet and in a slideshow. Pass layout= to force one, or build={w,h} to set the construction size yourself (in units of the base font size).

An automatic size is drawn from a seed derived from the expression itself, so that the same expression always draws the same figure — the question page, the answer page and a snapshot rendered again months later all agree. Pass seed= to vary the drawing of two otherwise identical expressions.

Nothing is ever computed from the labels: the area written with center= is whatever you put there, not a product of the drawn sides.

Side labels, vertex names and centre content are written smaller than the text around them — the typographic convention for the dimensions of a figure, and what keeps a labelled figure inside a worksheet line. The ratio is rendering.polygons.label_scale; it is not to be confused with the font_size option below, which scales the whole figure, drawing included.

Options

  • build — construction size: auto (default), or {w,h} in units of the base font size.
  • layoutgrid, page or slide; overrides what the render targets, for the size build=auto picks.
  • seed — a whole number seeding build=auto, to vary two identical expressions.
  • right_anglestrue (default) codes the four angles, false codes none, and a comma-separated list of vertex numbers (e.g. 1,3) codes only those.
  • diagonalstrue draws both diagonals, false (default) none; a comma-separated list of vertex pairs (e.g. 1-3) draws only those.
  • diagonal_stylesolid (default) or dashed.
  • center — an expression written at the centre of the figure, typically its area — or a Q{} where the area is what is asked for.
  • name — one letter per vertex (e.g. ABCD), written outside the figure.
  • labels — how side labels are written: horizontal (default for a rectangle). sloped, which turns each label along its side, is not implemented yet.
  • color — colour of the sides and diagonals.
  • mark_color — colour of the angle codings, independent of the sides'.
  • label_color — colour of the side labels, vertex names and centre content.
  • fill — interior colour. Left out, the figure is transparent.
  • thickness — stroke width of the sides, in pixels.
  • baseline — vertical alignment with the surrounding text: middle (default), top or bottom, all three measured on the figure itself — labels hanging outside it don't shift them. box measures on everything drawn, labels included: use it where the figure shares a line with a wording, so that the whole line is centred on what the eye sees rather than a label above the figure pushing it up.
  • font_size — scales the whole figure.

Examples :

Expression Renders as
rect{unit{7 cm}; unit{4 cm}} 7cm4cm
rect{unit{9 m}; unit{5 m} | name=ABCD; right_angles=false} 9m5mABCD
rect{unit{7 cm}; Q{} | center=unit{28 cm^2}} 7cm?28cm2
rect{L; _; _; l | diagonals=true; diagonal_style=dashed; fill=#eef2ff; color=#1F5C99; mark_color=#c5000b} Ll

Any polygon

poly{} takes one label per side — _ for a bare one — and a shape= option giving the vertices it is drawn from, in units, x,y pairs separated by ;:

poly{unit{5 cm}; _; _ | shape={0,0; 5,0; 2.5,4.33}; marks={|; |; |}}

Sides are numbered from the first vertex: side i joins vertex i to vertex i+1, and the last one closes the figure. Three vertices at the least, and labels are given either none at all or one per side.

The shape is handed over, not drawn

This is where poly{} parts company with rect{}. A rectangle's construction size is picked at random within a band, because nothing ties it to the labels. A polygon's proportions, on the other hand, often are what it is labelled with: two sides carrying the same tick mark had better be drawn the same length, or the figure contradicts itself. So poly{} is given its vertices and never invents them.

What is left to decide is only how big, and fit=auto (the default) decides it: the figure is scaled — never stretched, which would undo its equal sides — to the largest that fits the room the current layout affords (rendering.polygons.fit in the configuration). Then, if what is written around it collides, it keeps growing by steps until it does not, up to rendering.polygons.fit_growth.max times that room: the labels keep their size whatever the drawing does, so a crowded figure is a figure drawn too small — never text to be shrunk. Pass fit=none to take the vertices at face value instead.

Equal sides

marks= writes a coding across a side: |, || or ||| for one, two or three ticks, _ for a bare side, one entry per side. Sides carrying the same coding are read as equal, which is what lets a figure be labelled once per batch of equal sides rather than once per side — the same economy rect{} makes when it leaves its two opposite sides bare.

Nothing here checks that a marked side really is equal to its fellows: as everywhere in atmxg, the expression says what to draw. Where the figure comes from a question type, that guarantee comes from the geometry that built it — see Question types.

Right angles

right_angles= takes a comma-separated list of vertex numbers, counting from 1 — or true / false for all of them and none. Note the difference from rect{}, whose four right angles are coded by default and where 1 reads as true: a polygon has no angle coded unless it is named, and right_angles=1 codes its first vertex.

Options

  • shape — the vertices, as {x,y; x,y; …} in units of the base font size. Required.
  • fitauto (default) scales the figure into the room the layout affords, growing it if its labels collide; none takes the vertices as they are.
  • layoutgrid, page or slide; overrides what the render targets, for the room fit=auto works with.
  • marks — one equality coding per side: |, ||, |||, or _ for a bare side.
  • right_angles — a comma-separated list of vertex numbers (e.g. 1,3), or true / false. None by default.
  • diagonals — a comma-separated list of vertex pairs (e.g. 1-3).
  • diagonal_stylesolid (default) or dashed.
  • center — an expression written at the centre of the figure.
  • name — one letter per vertex (e.g. ABCDE), written outside the figure.
  • rotation — degrees to turn the figure by, around its centre.
  • labelshorizontal (the default here, and the only one implemented).
  • color, mark_color, label_color, fill, thickness, baseline, font_size — as for rect{} above.

Examples :

Expression Renders as
poly{unit{5 cm}; _; _ | shape={0,0; 5,0; 2.5,4.33}; marks={|; |; |}} 5cm
poly{unit{9 cm}; _; _; unit{5 cm}; _; unit{2 cm}
     | shape={0,0; 9,0; 12.7,5.2; 10.4,10.1; 5.1,11.2; 0.6,8.4};
       marks={|; |; |; ||; ||; _}}
9cm5cm2cm
poly{unit{6 cm}; unit{4 cm}; _; _ | shape={0,0; 6,0; 8,3.5; 2,3.5}; name=ABCD} 6cm4cmABCD
poly{unit{3 cm}; unit{4 cm}; unit{5 cm} | shape={0,0; 3,0; 3,4}; right_angles=2} 3cm4cm5cm