Add description-width config option #21

Merged
HEL merged 2 commits from dromell/rivet-typst:feat/description-width into dev 2026-08-29 10:22:36 +00:00
2 Commits
Author SHA1 Message Date
dromell f4c3fc7f61 fix: measure the description width instead of estimating it
With left-labels a description is placed by subtracting its width from
desc-x. That width was estimated as half the font size per character,
which undershoots Ubuntu Mono's advance of 0.56em by 12%, so the leader
line struck through the last letter of every label, as it does on the
manual's own cover page. Proportional fonts were off by more.

render is now a context block, so the text can be measured instead. The
font has to be passed explicitly: the set rule at the top of render is
not in scope for a measure further down the same context block.
2026-08-25 14:51:19 +02:00
dromell ac759746f3 feat: add description-width config option
Descriptions and values are drawn as a single line that never wraps.
Because a diagram is scaled to fit the width it is rendered into, the
longest label is what decides that scale: one long description makes the
whole diagram -- bit cells, indices and every other label with it --
shrink until that line fits. A register whose fields carry a sentence
each is then unreadable at any page width, and since each diagram is
measured on its own, a document full of them renders every one at a
different size.

Setting description-width wraps labels at that width instead, so the
length of a description no longer decides how large the diagram is
drawn. Values wrap at the same right edge as the description they belong
to, and the option composes with left-labels, force-descs-on-side and
ltr-bits.

Wrapping means a label is no longer one line tall, so labels can no
longer be spaced by a fixed line height. Each is now offset by the
height it actually occupies, measured before it is placed, which is why
render gained a context block.

The option defaults to none, which keeps the single-line behaviour on
the original code paths. With it unset every diagram in the gallery
renders byte-identical to before.
2026-08-25 14:51:19 +02:00