Skip to content

Spreadsheets

The spreadsheet{} keyword draws a small extract of a spreadsheet: the cells a formula reads its values in, and the cell the formula is typed in.

spreadsheet{A2=7; B2=Q{}}

Each value is one cell — its reference, =, and what it holds. Values are separated by ;, and options follow a | separator; multiple options are separated by ;.

Expression Renders as
spreadsheet{A2=7; B2=Q{}} AB27?

The formula is not in the picture

A spreadsheet question shows a formula — in B2, one types =9+6*A2 — and that sentence belongs to the wording, not to the figure. The picture holds the cells, their references and their values, and nothing else: it is what keeps it readable when a slideshow blows it up to fill a screen.

The formula itself is written with code{}, verbatim and in the font of source code — what is typed on a keyboard is not mathematics set in type:

Expression Renders as
En B2, on entre code{=9+6*A2}. En B2, on entre =9+6*A2.

The layout is read off the references

There is no layout option, and no horizontal or vertical variant to pick. The keyword reads the references it is given, takes the rectangle they span, and draws the headers of the columns and rows it covers.

Expression Renders as
spreadsheet{A2=7; A3=Q{}} A237?
spreadsheet{A2=7; B2=3; C2=Q{} | select=C2} ABC273?
spreadsheet{B3=12; C4=Q{}} BC3412?

Cells of that rectangle that were not given are drawn empty — as in the last example above, where B3 and C4 span a 2×2 block of which two cells hold nothing. A cell written _ is drawn empty too, which is how a figure reaches beyond the cells it fills: spreadsheet{A2=7; B2=Q{}; B3=_} draws the 2×2 block A2:B3. A figure may span at most 4 columns by 4 rows; past that it stops being a picture one can read at a glance, and the keyword refuses it.

Keeping room for the answer

A cell holding a Q{} shows a red question mark on the question, and the answer once it is substituted on the correction. A question mark is narrower than most answers, so the figure would change width between the two — visibly jumping, on a slideshow where the question and its answer follow one another.

reserve= is what prevents it: give it the content the placeholder will make way for — the answer — and the cell is sized from the start for what will land in it.

spreadsheet{A2=7; B2=Q{} | reserve=104}

Only the cell holding the placeholder is concerned, and only by what the answer takes beyond the question mark: a cell reading math{Q{} + 1} grows by the difference, not by the answer's whole width.

The reservation is capped at rendering.spreadsheets.cell_max_width_ratio (× the font size). Past that width an answer has no place in the picture anyway, and the question is better off writing it under the figure. The cap never clips what a cell actually holds, though: an answer wider than the reservation still widens its cell rather than overflow it.

Options

  • reserve — the content every cell holding a Q{} must keep room for, written like a cell value. Capped at rendering.spreadsheets.cell_max_width_ratio × the font size.
  • select — the reference of a cell to outline, the way a spreadsheet outlines the selected one. It must be one of the drawn cells. Left out, nothing is outlined.
  • cell_width — equal (the default) gives every column the width of the widest cell; auto sizes each column on its own content.
  • baseline — vertical alignment with the surrounding text: middle (default, the middle of the whole figure), top (the middle of the first row of cells) or bottom (the middle of the last one).
  • color — colour of the text and of the ruling. Left out, it follows the surrounding text.
  • border_color — colour of the cell ruling alone, when it should differ from the text.
  • header_fill — background of the two header bands; rendering.spreadsheets.header_bg by default.
  • header_color — colour of the thin lines ruling the header bands; rendering.spreadsheets.header_line by default, lighter than the cell grid so the eye reads the cells first and the references second.
  • font_size — a multiplier of the surrounding font size, applied to the whole figure.

Sizes

Every size is a ratio of the surrounding font size (see rendering.spreadsheets), so the figure follows the text it is set in — small in a worksheet, large on a slide — with no per-layout value to keep in step:

  • cell_pad_h_ratio, cell_pad_v_ratio — padding inside a cell;
  • cell_min_width_ratio — narrowest a cell may get, so a cell holding one digit still reads as a cell;
  • cell_max_width_ratio — widest a reservation may make one;
  • header_min_width_ratio — narrowest the column of row numbers may get;
  • border_thickness, header_thickness, select_thickness — the three strokes;
  • header_bg, header_line, select_color — the three colours.