Is `pagebreak` just a command, or also an element?

Continuing the discussion from How can I suppress headers and footers on blank verso/trailing pages:

We use a show rule “trick” to make pagebreaks detectable.

// make pagebreaks detectable
#show pagebreak: it => {
  [#metadata(none) <empty-page-start>]
  it
  [#metadata(none) <empty-page-end>]
}

@Andrew was confused about this, because he thought a pagebreak() was just a command.

Yes, for all intents and purposes a pagebreak is an element. I think you can find more elements than you can find non-elements. What I mean by element is the compiler definition of one. See How can I enumerate every element function in Typst?. It doesn’t mean the show rule will go well (e.g., with cite).

For more details, see the page.rs code

Below is “unexpected”, but perfectly acceptable Typst code.

#show math.overbrace: it => {
  it.annotation
}
$overbrace(1 + 1, "sum")$

For bibliography show rules, it’s very difficult… This is because the bibliography is not very flexible atm. Any reference to a label is first checked against the bibliography, and turned into a citation, but with no referring element.

#show cite: it => { // Do not do this
  ref(it.key) // it's a trap! (infinite loop)
}
#show ref: it => {
  // how to detect if the ref is to a bibliography item? 
  // it.element == none?
  // not very satisfying!
}

In what sense does it not create an element? The page code is a bit orthogonal, the comment there is about the absence of a “page element” rather than pagebreak.

For example the following code

#show: repr
= A
#pagebreak()
= B

shows

sequence(
  heading(depth: 1, body: [A]),
  [ ],
  pagebreak(),
  [ ],
  heading(depth: 1, body: [B]),
  parbreak(),
)

As far as I can see there is a real pagebreak element in the sequence.

Maybe there’s a confusion between page breaks (which are explicit markers to request a new page) and pages. Compiling #lorem(10000) will generate multiple pages without a single page break and in this case #show pagebreak: ... won’t match anything.

(Regarding the math.overbrace and ref things I’m a bit confused, are you sure they belong to this post?)

3 Likes

Ah you’re quite right! I read too fast. I will correct it.

I was expanding on the topic of elements by picking at something that is unexpectedly an element, e.g., “math.overbrace”, and the fact that some elements that in theory should exist, don’t, e.g., bibliography items.

I thought pagebreak is as long as a state.update or metadata — you can’t do anything with it, and the start/end markers will be in the exact same spot. But apparently pagebreak literally spans a whole page if needed.

I’m aware that pagebreak is an element. So, the title isn’t actually something that someone asked or interested in answer to (not me).