# Percentage-anchor memory verification - 2026-10-10

The reported `TeX capacity exceeded [main memory size=5000000]` error occurred
while declaring Carnot's percentage anchors in the generated Overleaf runtime.
The package expanded each family into 101 copies of its complete coordinate
calculation. The shape where allocation fails depends on available preamble
memory; it need not indicate a fault in that shape's physical equations.

## Storage and compatibility

A runtime-instrumented declaration count finds **374 complete native percentage
families and 37,774 anchor names**, including bare numeric legacy aliases.
The fix compacts **346 families / 34,946 anchor definitions**: each family has
one shared calculation, and each anchor stores a call with its literal integer.
The other 28 families already delegate to shared wedge/ramp/optics geometry
helpers. Indexed wave-mode anchors and coordinates created by individual pics
are outside this native percentage count.

PGF stores named anchors as TeX control sequences, for example
`\pgf@anchor@physicscarnotcyclenode@hot-6`. It restores a named node's saved
points/macros and transformation before evaluating that shape's anchor.
The replacement anchor calls
`\tikzphysics@anchorfamily@physicscarnotcyclenode@hot{6}`. The family's body
restores the same saved component state and evaluates the same expressions.
The helper control sequence is bound at declaration time; geometry expressions
remain unexpanded until access. Families are isolated by shape and family name.

This preserves integer ranges, aliases, directions, per-instance parameters,
transformations, debug/reference registration and physical styling. Definitions
are shared across instances of a shape; individual nodes retain their own saved
geometry. Runtime formula expansion, rather than `.sty` byte size, is what
consumed the excess memory.

## Verification

- All 16 `l3build check` suites pass without changing their baselines.
- `scripts/verify_overleaf.py` passes its minimal Carnot probe, fixed preamble
  pressure test and all 14 shipped `.tex` examples: 16 isolated compile checks.
  Every compile fixes `main_memory=5000000`, `extra_mem_top=0`,
  `extra_mem_bot=0`, uses an empty `TEXMFHOME`, and records only the local
  standalone runtime, with no installed or split physics source.
- A matched minimal Carnot compile changes from 3,404,339 to 1,405,834 words
  of reported main memory, a reduction of about 59 percent. The general
  formulas, optics arcs/numeric anchors and differential arcs/edges are compact.
- The previous bundle reproduces the same capacity error with pgfplots,
  circuitikz and a fixed 524,288-token preamble payload at the 5-million-word
  budget. The corrected bundle passes that pressure test. The failure appears
  in a later shape declaration because remaining memory differs by preamble.
- All 58 repository example documents compile, producing 156 pages. All 34
  pages of the 14 shipped Overleaf examples are pixel-identical before/after
  at 72 dpi; representative Carnot, optics and differential-element pages
  were visually inspected.
- Generated reference and bundle freshness checks pass for all 122 features.
- The rebuilt Overleaf ZIP contains 21 files; its `.sty` matches the canonical
  generator output and its archive integrity check passes.

Evidence is under `tmp/overleaf-memory-review/`: before/after logs, isolated
compile recorders, regression output, declaration counts, example build evidence
and before/after render comparisons. The published 1.7.0 CTAN archive is unchanged;
this fix is local/unreleased and available through the direct-upload bundle.

Regenerate and verify with:

```sh
python3 scripts/build_overleaf_bundle.py
python3 scripts/build_overleaf_bundle.py --check
python3 scripts/verify_overleaf.py
l3build check
```

Replace the old project-local `tikzphysics.sty` on Overleaf and use **Recompile
from scratch**. Verification here is local pdfLaTeX compatibility testing, not a
claim that the user's hosted project was accessed.
