Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export logic.typ for counter/state access #206

Open
ntjess opened this issue Feb 7, 2025 · 6 comments
Open

Export logic.typ for counter/state access #206

ntjess opened this issue Feb 7, 2025 · 6 comments

Comments

@ntjess
Copy link
Contributor

ntjess commented Feb 7, 2025

It would be nice to provide direct access to the slide counter, subslide, etc. However, since logic.typ isn't exported from the main entrypoint or toolbox, the counters are not accessible.

Toolbox only provides content versions of the first and last slides, and no way to access the current repetitions value

@ntjess ntjess changed the title Export logic.typ Export logic.typ for counter/state access Feb 7, 2025
@andreasKroepelin
Copy link
Collaborator

What would be the usecase of having access to these states and counters?

@ntjess
Copy link
Contributor Author

ntjess commented Feb 7, 2025

Sure, my preferred slide numbering format is slide.subslide, but this isn't exported by the toolbox. Furthermore, there are more options available when you have the direct number exported, rather than the content-ified version. Therefore I recommend allowing users to access the states, since (IMO) slide/subslide primitives are core presentation concepts rather than implementation details and therefore don't need to be hidden.

A workaround is for users to define their own counter('subslide'), and since the key is recycled they can access the state. But it would be ideal to use polylux's counters directly.

@andreasKroepelin
Copy link
Collaborator

Hmm I see. How about having

#toolbox.current-subslide // opaque content

#toolbox.with-subslide(s => 3 + s * 4)

?

Then it's still read-only access (which I would prefer) and at least your use case is covered.

@ntjess
Copy link
Contributor Author

ntjess commented Feb 8, 2025

IMO write access isn't too bad... It can just be clearly stated in the docs that it's undefined/forbidden behavior.

Otherwise, to access multiple properties at once with functions, you have to do

#toolbox.with-slide(s => {
  toolbox.with-subslide(sub => {
    toolbox.with-repeats(r => [
      Slide #s.(#sub of #r)
    ])
  })
})

It seems easier from UX/DX perspective to just provision counter access directly.

Edit: The simple example above works with just content versions of each counter. But having direct access to the numbers allows calculating other ratio/progress values for subslide vs repeats, counting total slides (repeats per slide plus total slides), etc. Typst in general compared to Powerpoint represents infinite customizability, and I'd love for that to continue being the message within polylux for slide fundamentals like numbering.

Edit 2: You could also have a "read-only" counter that's constantly updated by business logic that combines slide + subslide in true counter fashion:

#let slide-subslide = counter("exposed") 
// Handled internally by polylux, so even when user manually overrides the value, it has no effect by the next slide
#slide-subslide.update((1,2))

// User then has more "counter-y" freedoms
#context slide-subslide.display("1a")

@andreasKroepelin
Copy link
Collaborator

I think I like your last idea of those derived counters 👍🏼 Feel free to start a PR.

@jounathaen
Copy link

In my slide template (which is designed as a wrapper around polylux), there are some slides I don't want to count towards the total number of slides. These are section separators and backup slides. In previous versions of polylux, I implemented this by manipulating the counters in logic.typ.
Now that there is no more access to these counters, I've resorted to implementing my own slide counter. This works just fine and was not too difficult to implement, but now there are basically two counters with the same intention.

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

No branches or pull requests

3 participants