How to convert content to length

Hi,

I’d like to set text font size twice bigger or smaller than current. Something like this:

#[
  #let stampsize = (context text.size / 2)
  #set text(size: stampsize)
  //#(context text.size / 2)
]

The commented out line shows something I want, like 9pt after dividing 18pt by two. Unfortunately, there’s an error expected length, found content. Not quite surprising, because the content is probably a string, and 18pt is a literal of another type.

Is there a way to get what I want?

You can use the sizes 2em or 0.5em to get a font size that is double or half the current font size. In the example below the first and last “hello” will have the same font size, whereas the second “hello” will have twice the current font size.

hello
#set text(size: 2em)
hello
#set text(size: 0.5em)
hello

The error in your case is caused by the fact that a context always returns content. If you want to understand this, I can recommend reading this post.

1 Like