How do I draw a box behind text?

I suggest simply using outset for the y-axis, this will leave the baseline unaffected:

#let part(content, angle: 0deg, content_color: black) = {
  box(
    radius: 0.1em, 
    stroke: (2pt + oklch(40%, 0.2, angle, 100%)), 
    fill: oklch(95%, 0.05, angle, 80%), 
    inset: (x: 0.3em),
    outset: (y: 0.3em),
  )[#text(content_color)[#content]]
}

x-inset + y-outset is the go-to style for inline raw in most of my documents and it served me pretty well.

I think this also has the added benefit of not affecting line spacing, in case the baseline option does, I’m not 100% sure about that. But this also means for tight line spacing this will intersect with the other lines.

4 Likes