typst icon indicating copy to clipboard operation
typst copied to clipboard

Allow pagebreaks within containers (columns, lists, ...)

Open StrangeGirlMurph opened this issue 1 year ago • 7 comments

Description

+ A 
#pagebreak()
+ B

Should output "1. A" on the first page and "2. B" on the second page but instead outputs "1. A" and "1. B". They are treated as separate containers and the counter starts from one again.

Reproduction URL

No response

Operating system

No response

Typst version

  • [X] I am using the latest version of Typst

StrangeGirlMurph avatar May 21 '23 14:05 StrangeGirlMurph

Yeah, enums reset when they are inserted in a different container and in several other contexts. You're looking for 1. A #pagebreak() 2. B instead

PgBiel avatar May 22 '23 03:05 PgBiel

I'm closing this one, as I'm fairly sure it's the intended behavior. Without putting it on the same line, or by indenting the #pagebreak, typst interprets this as two different lists.

Enivex avatar May 25 '23 18:05 Enivex

Sadly indenting doesn't help :(

StrangeGirlMurph avatar May 25 '23 18:05 StrangeGirlMurph

Sadly indenting doesn't help :(

My bad, I misread it. You can use

+ A
  #v(1fr)
+ B

or

+ A #v(1fr)
+ B

My point originally was that

+ A
#pagebreak()
+ B

is interpreted as two different lists. Hopefully it will become possible to do

+ A
  #pagebreak()
+ B

in the future as an alternative to #v(1fr).

I reopened the issue.

Enivex avatar May 25 '23 18:05 Enivex

Yes the same should work with #pagebreak()

StrangeGirlMurph avatar May 25 '23 18:05 StrangeGirlMurph

I am having this issue when trying to use columns and break the page. I know the answer is "Use a colbreak() instead of a pagebreak()," but there may be a case where I want to force a page break regardless of where I am in the columns layout. If nothing else, maybe this comment will help someone else avoid the confusion I created for myself by hiding the show: columns.with() in a page template.

main.typ:

#import "template.typ": project
#show: project

#for value in range(30) {
  [
    + #value
  ]
}

// #pagebreak() // error: Pagebreaks are not allowed inside of containers
#colbreak() // works to break the page, but only if I know the last text ended on the second column

#for value in range(30) {
  [
    + #value
  ]
}

template.typ:

#let project(title: "", cols: 2, body) = {
  set page(
    paper: "a6",
  )
  show: columns.with(cols, gutter: 1.3em)
  body
}

https://typst.app/project/rW2DXeoRiTiwxau1zLbjE3

onomou avatar Mar 24 '24 19:03 onomou

The following worked for me. I have included some comments and stuff not used to help people come up with better alternatives. Ideally one that does not require passing in the number of columns.

#let my_pagebreak(n_cols: 2, ) = [
  #context[
    // #let n_cols = page.columns  // I wrap thing inside a #columns function to allow breaking out as needed. page.columns does therefore not do the job for me.
    #let width_page = page.width
    #let width_col = width_page/n_cols
    #let x_init = here().position().x
    #let n_current_col = calc.ceil(x_init/width_col)
    #let n_colbreaks_required = n_cols - n_current_col + 1
    #text(1pt, luma(100%))[#n_colbreaks_required] // The function breaks without this. Seems like an anchor for the colbreaks somehow
    #for _ in range(n_colbreaks_required){
        colbreak()
        // text[I am at page #{here().page()}]  // This reports the wrong page...
    }
  ]
]

KronosTheLate avatar Apr 18 '24 10:04 KronosTheLate