Why i need one more context inside context?

Here is a simple code example. Here I want to generate a special footer for the first page, and for all subsequent ones, there will be another one.

#set page(
  width: 10cm,
  height: 10cm
)

// context inside context
#let temp1(body) = context {
  set page(footer:  context if here().page() == 1 {
    [ First page footer ] 
  } else {
    [ Other pages footer ] 
  })
  
  body
}

// context
#let temp2(body) = context {
  set page(footer:  if here().page() == 1 {
    [ First page footer ] 
  } else { 
    [ Other pages footer]
  })
  
  body
}

// #temp1()[#lorem(250)]
// #temp2()[#lorem(250)]

If I use the first function, the footers will be correctly generated on the page based on my rule, but if I use the second function, it won’t work that way. Although all calculations still take place inside the context.

Is this a bug or I just don’t understand how to use it properly?

1 Like

This is because context is content, and temp2’s content is only used/placed once at call site. While page.footer’s content is placed once per page. Hence, you must give a fresh/updated context on every page, i.e., use context in page.footer.

#set page(width: 10cm, height: 10cm)

#let temp(body) = {
  set page(footer: context {
    if here().page() == 1 [First page footer] else [Other pages footer]
  })

  body
}

#temp[
  #lorem(250)
]
3 Likes