Use Computer Modern Font in LuaLaTeX

computer-modernfontsluatex

I was a pdfLatex user until I encountered a LaTeX capacity issue because of a large amount of figures included in my thesis. I am now using LuaLaTeX which dynamically allocates the memory and it solves the above issue.

But now another issue comes up: The fonts of all chapters, sections, subsections, subsubsections' titles are changed. I would like to keep using the Computer Modern fonts (see below image) as I had with pdfLaTeX for them. Is there an easy way/workaround to do this trick in LuaLaTeX? If possible, I would like to use the font family that comes with pdfLaTeX in LuaLaTeX.

  • Computer Modern fonts in pdfLaTex:
    enter image description here

  • Different fonts in LuaLaTex:
    enter image description here

Best Answer

By default, LuaLaTeX uses a clone of Computer Modern, by the name of Latin Modern Roman. Either your document class or some package you are using changes the font, but you do not give us enough information to tell which. If it is one of the Koma-script classes, you will likely want to turn off sans-serif titles.

The simplest way to change the main font to a clone of Computer Modern is

\usepackage{newcomputermodern}

This loads a slightly-heavier weight, and both text and math fonts. To get the original weight, you can use

\usepackage[regular]{newcomputermodern}

Other alternatives include loading fontsetup, and changing the main font with \usepackage{fontspec}. There are four OpenType versions of Computer Modern that ship with TeX distributions:

\setmainfont{NewCM10-Regular} % New Computer Modern 10

\setmainfont{NewCM10-Book} % Slightly heavier.

\setmainfont{Latin Modern Roman}

\setmainfont{CMU Serif} % Computer Modern Unicode

For any font in your TeX tree, you want to search for a .sty or .fontspec file that sets everything up properly, and load that. For example, \usepackage{newcomputermodern} loads newcomputermodern.sty, and \setmainfont{NewCM10-Regular} loads the commands in NewCM10-Regular.fontspec.

If you are not sure which to use, New Computer Modern has the most symbols and bug fixes, Computer Modern Unicode has the most typefaces, and Latin Modern has the best set of optical sizes.