How do I add a custom math font / MLModern

Hello, everyone.

I like a lot the New Computer Modern/Latin Modern variant called MLModern, that was available in LaTeX under the package mlmodern. It has thicker glyphs to enhance readability and comprises the whole set of math symbols.

What I have done so far

The original package from CTAN has various files, but the relevant ones are *.pfb files, i.e. type1 files. Since typst supports .ttf/.otf files, I’ve converted all the type1 files to .ttf using the script from this Reddit post. When I upload the converted .ttf files to typst, I am able to use the fonts in text using

#set text(font: "MLMRoman10")

but (A) I am not sure it is using correctly also the bold and italic variants, and (B) the same does not work for the math variants:

#show math.equation: set text(font: "MLMMathSymbols10")

the compiler gives an error when I try to use math:

This markup in “main.typ”…
$x^2$
…caused this problem:
Current font does not support math.

Type1 files

There are files for different styles and sizes (ranging from 5pt to 17pt depending on the style). Stripping the mlm prefix and <size>.pfb suffix, these are the font filenames: b, bx, csc, duno, mib, ro, ssbx, sso, tcso, tl, tlo, tto, vtko, vtt, bo, bxi, csco, ex, r, ss, ssdc, sy, tk, tlc, tt, u, vtl, vtto, bsy, bxo, dunh, mi, ri, ssbo, ssdo, tcsc, tko, tlco, tti, vtk, vtlo.

I don’t know what math fonts typst supports and which font files should be merged together (if a single file is needed) nor do I know how to do that preserving math properties. I suspect that, in the conversion from type1 to truetype, the MATH table has not been converted properly. Please help me find some leads.

Thank you all

  1. For math font choice,

    #show math.equation: set text(font: "MLMMathSymbols10")
    

    is correct.

    However, Typst only accepts fonts with OTF Math support, so you probably need to figure out a way to create the relevant OTF tables in your conversion.

  2. Combining files: for the math font, I think it should be one file, as the e.g. bold math letters are different unicode and OTF math variants, and not a bold variant of the font.

    For the regular font, typst can handle fonts being split across multiple files, but it doesn’t always piece them together correctly. Especially for fonts with many variants, it sometimes does’t “merge” them all. You can find out more in the web-app by hovering over the font name in the set-rule, it will show you how many variants and weights it found.

    It might help to use more standard font names (-Bold.ttf, -BoldItalic.ttf, -SemiBold.ttf,…), but honestly I’m not sure how it determines that multiple files belong to one font.

    (Interestingly, this is not the same always in the web app vs locally, I have fonts where the web app has the condensed version as its own font-family (“[name] Condensed”), but locally its one font family with different stretch…)

1 Like

The following might be useful in figuring out the MATH tables:

(Worst case, how to build it by hand, but also how to find the relevant data in font-editing software, so you could check if the tables have been converted or not in the first place)

1 Like

Hey,
I would say that the previous poster is on the right track. I can only advise to try and fix the font for export using fontforge directly instead of automatically converting from a script. The GUI will help you fix some issues for ttf/otf export.

1 Like

Thanks everyone for your responses.

Unfortunately, for me it’s not worth the effort and I doubt that anyone will do it from the time being.