How to measure content including leading/trailing whitespace?

I need to typeset a paragraph like the following. For that I need to set hanging-indent to the width of "Advisors: ", space included.

Advisors: Ph.D Very Long Name
          Ph.D Another Very Long Name

The problem is: measure ignores any space width — be it a normal or non-breakable space. So the above turns out like:

Advisors: Ph.D Very Long Name
         Ph.D Another Very Long Name

This is contrary to the norms of my institution… Below is the code I’m using. I also tried to add + measure(sym.space.nobreak).width in the padding attribution, but it changes nothing.

context {
  let prefix = [Advisors:~]
  let padding = measure(prefix).width
  let body = par(hanging-indent: padding, {
    prefix + advisors.join(linebreak()) // advisors is an array of names
  })
}

Am I missing something? Thank you in advance!

A grid (or, for simpler cases, stack) is ideal for this use case, and does all the measuring magic for you:

#let advisors = ([Phil Phil], [John John])
#grid(
  columns: 2, column-gutter: 4pt,
  [*Advisors:*], advisors.join([\ ])
)

For more information, see:

  1. Grid Function – Typst Documentation
  2. Table guide – Typst Documentation (also applies to grids)
1 Like

Less ideal and also less automated/magical solution (but less bulky):

#let prefix = [Advisors:]
#prefix Ph.D Very Long Name \
#hide(prefix) Ph.D Another Very Long Name

image

1 Like

Thank you, @Andrew ! Using hide here as you suggested solves only the start of lines, but if one of the names wrap, it doesn’t get a hanging indent. But thanks anyway, I wasn’t aware of this way :slight_smile: