Ralph Smith Formal Script working in Typst

Note 1: This is probably mostly of interest to those in mathematical circles, as I don’t know if other scientific communities use this font.

Note 2: I don’t know if this was already built into the language, but since I couldn’t find it, I decided ot go down the rabbit hole of figuring out how to implement it using .otf files.

Because a paper I wanted to try and translate to Typst uses Ralph Smith Formal Script, with notable examples being that the roundface script S is used to denote Schwartz spaces of test functions in Distribution Theory (insert your Space Balls jokes here). While some of the letters seem to be similar to the built in

#math.scr("A")

which I assume is a built-in script font with New Computer Modern, other letters are very far off, such as Q. As such, i went down the rabbit hole of trying to get RSFS working. It wasn’t a fun task, but it’s working now.

If anyone wants to repeat the process while actually making sure the glyphs aren’t messed up, as I’m not a font specialist, you can do it by taking the Type 1 font files here and converting them to .otf files. I used Font Forge for this step.

Next, and I don’t know if this has to do with ASCII encodings, or something more esoteric, but when you place these .otf files into a directory where your Typst installation will find them, you need to use:

#text(font: "rsfs10")[ABCDEFGHIJKLMNOPQRSTUVWXYZ]

rather than the $scr("ABC")$ command to get RSFS to appear.

I’d share my .otf files here, but the upload system doesn’t allow it.

I am going to feel very foolish if these turned out to already be within the compiler, but nonetheless, if anyone gains anything from this, it’ll have been worth it.

3 Likes

Nice! I’ve also noticed that there are some glyphs that look different in typst vs TeX, but never bothered to do anything about it. Good to now have a reference :smile:

This is probably because you can’t set the font for a single variant typeface. A workaround would be

#let scr(it) = text(font: "rsfs10", it)
2 Likes

Maybe, and yeah, what I use is a custom function:

// Import Ralph Smith Formal Script, with adjustable font size based on text size
#let rscr(content) = context {
  let size = text.size
  let font = if size <= 7pt {
    "rsfs5"
  } else if size <= 10pt {
    "rsfs7" 
  } else {
    "rsfs10"
  }
  text(font: font, content)
}

followed by a bunch of shorthands:

#let scrA = rscr("A")
#let scrB = rscr("B")
...

My next task is to figure why the

#math.cal("A")

and other calligraphic fonts appear to be the Euler script (see here), as I’m more familiar with the restrained CM calligraphic (cmsy) font, for instance in the use of the Hamiltonian, with the calligraphic H. The initial outlook isn’t as good though, as a few searches have refused to cough up any font files.

1 Like

Please see How to use (old) Computer Modern for `math.cal`? And why context matters?.
(It’s somewhat off the topic, so I won’t explain it in detail in this thread)

1 Like

@Y.D.X Thank you for the reference!

Oh thank you @Y.D.X, you just saved me a load of effort, and another rabbit hole. I would never have started thinking about lookingh at the matplotlib tooling.

And @aarnent, if you do use the RSFS script, be aware that, while I haven’t encountered any problems with subscripts, superscripts and stuff like:

$rscr(N)(diameter), rscr(N)^(c)(diameter)$

have caused problems, likely due to the fact that many of the characters of RSFS occupy much of the top right corner of their block, and the .otf file isn’t actually communicating with Typst on spacing. Comparison pictures are below:

LaTeX


vs. Typst



Someone more competent is going to have to come in and fix this, as I do not understnad how to modify OTF files to fix this, unless LLMs hae enough contextual knowledge to explain this.

1 Like

Well, having spent the full morning trying to understand anything in FontForge beyond the export button, I can say I’ve failed and I cannot make sense of it, so someone else is in fact going to have to do the Unicode mapping and kerning modifications to really get this font up to scratch.