I'd like to typeset a document in MLModern's fonts (serif, sans serif, teletype, etc.), then later change the teletype font to a different custom font whose TTF I provide (Iosevka, in the example below). This is my attempt at doing it using fontspec, compiling with LuaLaTex:



This should be in MLModern's roman font.

\texttt{This should be in MLModern's teletype font.}

\texttt{This should be in Iosevka.}

Having loaded the mlmodern package, I expected the default font to be MLModern, but the first line seems to be in Latin Modern instead. Curiously, the second line is also in roman and not teletype. (Third line is fine.)

If I try to set the main font to MLModern with the commented out line above, compilation doesn't succeed:

This is LuaHBTeX, Version 1.13.2 (TeX Live 2021/Arch Linux) 
 restricted system commands enabled.
LaTeX2e <2021-11-15> patch level 1
 L3 programming layer <2021-11-22>
Document Class: article 2021/10/04 v1.4n Standard LaTeX document class

LaTeX Font Warning: Font shape `TU/mlmr/m/n' undefined
(Font)              using `TU/lmr/m/n' instead on input line 7.

(./main.aux) (/usr/share/texmf-dist/tex/latex/base/ts1cmr.fd)
luaotfload | db : Reload initiated (formats: otf,ttf,ttc); reason: Font "MLModern" not found.

Other names I've tried are mlmodern and mlm, with the same result. How do I set the main font to MLModern then?


1 Answer 1


(EDIT 1: In an earlier version of this answer, I said to use 'OT1' as the option to fontenc; I now think you can use T1 or OT1; you just need to put the packages in the right order...)

Apparently you need to load the packages in a certain order.

The following works for me (– I don't have Iosevka installed right now so I substituted Cousine –):



This should be in MLModern's roman font.

\texttt{This should be in MLModern's teletype font.}

\texttt{This should be in Cousine.}

fontspec needs to go first.

(Apparently it's not supposed to be necessary to load fontenc at all with lualatex: see here, but actually in this case, it seems to help because it looks for a TU encoded font first otherwise.)

EDIT 2: I came up with this answer by trial and error, not deep knowledge of best practices. For reasons Ulrike Fischer mentions in the comments to this answer, this may not be a great idea. You may encounter problems.

I haven't found any problems with hyphens, but you may.

For non-ascii characters, some of them work, some of them don't, but in my testing, the ascii LaTeX commands to produce non-ascii characters do generally work. For example, inserting ß directly doesn't work, but \ss does; using directly doesn't work, but \ldots does and so on. How big a problem this is obviously depends on your use case. But I find that even with the non-ascii characters, it works to load the newunicodechar package and issue commands such as these at the end of the preamble:

% and so on

This allows me to use the non-ascii characters in my source. But my testing of this is not exhaustive, so use this answer with caution.

  • this is wrong. You are setting the wrong encoding for luatex and will run into problems with hyphenation and non-ascii chars. See here why you shouldn't set T1 for lualatex: tex.stackexchange.com/a/470987/2388 Commented Mar 16, 2022 at 9:02
  • 1
    The font defaults to Latin Modern if I exclude using fontenc though, how am I supposed to make it pick MLModern instead?
    – ionchy
    Commented Mar 17, 2022 at 18:36
  • @UlrikeFischer I knew my first answer wasn't right almost as soon as it was accepted as correct, and I'm not at all surprised this isn't quite right either. So I've added an edit with some more information. I'd be delighted to change my answer even more to make it more correct, but I don't know of a better answer that would allow one to achieve the desired effect, and this might "work" for some use cases even if it isn't fully advisable.
    – frabjous
    Commented Mar 18, 2022 at 3:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .