How to specify custom underline strokes based on default stroke thickness?

Ah I understand now, sorry for the confusion.

Indeed if you pass a troke to the underline function, the thickness default is based on the font thickness, or defaulted to 0.06em.

Because this value is based on the actual font you are using (i.e. some fonts will set it to different values), the pt/em value is not exposed through typst.

You can, however, use the string “dot” for a length equal to the line thickness in stroke, so something like this would work:

#underline(stroke: stroke(
  // works
  dash: ("dot", 7pt)
),)[#lorem(10)]

Downside with this is that you can’t set it to 0.7 times the thickness, so this wouldn’t work

#underline(stroke: stroke(
  // does not work
  dash: ("dot",  0.7 * "dot")
),)[#lorem(10)]

It seems the best way to achieve “relative thickness” would be through trial and error, or by exploring the .otf themselves. Maybe somebody else knows a better solution.

1 Like