Most basic: page numbering on footer

I’ve already browsed al topics, but I’m unable to insert page numbering in my footer. I have this:

#set page(
  numbering: "1",
  number-align: start,
  footer:   
    counter(page).update(1),
    align(left)[
      My Footer
    ], 
    footer-descent: 10% + 15pt,
  )

What is wrong?

Try something based on this:

#set page(
  footer:   
    context{counter(page).display()
      [ My Footer]
   }
  )
  This is a page
  #pagebreak()
  This is a page

The important thing here is that context is needed.

The default numbering is “1” and the default alignment is left.

Explicit page.footer content needs to explicitly show page number. The set rule does not display page number in any way. Furthermore, the provided example does not compile. Page Function – Typst Documentation

Now I’ve set the context, but I want the page number at the location marked by X.

#set page(
  paper: "a4",
  margin: (left: 25mm, right: 70mm, top: 20mm, bottom: 28mm),
  numbering: "1",
  number-align: start,
  footer:   
    context{counter(page).display()
      [X — My Footer]
    #set align(left)
    #set text(10pt)
   },
  footer-descent: 10% + 15pt,
)

Instructions don’t tell anything about a placeholder code for the page number that I can put at X. (Everything would be much easier if we had a placeholder to introduce it in a string.)

OK. Now I see. I don’t need a placeholder, because the number is right there at X.
What happens now is I cannot have

   #set align(left)
   #set text(10pt)

It shows an error.

# is used in markup mode and not code mode.

Let’s leave it here. Thanks anyway.
(It obviously is markup mode. I don’t know what you mean.)

You provided a snippet from the page footer, where set rules written in the code mode block, therefore adding # is like forcing to switch to code mode that is already active. Moreover, set rules must go above a styled content. The provided link demonstraits this.

Putting the suggestions from the others together:

#set page(
  paper: "a4",
  margin: (left: 25mm, right: 70mm, top: 20mm, bottom: 28mm),
  numbering: "1",
  number-align: start,
  footer:   
    context {//Code mode
      //Configure where and how large the text should be
      set align(left)
      set text(10pt)
      
      //Values can be saved and used later (like this), or the values can be calculated in the place they are needed
      let placeholder = counter(page).display()
      
      //So far nothing has been displayed
      //The [ below starts a block of content which will be displayed
      [#placeholder - My Footer] //Within this content is some code marked by the #
   },
  footer-descent: 10% + 15pt,
)

I’ve also included some comments. Hopefully are helpful.
The above code results in a footer that looks like this:


Typst allows defining your own variables which act as placeholders. The closest documentation I know of for this is on the Scripting page. It doesn’t describe them, but does show them being used like this:

#{
  let a = [from]
  let b = [*world*]
  [hello ]
  a + [ the ] + b
}

For learning about the different modes (context, code, and math), see here:
Syntax – Typst Documentation (posted earlier by @Andrew).


There are many small things to learn at the beginning but I hope those don’t discourage you from continuing to learn Typst. And the forum is here to answer any questions you have!

1 Like