How to start page number 1 in the chapter 1?

I would like to have page 1 start from chapter 1, but it seems impossible. I don’t know how to set it up given the formatting of the document I want. Everything is fine, except for that detail. Could someone explain it to me?

main.typ:

#set page(numbering: "i", number-align: center)
#counter(page).update(1) 

// TOC
#toc()
#pagebreak()

#set page(numbering: none)

#document-template[
  #include "chapters/chapter1.typ"
  #include "chapters/chapter2.typ"
]

and in template.typ:

#let toc() = [
  #show outline.entry: it => {
    if it.level == 1 {
      strong(it)
    } else {
      it
    }
  }
  #set page(margin: 3.0cm)
  #v(2cm)
  #align(center)[
    #text(size: 22pt, weight: "bold")[Contents]
    #v(1cm)
    #set text(size: 16pt)
    #outline(
      title: none,
      indent: 1em,
      depth: 3
    )
  ]
]

#let document-template(body) = { 
  
  show heading: it => {
    let font_book = 16pt
    [
      #if it.level == 1 {
        pagebreak(to: "even", weak: false) 
        block(
          text(size: 28pt, weight: "bold")[#counter(heading).display() #it.body]
        )
        v(0.8em)
      } else if it.level == 2 {
        block(
          text(size: 20pt, weight: "bold")[#counter(heading).display() #it.body]
        )
        v(0.5em)
      } else {
        block(
          text(size: font_book, weight: "bold")[#counter(heading).display() #it.body]
        )
        v(0.5em)
      }
    ]
  }
  show link: set text(fill: blue) 
  set text(font: "Source Sans Pro", size: 16pt, hyphenate: true)
  set par(justify: true) 
  set figure.caption(position: bottom)
  set page(numbering: "1", number-align: center)
  counter(page).update(1)
  // Return body
  body
}

Some meta comments about your post itself, not the problem you are facing:

  1. The title of a question should, itself, be a question. See this nice guide: How to post in the Questions category
  2. You have included your code in code blocks which is great, but the language in this case should be typ:
    ```typ
    //Your code goes here
    ```
    
  3. The code you have provided does not compile. It takes more effort to help you if each person that attempts to do so must work around missing pieces. Your code as it has been posted has these two issues:
    • main.typ does not import template.typ so the functions called don’t exist in that scope
    • Neither of the chapters included in main.typ have been given. Using lorem() is handy for these kinds of MWE.
2 Likes

Hello @Rafael_Bluhm and welcome!

I think you will find your answer on this topic: How can I continue frontmatter numbering in backmatter?

1 Like

Solved by rewriting : Put a page numbering (none) inside toc and break page after (to jump to odd).

#let toc() = [
  #show outline.entry: it => {
    if it.level == 1 {
      strong(it)
    } else {
      it
    }
  }
  #set page(margin: 3.0cm)
  #v(2cm)
  #align(center)[
    #text(size: 22pt, weight: "bold")[Contents]
    #v(1cm)
    #set text(size: 16pt)
    #outline(
      title: none,
      indent: 1em,
      depth: 3
    )
    #set page(numbering: none)
    #pagebreak(to: "odd")
  ]
]

Then, can’t make automatic page break inside formatting function:

#let document-template(body) = { 
  show link: set text(fill: blue) 
  set text(font: "Source Sans Pro", size: 16pt, hyphenate: true)
  set par(justify: true) 
  set figure.caption(position: bottom)
  counter(page).update(1)
  set page(numbering: "1")

  // Ativa numeração para capítulos, seções e subseções
  set heading(numbering: "1.1")

  // Personaliza os headings por nível
  show heading: it => {
    if it.level == 1 {
      text(size: 28pt, weight: "bold")[#it]
      v(0.5cm)
    } else if it.level == 2 {
      text(size: 24pt, weight: "bold")[#it]
      v(0.3cm)
    } else if it.level == 3 {
      text(size: 20pt, weight: "bold")[#it]
      v(0.2cm)
    } else {
      // Outros níveis (se houver)
      it
    }
  }
  body
}

The page breakers to odd pages must be manual as:

#counter(page).update(1)
#set page(numbering: "i")

#toc()

#document-template[
  #include "chapters/chapter1.typ"
  #pagebreak(to: "odd")
  #include "chapters/chapter2.typ"
]

It is a less automatized version, but works.

2 Likes

Hi @Rafael_Bluhm, first of all welcome and thanks for editing your post as indicated!

If you’re satisfied with your solution, be sure to give it a checkmark :ballot_box_with_check:, this will help others find the solution in the future. If not, you can describe what you’re missing from your solution, or ask a new question focused on the remaining problem. Thanks! :slight_smile:

1 Like

I was waiting to see if anyone had a better solution. Thanks for remembering.

1 Like