How to display a symbol within a verbatim string?

Typst allows you to display multiple letters verbatim in mathematical formulas using quotes. For example:

$1 "ms"$

The example above will display ms in an upright style to denote millisecond units, as opposed to displaying in italics which would incorrectly denote “m times s”.

Similarly, I would like to display μs to denote microsecond units. However, there does not appear to be a way to use named symbols1 within quotes.

I can think of three ways to achieve this:

  1. Search for the symbol online and copy and paste it manually:

    $1 "μs"$
    
  2. Use the upright3 function (this removes the leading space, which is undesirable):

    $1 upright(mu s)$
    
  3. Define a variable:

    #let mus = sym.mu + "s"
    $1 mus$
    

Is there a better way to do this that I’m unaware of?


1 https://typst.app/docs/reference/symbols/sym/2
2 New forum accounts are not allowed to include more than 2 links in a single post, so I am using footnotes as a workaround.
3 https://typst.app/docs/reference/math/styles/#functions-upright

Because nothing can be used within string literals. Convenient string formatting · Issue #2267 · typst/typst · GitHub

The most straightforward way is to use code mode:

$#(sym.mu + "s")$

Or

#import sym: *
$#(mu + "s")$

Which is basically the same thing as string interpolation by width:

$#(mu+"s")$

$"#{mu}s"$
1 Like