#type array has no method "location"

8 messages · Page 1 of 1 (latest)

scarlet iris
#

I've been using the following line of code to generate a header for my Typst document:

(#counter(heading).at(last-heading.location()).at(0)) #upper[#last-heading.body]

However, it seems like this code is no longer working as expected. I'm wondering if there might be a small bug in my code, or if there have been changes to the location() function.

According to the documentation, it states that location "is only available on content returned by query or provided by a show rule, for other content it will be none."

For context, here's my full code snippet:

let previous-heading = state("page-first-section", [])

set page(
    header: locate(
      loc => [
        #let pageNumber = loc.page()
        // find the last heading of level 1 on the current page
        #let last-heading = query(
          heading.where(level: 1), loc)
          .rev()
          .find(h => h.location().page() == loc.page())
        #{ 
          if calc.even(pageNumber) {
            align(left, text(font: "New Computer Modern", size: 12pt, style: "italic")[#previous-heading.display()]) 
          }
          if not last-heading == none { 
            previous-heading.update([ 
              (#counter(heading).at(last-heading.location()).at(0)) #upper[#last-heading.body]
            ]) 
          } 
        }
        #line(
          length: 100%,
          stroke: 0.4pt
        )
      ]
    )
  )
frank crypt
#

Into the document

#

This changed in 0.8.0

#

You need to place them in the same line or use something like

#let x = {
some
.thing()
}

#

(Cc @simple summit in case there’s something I’m missing)

simple summit
#

That's correct, the original parsing behaviour was unintended.

#

In this case, it would probably be easiest to just use a code block for the whole thing. Something like this:

#let previous-heading = state("page-first-section", [])
#set page(header: locate(loc => {
  let pageNumber = loc.page()
  // find the last heading of level 1 on the current page
  let last-heading = query(heading.where(level: 1), loc)
    .rev()
    .find(h => h.location().page() == loc.page())
    
  if calc.even(pageNumber) {
    align(left, text(font: "New Computer Modern", size: 12pt, style: "italic")[#previous-heading.display()]) 
  }
  
  if last-heading != none { 
    previous-heading.update([ 
      (#counter(heading).at(last-heading.location()).at(0)) #upper[#last-heading.body]
    ]) 
  } 
  
  line(
    length: 100%,
    stroke: 0.4pt
  )
}))