Skip to content

Conversation

@andreasKroepelin
Copy link
Collaborator

@andreasKroepelin andreasKroepelin commented Apr 13, 2023

This PR makes the API for dynamic content much more convenient and also closer to what LaTeX beamer offers.

In particular, we now have

  • #pause (pretty much like in beamer) a poor man's version of \pause in beamer using #show (you have to track the "progress" of it manually)
  • #only without reserving space
  • #uncover reserving space
  • some convenience functions (#alternatives, #one-by-one, #line-by-line)
  • complex display rules of the form "-2, 5-7, 9, 11-" for #uncover and #only
  • different modes of covering are now called "invisible" and "transparent" as in beamer and are not handled globally anymore

To do:

  • update documentation in the book
  • adapt examples

If you want to review this, it is probably a good idea to go through examples/demo.typ and see if the API actually is pleasant to work with.

Any opinions are welcome! Pinging @drupol @PgBiel @astrale-sharp @palainp

@andreasKroepelin andreasKroepelin marked this pull request as draft April 13, 2023 15:11
@andreasKroepelin andreasKroepelin marked this pull request as ready for review April 13, 2023 15:12
Copy link
Contributor

@drupol drupol left a comment

Choose a reason for hiding this comment

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

I just tested it on my own slides ... I just love it.

Please merge it :)

@palainp
Copy link

palainp commented Apr 13, 2023

It looks great, I'll test that soon!

@drupol
Copy link
Contributor

drupol commented Apr 13, 2023

I think there is a bug with one-by-one... I'll see if I can reproduce it => https://typst.app/project/r7yTm5eybG7JmVb4m1oU61

Also, if you add #set par(justify: true) in your slide, then #pause does not work anymore. => https://typst.app/project/rz1W4y5R8mSbvIxVHmiUDh

@andreasKroepelin
Copy link
Collaborator Author

Also, if you add #set par(justify: true) in your slide, then #pause does not work anymore. => https://typst.app/project/rz1W4y5R8mSbvIxVHmiUDh

The issue here is the #set .... It introduces a styled element and all subsequent content is a child of that. The logic for #pause assumes that all content of a slide is just one flat sequence. I'm afraid that as long styles are opaque, this will not work with styled content. I guess I'll just add a guard against that for now, so #pause will only work in slides without a #set ... command.

@drupol
Copy link
Contributor

drupol commented Apr 13, 2023

The issue here is the #set .... It introduces a styled element and all subsequent content is a child of that.

Argh that's so unfortunate :(

@andreasKroepelin
Copy link
Collaborator Author

I think there is a bug with one-by-one... I'll see if I can reproduce it => https://typst.app/project/r7yTm5eybG7JmVb4m1oU61

The bug is actually with the cover-mode state. Apparently querying its value at the time of covering does not work reliably. It looks like changing the cover-mode at one place has consequences for unexpected (e.g. earlier) places...

@drupol
Copy link
Contributor

drupol commented Apr 13, 2023

The issue here is the #set .... It introduces a styled element and all subsequent content is a child of that.

Argh that's so unfortunate :(

I made some changes and I got it working !

@andreasKroepelin
Copy link
Collaborator Author

I made some changes and I got it working !

How? 😮

@drupol
Copy link
Contributor

drupol commented Apr 13, 2023

Check the link: https://typst.app/project/r7yTm5eybG7JmVb4m1oU61

@andreasKroepelin
Copy link
Collaborator Author

andreasKroepelin commented Apr 13, 2023

I think there is a bug with one-by-one... I'll see if I can reproduce it => https://typst.app/project/r7yTm5eybG7JmVb4m1oU61

Also, if you add #set par(justify: true) in your slide, then #pause does not work anymore. => https://typst.app/project/rz1W4y5R8mSbvIxVHmiUDh

Okay so both of these issues are fixed now, however with some disadvantages to the API 😞

First, we can't have a simple #pause because of styles, as explained above. In principle, we could do a similar parsing as for the original #pause idea, just a bit more complex tree-traversal, but one can (currently) not mutate the children properties of sequences, nor the child property of styled, nor one can programmatically create sequence or styled directly (try calling [ a b c ].func(), which is a sequence, with arguments, it doesn't work).

For that reason, we have to fall back to the "do something with the rest of this scope"-mechanism that Typst provides: #show. By making pause a shallow wrapper around uncover [EDIT: and introducing a new global counter], we can now write #show: pause(2) #show: pause and then the rest of the slide is uncovered on the second next subslide. For subsequent pauses, you would write #show: pause(3), #show: pause(4).

I think using #show is fine in principle (probably kinda Typst-idiomatic) but it's annoying that you need to keep track of the "index" of the pause yourself. Maybe there is a solution to that using a global counter, but so far my experiments in that direction did not work. [EDIT: Using a global counter, you do not need to track the "index" of the pause yourself. I just did a silly error in previous implementations so they didn't work.]

Next, there is the issue with the cover mode. As explained in an earlier comment, this behaves somewhat inpredictably and makes the #cover-mode-transparent and #cover-mode-invisible commands unusable. I have therefore decided to get rid of that global state and add optional mode arguments to every function that covers something. So you write

#uncover(2, mode: "transparent")[still visible]
#show: pause(3, mode: "transparent")
#one-by-one(mode: "transparent")[a][b][c]

etc. now.

This is also a bit inconvenient but at least this could be fixed in the future when Typst allows #set rules for custom functions.

P.S.: states and counters can be really confusing and I get somewhat annoyed that it's so hard to predict how they behave...

@andreasKroepelin
Copy link
Collaborator Author

As @palainp has found out, it doesn't work to have #show: pause and then step a global counter inside the pause function. So we are back to the system where you would have to increase that counter yourself...

To relieve the pain a tiny bit, you can at least write

#let pc = 1
some text
#{ pc += 1 } #show: pause(pc)
more text
#{ pc += 1 } #show: pause(pc)
yet another text

Kinda frustrating that this seems to be the best option for now.
Well, besides getting rid of some kind of pause completely, that is. But that would be even more sad, don't you think?

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.

4 participants