What's the best way to duplicate content with different styling?

I have two different PDF outputs for my project, and I want to share some content between them. In one, I can show some cute inline boxes and colors and things, but the other is just black text on white bg.

Since the styling I want to change is all wrapped in a few custom functions, I was hoping I could do like a show rule for them but I’m told you can only show the standard library functions.

Minimal example:

// template.typ
#let funny-style = content => box(fill: red, content)
// main1.typ

#let get-content = () => [*Wow* that's some #funny-style[funny text]]

#get-content()
// main2.typ

show funny-style: content => content

#get-content() // wow should be bold but funny text should be nothing

In real life I have a few of those functions doing different things involving boxes and colors so I’m hoping for a general solution.

My idea so far is to push the responsibility down to all the functions that need to care and use context to figure out who’s calling it, maybe using metadata? Though I don’t have much experience with metadata and don’t want to go down that road if there’s an easier way.

Turns out using the metadata was pretty easy.

#metadata("main1") <entrypoint>

#let funny-style = content => {
  if query(<entrypoint>).first().value == "main1" {
    box(fill: red, content)  
  } else {
    content
  }
}

Happy to see alternate solutions but it looks like this will work for me.

1 Like