Skip to content

cetz skill: correct the anchor gotcha's mechanism, and add four more - #598

Merged
lmoresi merged 1 commit into
developmentfrom
docs/cetz-cheatsheet-gotchas
Aug 18, 2026
Merged

cetz skill: correct the anchor gotcha's mechanism, and add four more#598
lmoresi merged 1 commit into
developmentfrom
docs/cetz-cheatsheet-gotchas

Conversation

@lmoresi

@lmoresi lmoresi commented Aug 17, 2026

Copy link
Copy Markdown
Member

All six entries cost a compile failure during the rotated-boundary-conditions figure, so they are diagnosed rather than recalled.

The existing entry had the wrong mechanism

The skill said cetz "treats anchor: specially". It does not. The cause is the import cetz.draw: * that a drawing helper needs in its own body — it runs inside the function after the parameters are bound, and shadows any parameter sharing a name with a cetz.draw export.

Isolated: the same helper without the inner import compiles fine. That is what identifies the import rather than the parameter name.

This matters because it converts a one-name warning into a rule. A parameter named fill fails the same way, with an error that is much harder to read:

error: expected color, gradient, tiling, or none, found function
  ┌─ @preview/cetz:0.3.4/src/canvas.typ:145:16

— reported inside cetz's own source, nowhere near the helper. And it gives the second fix: if the helper does not actually draw, drop the inner import instead of renaming.

Four new entries

  • let h(x) = ... shadows Typst's h(). A figure defining a surface height as h(x) breaks every #h(0.4em) used for spacing in a label, failing with "cannot add length and float" — an error naming neither the function nor the label.
  • A multi-line expression in a let ends at the first newline unless parenthesised, reported as unknown variable: x, which sends you looking at the wrong line.
  • content() anchored "west" centres a multi-line block vertically, so a caption that wraps grows upwards into the heading above it. Nothing errors — it only shows up in the PNG.
  • Joining nodes by a distance threshold is not a triangulation. It silently omits nodes near the domain edge and in sparse regions, and the result looks almost right. Plus the two follow-ons on a geophysical domain: Delaunay fills the convex hull, so a domain under topography needs triangles culled by centroid; and a perfect lattice produces degenerate slivers, so stagger alternate rows.

Documentation only — no code paths touched.

Underworld development team with AI support from Claude Code

The skill said cetz 'treats anchor: specially'. It does not. The cause is the
import cetz.draw: * that a drawing helper needs in its own body: it runs inside
the function after the parameters are bound and shadows any parameter sharing a
name with a cetz.draw export. Isolated by removing the inner import from an
otherwise identical helper, which compiles.

That turns a one-name warning into a rule, and covers fill and stroke as well —
a parameter named fill fails with 'expected color, gradient, tiling, or none,
found function' reported inside cetz's canvas.typ, nowhere near the helper.

Four more, each one compile failure during the rotated-BC figure:

- let h(x) shadows Typst's horizontal-spacing h(), so a figure defining a
  surface height breaks every #h(0.4em) in a label, with an error naming
  neither;
- a multi-line arithmetic expression in a let ends at the first newline unless
  parenthesised, reported as 'unknown variable: x';
- content() anchored west centres a multi-line block vertically, so a caption
  that wraps grows upwards into the heading above it — nothing errors, it just
  overlaps;
- joining nodes by a distance threshold is not a triangulation and silently
  omits nodes, plus the two follow-ons for a non-convex domain: Delaunay fills
  the convex hull so cull by centroid, and a perfect lattice gives degenerate
  triangles so stagger the rows.

Underworld development team with AI support from Claude Code
Copilot AI lite review requested due to automatic review settings August 17, 2026 09:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@lmoresi

lmoresi commented Aug 18, 2026

Copy link
Copy Markdown
Member Author

Adversarial review — documentation, skills and tooling (#476, #580, #598, #599)

Reviewed together because none of them changes library behaviour and the useful
question is the same for all four: is the claim they make true of the code as it
stands today.

#580refinement=R is a factor on the background spacing

Verified against the source. The correction says coarsening="auto" is the
budget-conserving R**(1/d), so the envelope is h in [h0/R, h0·R**(1/d)] and
the finest:coarsest ratio is R**(1+1/d). metrics.py:587 reads

coar_val = ref_val ** (1.0 / cdim)

which is exactly that, and the arithmetic in the text checks: R=5 at d=2 gives
2.236 and a ratio of 11.18; at d=3, 1.71 and 8.55. The previous wording — "the
finest:coarsest grading ratio" — was wrong by that factor, so anyone who tuned R
against an observed ratio was tuning against a number roughly twice what they
asked for.

One thing the correction does not say: whether any existing example or notebook
was written against the old reading and now wants its R adjusted. Worth a grep
before this lands, since the doc change alone will make previously-tuned scripts
look wrong rather than making them right.

#476 — adapt cost microbenchmark

Its red CI is stale, not a defect in the change. The failures are in
test_0851_fault_network_3d.py and test_0851_std_reduction_method.py, neither
of which this PR touches — it changes one script. The run is from 2026-08-12
against a trunk that was red at the time. We re-triggered it; if it comes back
green the PR is a one-file update with nothing to argue about.

scalar_dt is the substantive addition: it coerces estimate_dt() output to a
float, taking nanmin over an array, and raises on a non-finite or non-positive
result. That is a benchmark script defending itself against an API that returns
different shapes, which is reasonable here — but the same coercion is what a
caller of estimate_dt() in a model script would have to write, and it belongs
behind the API rather than in each consumer. Worth an issue rather than a change
to this PR.

#598, #599 — cetz figure skill and the rotated-basis figure

These two are a pair: #598 corrects the skill's anchor guidance and adds
gotchas, #599 is a figure built to that skill's rule that geometry is computed
in Python and Typst only draws. #599's own docstring records why — an earlier
version connected nodes by a distance threshold and silently dropped several
from the mesh — which is the kind of failure the rule exists to prevent, and it
is good that the script says so where the next author will read it.

The reviewable question for the pair is whether #598's corrected guidance
matches what #599 actually does, since one is the rule and the other is the
worked example. They were authored together, so agreement is likely and
unchecked; if the skill is meant to be normative it would be worth having the
example's JSON schema referenced from the skill rather than described twice.

Neither changes library code, so the risk is confined to what a future author is
told.

Underworld development team with AI support from Claude Code

@lmoresi
lmoresi merged commit 4ba0488 into development Aug 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants