How to know the length of a space?

I’ve tried to use the measure contextual function, but it seems to not work as I expected. I’ve tried to use the h function inside measure to test that it retrieves the measurement passed to h but does not.

I want to know the length of the spaces available in sym module, for example: sym.space.thin. However, I was trying to find a space of 0.6 em. By the way, the measure function retrieves the measurement in pt, not in em.

Any help, please.

indeed, measure() returns values in terms of absolute (pt) rather than relative (em) lengths. this is probably desirable for most use cases. what you can do is obtain the current value of 1em as converted to pt (which is just the current font size!), and use this conversion factor to convert pt back to em. this of course also requires context. something like this:

#let pt-per-em = 1em.to-absolute() // equivalently: text.size
#let width = measure(...).width
#let width-em = width / pt-per-em
#width.pt() pt is equal to #width-em em.

i think it might make sense to have a contextual .to-relative() method on length? but not sure how useful it would be.


here’s a little demo of (some) spaces and their widths :p, last column assuming 1em = 11pt.

source code
#set page(width: auto, height: auto, margin: 20pt)
#context grid(columns: 2, gutter: 5pt, align: right,
  ..for variant in ("quad", "en", "fig", "third", "quarter", "med", "punct", "sixth", "narrow", "thin") {
      let pt-per-em = (1em).to-absolute()
      let width = measure(eval("sym.space." + variant)).width
      (strong(variant), [#width.pt() pt $=$ #(width / pt-per-em) em])
  }
)
4 Likes

Note that the size of the sym spaces is dependent on the font.

If you want a space of exactly 0.6em, you should use #h(0.6em);.

3 Likes