#Having a full white-on-black page for chapters, black-on-white for normal text, but still flow text

6 messages · Page 1 of 1 (latest)

sleek jacinth
#

Is this possible? See example images.

Note that the second page does NOT start with a new paragraph, it's just the continuation from the previous, chapter page.

Is this even possible with Typst?

cloud locust
#

I'd probably do this as a post-processing step. The stuff we can do based on what page things land on is still quite limited with flows that cross page-boundaries. I wouldn't know of a great solution to this besides utilizing this package to break up our text accordingly: https://typst.app/universe/package/meander

#

?r ps=d t=t ```ts
#import "@preview/meander:0.4.0"
#set page(background: context if here().page() == 1 { place(rect(height: page.height, width: page.width, fill: black)) })

#meander.reflow({
import meander: *

container(height: 100%, width: 100%, style: (text-fill: white))
content({
block(below: 1cm, [
#text(20em)[1]
#text(5em)[The Dark Page]
])
lorem(800)
})
})

#lorem(200)

cloud locust
#

Meander does a lot of magic to make this possible 😅
I'd use it as a last resort if you need to do these things today and try to minimize how much of the document depends on it (meander is pretty good but will slow things down at some point and there are a couple of bugs with a few edge cases). In plain Typst, styling and layout are still being worked on; it will probably be possible without hacks at some point.

pine bone
#

Actually doing this with meander is not to bad performance wise. I have improved on your proposal to make it viable as a template and stress tested it. Layouting 18 Chapters and 100 Pages of content took 3.2s, while incremental compilation continued to be fast enough for the web app to feel nice.

#import "@preview/meander:0.4.0"

#let chapter-block(body) = {
  pagebreak(weak: true)
  context place(center + horizon, rect(height: page.height, width: page.width, fill: black))
  meander.reflow({
    import meander: *
    container(height: 100%, width: 100%, style: (text-fill: white))
    content(body)
  })  
}

#let chapter-nr = counter("chapter-nr")
#let chapter-title(title) = {
  v(33%)
  chapter-nr.step()
  block(below: 1cm, [
    #text(15em, weight: "black", context chapter-nr.get().first(default: 0))
    #text(4em, weight: "bold", title)
  ])
}

#let chapter(title, body) = chapter-block({
  chapter-title(title)
  body
})

#set par(justify: true)

// Your Text

#chapter[The Dark Page][
  #lorem(1000)
]

#chapter[My Short Chapter][
  #lorem(300)
]

#chapter[The Long Chapter][
  #lorem(6000)
]