Skip to content

How to add text background-color? #845

Closed Answered by PgBiel
dsantiago asked this question in Q&A
Discussion options

You must be logged in to vote

Oh, I see what you mean - you want background that adjusts to the text. Right now this isn't natively supported, but here's a rough hack:

#[
   #show regex("\\w+|[^\\s]"): box.with(fill: red)
   #show " ": box.with(fill: red, width: 2pt)
   #lorem(30)
]

(Places every word - or, otherwise, character - in an individually filled box, with a special case for space (a box with just a space and auto width is automatically collapsed))

This should get better in the future - please open a feature request issue for this.

Replies: 4 comments 8 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@PgBiel
Comment options

PgBiel Apr 17, 2023
Collaborator

Answer selected by dsantiago
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
7 replies
@PgBiel
Comment options

PgBiel Apr 17, 2023
Collaborator

@SylvanFranklin
Comment options

@PgBiel
Comment options

PgBiel Dec 19, 2024
Collaborator

@SylvanFranklin
Comment options

@PgBiel
Comment options

PgBiel Dec 20, 2024
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants