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

Fix frozen-counters bug with multiple #pause commands #124

Merged
merged 3 commits into from
Nov 29, 2024

Conversation

enklht
Copy link
Contributor

@enklht enklht commented Nov 28, 2024

Description

This PR addresses a bug in the frozen-counters functionality where status updates show unexpected behavior when using multiple #pause commands. This issue may be related to #72.

Problem

When using multiple #pause commands, figure captions are not correctly incremented. For example, in the example below with multiple figures and pauses, the final figure might be captioned as "Figure 2:" though it should be "Figure 3:".

#import "@preview/touying:0.5.3": *
#import themes.simple: *

#show: simple-theme

== slide 1
#figure([test figure], caption: [caption])

== slide 2
#figure([test figure], caption: [caption])
#pause
paused

== slide 3
#figure([test figure], caption: [caption])
#pause
paused

Solution

Instead of storing the counter value at the beginning of a sequence of subslides, we now store the location. We then use status.at(location) to rewind the status when needed. This approach ensures that counters are correctly updated across pauses and slides.

Testing

I have tested my code with examples given in the examples folder in this repository, besides the example above, and two examples in #72. All of them compiled with no errors / warnings.


  • As I'm not fluent in Typst, my code might not be fully ideomatic. I welcome any revisions or improvements to the implementation.
  • It might be better to store the location in some outer variable (e.g. #utils.current-slide) and update it when creating a new slide, instead of querying the label for every new subslide.
  • minor fix: I found a variable named current, which is not used, so I deleted it.

@enklht
Copy link
Contributor Author

enklht commented Nov 28, 2024

It might be better to store the location in some outer variable (e.g. #utils.current-slide) and update it when creating a new slide, instead of querying the label for every new subslide.

I found this idea won't work because Typst doesn't allow changing outer variables within a context. Therefore, querying the label for every new subslide is necessary with this approach.

@enklht
Copy link
Contributor Author

enklht commented Nov 28, 2024

I added a new state #utils.loc-prior-newslide to store the location of parent slides. This simplifies the code and improves readability (and performance?) The implementation works well in testing. Sorry for sending multiple comments in a short period.

@OrangeX4 OrangeX4 added enhancement New feature or request bug Something isn't working labels Nov 28, 2024
@OrangeX4
Copy link
Member

Thank! I'll check it out later.

@OrangeX4
Copy link
Member

Thanks, I think your method is more elegant.

@OrangeX4 OrangeX4 merged commit ebf5040 into touying-typ:main Nov 29, 2024
@OrangeX4 OrangeX4 linked an issue Nov 29, 2024 that may be closed by this pull request
@OrangeX4
Copy link
Member

With this PR, we can also add the counter(heading) to the frozon-counters: 34bfe9e

@enklht
Copy link
Contributor Author

enklht commented Nov 29, 2024

Yes, and that resolves the issue #83.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
3 participants