#Can you set custom attrs on an element?

19 messages · Page 1 of 1 (latest)

stuck quest
#

https://typst.app/project/pjAv5m0LMLux9HwsYyUU_J#

In this example, I am querying for headings.

Unfortunately, the heading generated via outline() is being included in the query.

Hence, why one of the chapter titles in the upper right footer says, "Contents".

I was wondering if there's a way to attach custom metadata to elements. This way, when I do the query for headings, I can specify the metadata to just get specific ones I am looking for.

empty rover
#

Failed to initialize: You do not have sufficient permissions to access this project.
I assume this project isn't publicly accessible

#

It would be simpler if you made a minimal example that you posted here to illustrate your point

stuck quest
#

it should be readable now. sorry about that

ancient monolith
#

you can't add custom properties, but maybe where(outlined: true) is sufficient?

#

alternatively, you can insert #metadata(none) <main> and then use after(<main>) in your queries, to filter by location instead of by metadata

empty rover
#

Here is the code I have been using for headers:

#

?r ```
#let last-hd = state("body", [])
#set page(
header: context {
set text(size:12pt,hyphenate:false)
let first-heading = query(
heading.where(level: 1)
).find(h => h.location().page() == here().page())
let last-heading = query(
heading.where(level: 1)
).rev(
).find(h => h.location().page() == here().page())

let header = if not first-heading == none {
  first-heading.body
  last-hd.update(last-heading.body)
} else {
  last-hd.display()
}

let n = counter(page).get().first()
if (n > 1) {
  align(center, header)
}  

}
)

#let section(title: none) = {
if title != none {
heading(title)
}
lorem(10)
pagebreak()
}

#{
outline()
pagebreak()
text("instead of saying 'contents', it should say first chapter too", size: 25pt, fill: red)
section(title: "first chapter")
section()
section()
section(title: "second chapter")
section()
}

empty rover
#

It's a bit more convoluted, but it consistently gets the last heading, or the first heading of the current page if there is one

ancient monolith
#

(there's also hydra, btw, but I'm not sure if it does exactly what you both want)

stuck quest
#

As an addendum, for the outline, would it be possible not just to specify where the page starts, but the entire range of the chapter? ie instead of chapter 1 -- page 3, to say say chapter 1 -- page 3 to page 5

ancient monolith
#

manually, sure. just find the next chapter, and subtract one from the page number

empty rover
#

?r ```
#show outline.entry: it => context {
let first-page = counter(page).at(it.element.location()).at(0)
let next-heading = query(selector(heading).after(it.element.location()))
let next-heading = next-heading.at(1, default: none)
let last-page = if (next-heading == none) {counter(page).final().at(0)} else {counter(page).at(next-heading.location()).at(0) - 1}
[#it.body #box(width:1fr, repeat[.]) #first-page;--#last-page]
}

#let section(title: none) = {
if title != none {
heading(title)
}
lorem(10)
pagebreak()
}

#{
outline()
pagebreak()
text("instead of saying 'contents', it should say first chapter too", size: 25pt, fill: red)
section(title: "first chapter")
section()
section()
section(title: "second chapter")
section()
}

empty rover