Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

feat: properly update last used coordinate "()" #161

@bendix4620

Description

@bendix4620

The problem

Currently, zap does not allow cetz to update the last used coordinate

#import "@preview/zap:0.5.0"
#set page(width: auto, height: auto, margin: 5pt)

#zap.circuit({
  import zap: *
  resistor("r1", (), (2, 0))
  resistor("r2", (), (2, 2))
})
what I got what I want
what I got what I expected

Proposed Solution

change the scoping and coordinate resolution to allow updates of ctx.prev:

#let component(...) = {
  ...

  // resolve coordinates and update the context
  get-ctx(ctx => {
    let (ctx, ..position) = cetz.coordinates.resolve(ctx, ..position)
    set-ctx(_ => { ctx }) // update the context, so "ctx.prev" is correct
  
    // wrap all component logic/drawing inside scopes or groups, so that it does not alter the context any further
    scope({
      // draw the component here
      ...
    })
    // the scope/group will reset the context (and keep the anchors)
  })
}

Contribute

  • I am willing to submit a pull request for this feature
  • I can help with testing this feature

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions