touying-typ / touying

Touying is a powerful package for creating presentation slides in Typst.
https://touying-typ.github.io/touying/
MIT License
461 stars 10 forks source link

Is it possible to set slide titles by level-2 headings but create slides with `#slide` function? #7

Closed HPDell closed 4 months ago

HPDell commented 4 months ago

Hi! Thanks for your great package.

I've learnt that there are two modes to create packages. In one way, we use #slide to create slides and put the title in the argument title. In the other way, we show the document with #slides and use headings to create slides.

However, I wonder whether a third way is possible. That is to set sections, subsections, and titles with headings (of levels 1, 2, and 3 respectively), but they do not create any slides. Instead, we still use #slide to create slides. By this practice, we can leave a clear structure in the document. And when we need to create several slides with a same title, we don't need to type the title repeatedly.

For example

= Section 1

#new-section-slide[
  Additional content
] // -> A section slide

== Slide A

#slide[
  Some content
] // -> A slide with title "Slide A" and content "Some content".

#slide[
  Some other content
] // -> Another slide with title "Slide A" and content "Some content".

Contents outside the range of #slide are ignored.

OrangeX4 commented 4 months ago

I also really like this syntax, and I've considered it before. The most challenging of implementing this syntax might be performance issues. To achieve the desired syntax, we would need to use a syntax like #show: slides. However, due to triggering the execution of slides(body) function every time there is a small change, there could be significant performance issues, especially in cases where there is a substantial amount of content.

Additionally, we would need a way to encapsulate the slide function and title-slide with metadata.

HPDell commented 4 months ago

How about using the section states? The headings are used to change a state, and the slide function choose the last section there and render the section's name as its title? Just think about some books that the current section is shown in each header (see the following image as an example). Is it possible to copy that design?

image

The following codes are showing the idea that was implemented by myself a few months ago.

#let template(body) = {
  show heading.where(level: 3): none
  ...
  body
}

#let slide() = {
  ...
  locate(loc => query(
    selector(heading.where(level: 3)).before(loc), 
    loc
  ).last().body)
}

But I cannot use them with polylux, or the rendering will be broken.

OrangeX4 commented 4 months ago

I understand your idea, and I've thought about it before, but the actual problem is updating state before #slide[] will creates an empty page. This is due to typst's own limitations, i.e. 'set page()' creates a new page. A big part of touying's job is to avoid this problem.

#import "@preview/touying:0.2.1": *

#let (init, slide,) = utils.methods(s)
#show: init

#states.slide-counter.step()

#slide[
  Updating state before `#slide[]` creates an empty page.
]

image

OrangeX4 commented 4 months ago

And what you said about showing the current section, touying is already doing that, such as the metropolis theme.

HPDell commented 4 months ago

I understand your idea, and I've thought about it before, but the actual problem is updating state before #slide[] will creates an empty page. This is due to typst's own limitations, i.e. 'set page()' creates a new page. A big part of touying's job is to avoid this problem.

I see. And I noticed that "Page adjustment from within flow" is put in the roadmap. Maybe they are going to fix this problem in the future.