Skip to content

Elements with no content can force a breakable block to create an empty frame #2297

Closed

Description

@MDLC01

Description

If a block has its breakable property set to true, it may be broken across multiple pages in what are called “frames”. When an element in a block is too big to fit on the current page, it creates a new frame on the next one and the block continues there. If the first frame of a block is empty (typically, because the first element of the block was too big to fit on the first page), it is not displayed (unless there is no other frame).

let mut skip = false;
if let [first, rest @ ..] = frames.as_slice() {
skip = first.is_empty() && rest.iter().any(|frame| !frame.is_empty());
}

However, if the first frame of a block contains elements that have no visible content (like a counter update), it is still displayed, even though it has no visible content.

This issue should not be too hard to fix, as a similar problem was already solved in #1929, although there is something more to this one: out-of-flow elements (typically, place) should be treated as “basically empty”, and they may also have to move across frames. Indeed, if the element that causes the first frame to be displayed is an out-of-flow element, I think it is safe to assume you would want it to (1) not cause the first frame to be displayed, and (2) be laid out as part of the first displayed frame.

Reproduction

#set page(height: 10cm, margin: 1cm)

Not enough space on this page to fit the rectangle, so the whole block is moved to the next page.
#block(breakable: true, stroke: 1pt, inset: 0.5cm)[
  #rect(height: 7cm, fill: gray)
]

Not enough space for the rectangle on this page either, but this time there is an invisible element (a counter update) before the rectangle within the block.
#block(breakable: true, stroke: 1pt, inset: 0.5cm)[
  #counter("dummy").step()
  #rect(height: 7cm, fill: gray)
]

Not enough place again, but this time, the element that's causing the first frame to be displayed _has_ visual content, but it is out-of-flow, so we might want it to belong to the next frame instead.
#v(0.5cm)
#block(breakable: true, stroke: 1pt, inset: 0.5cm)[
  #place(dx: -0.5cm, dy: -1cm, box(width: 200%)[Out of flow title])
  #rect(height: 7cm, fill: gray)
]

Operating system

No response

Typst version

  • I am using the latest version of Typst

Activity

  1. added
    bug
    on Oct 2, 2023
  2. MDLC01 commented on Oct 2, 2023

    @MDLC01
    CollaboratorAuthor

    I realise now that I may not have been very clear in the original message: the main question here is how to treat out-of-flow elements.

  3. added
    layout
    on Oct 4, 2023
  4. added a commit that references this issue on Oct 30, 2023
    34e27a9
  5. added a commit that references this issue on Nov 26, 2023
    5e79567
  6. laurmaedje commented on Nov 27, 2023

    @laurmaedje
    Member

    Example:

    #set page("a6")
    
    #lorem(120)
    
    #block(stroke: 2pt, inset: 10pt, width: 100%)[
      #counter(heading).update(1)
      #rect(height: 70pt)
    ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buglayout

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions