Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Individual footnote formatting and omission of footnote reference #5630

Open
chrarnold opened this issue Dec 27, 2024 · 1 comment
Open

Individual footnote formatting and omission of footnote reference #5630

chrarnold opened this issue Dec 27, 2024 · 1 comment
Labels
feature request New feature or request

Comments

@chrarnold
Copy link

Description

I am wondering whether the following is possible with typst, whoever is smart and experienced with typst: help is very appreciated!

  1. Format each footnote individually: I need a different background color and transparency value for the text for each footnote entry. I couldn't find examples of this in the Docs, not sure that's possible?
  2. I want the footnote numbering to NOT be printed, neither in the text where the footnote is created and referenced, nor in the footnote footer.

You may ask why I want that, and I admit it is a bit of a special case. I basically want to highlight particular sections of text with a background color on each page, and for each highlighted section, a footnote entry should be present with the same background color to visually match the main text. I then don't want and need the footnote numbering and therefore want to omit it.

Thank you!

Use Case

My 2 mentioned issues can be useful when having special requirements as outlined above.

@chrarnold chrarnold added the feature request New feature or request label Dec 27, 2024
@Fevol
Copy link

Fevol commented Dec 27, 2024

Hi, I am guessing this is somewhat what you want? Though, you won't be able to style individual footnotes (well, not easily).

Code: Override footnote behaviour
#set page(height: 200pt)
#let determine-highlight(location, body) = context {
    let footnote-counter = counter(footnote).at(location).first()
    let fill = none
    let transparency = none
    let rem = calc.rem(footnote-counter, 5)
    if rem == 1 {
        fill = blue
        transparency = 90%
    } else if rem == 2 {
        fill = green
        transparency = 70%
    } else if rem == 3 {
        fill = yellow
        transparency = 50%
    } else {
        fill = red
        transparency = 30%
    }

    highlight(fill: fill.transparentize(transparency), extent: 2pt, body) 
}

#show footnote: it => {
    set text(weight: 900)
    determine-highlight(it.location(), it.body)
}

#show footnote.entry: it => {
    determine-highlight(it.note.location(), it.note.body)
}


#lorem(5)
#footnote[Highlight one]

#lorem(5)
#footnote[Highlight two]

#lorem(5)
#footnote[Highlight three]

#lorem(5)
#footnote[Highlight four]

Which produces the following output:
image


However, instead of hijacking the footnote rendering to add highlights, it'd be much better (and easier!) to define your own function which places your highlights anywhere on the page. Specifically, the highlights are added to the footer here, but with place + page: foreground, you could place them anywhere you want.

This makes it much easier to customize the styling for each individual highlight.

I'm personally not entirely confident about the way I wrote the page highlights filtering code (query(selector(<showcase-highlight>).before(here())), perhaps someone else can chime in to offer a better alternative.

If this was indeed your question, maybe it'd be interesting to continue discussing this on the forum or in the Discord?

Code: Custom highlight rendering
#set page(height: 80pt)
#let highlight-item(fill: red, body) = [#highlight(fill: fill, extent: 2pt, body) <showcase-highlight>]

#set page(footer-descent: -4pt, footer: context {
    let all-highlights = query(selector(<showcase-highlight>).before(here()))
    let highlights-on-page = all-highlights.filter(it => it.location().page() == here().page())

    set text(size: 0.8em) // Apply custom styling to the highlights in the 'footnote'
    highlights-on-page
        .map(it => link(it.location(), it)) // Additional example:  link back to the highlight in the text
        .join(h(1em))
})

#lorem(5)
#highlight-item(fill: blue.transparentize(90%))[Highlight one]

#lorem(5)
#highlight-item(fill: green.transparentize(70%))[Highlight two]

#lorem(5)
#highlight-item(fill: yellow.transparentize(50%))[Highlight three]

#lorem(5)
#highlight-item(fill: red.transparentize(30%))[Highlight four]

#lorem(5)
#highlight-item(fill: purple.transparentize(10%))[Highlight five]

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants