1

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

6
  • no. fonts in lualatex and pdflatex are different. You can try the unicode version of the cm, or newcomputermodern instead of the default latin modern, but they still will be different fonts. Apr 1, 2022 at 9:06
  • @UlrikeFischer How to use newcomputermodern in LuaLaTeX? I tried \newpackage{newcomputermodern} and it doesn't work. Apr 1, 2022 at 9:29
  • 1
    The command is \usepackage, not \newpackage Apr 1, 2022 at 9:35
  • Yes, it's a typo though, sorry. And \usepackage{newcomputermodern} still doesn't work. Apr 1, 2022 at 14:10
  • Please post the code what you tried as MWE...
    – MadyYuvi
    Apr 1, 2022 at 14:36

2 Answers 2

5

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.

5
  • Fyi. I tried a random document I have, and just added \usepackage{newcomputermodern} in the preamble below all the other packages I was loading. Now the command lualatex gives an compile error that makes no sense. Once I remove thi packages, the file compile OK as expected. No other changes. I have not yet tried your second method above. Will try that next. TL 2022 on Linux.
    – Nasser
    May 2, 2022 at 7:07
  • fyi, you have typo \usepackge{fontspec} should be \usepackage{fontspec} . Using \usepackage{fontspec} \setmainfont{NewCM10-Book} it compiled with no error. But using \usepackage{newcomputermodern} gives compile error.
    – Nasser
    May 2, 2022 at 7:19
  • @Nasser Thanks for the correction! Do you have the New Computer Modern package installed? The command I gave should work, but the manual actually recommends doing it through fontsetup.
    – Davislor
    May 2, 2022 at 8:18
  • What do you mean by having the package installed? Is this not part of TL 2022? The error does not say anything about package not found, but I get a compiler syntax error as it runs unrelated to anything near it. Once I comment this package, then it compiles OK. I am sure this is an error in the package itself (may be it redefines things, or clash with something else). But your second method using fontsetup worked OK. No errors. cheers.
    – Nasser
    May 2, 2022 at 8:49
  • @Nasser It’s impossible to tell what the problem might have been, without a MWE.
    – Davislor
    May 2, 2022 at 23:35
1

This can be done using the fontspec package and specifying whichever computer modern font you want in your project.


\documentclass{article}
\usepackage{lipsum}

\usepackage{fontspec}  % package for doing font stuff

% set font
\setmainfont{cmunbto}[]

\begin{document}

\lipsum

\end{document}

You can also specify separate fonts to use for italics, smallcaps, boldface, et cetera by extending the \setmainfont command:


\setmainfont{cmunbtl}[
    BoldFont        = cmunbx ,
    ItalicFont      = cmunci ,
    %SmallCapsFont   = <somefont>,
]

Abbreviations for the font names can be found in this list, but must be prefixed with cmun.

7
  • cm-unicode is in texlive, there is no need to download it from an external source. Apr 1, 2022 at 9:34
  • Oh you can! My experience is with external font files, and I had understood that part of the problem was being unable to access the regular TeX fonts from LuaLaTeX. I've simplified my reply. Apr 1, 2022 at 9:50
  • @baileythegreen Which options I could specify in the [] of \setmainfont{cmunbto}[]? Sorry I am quite new to this. Apr 1, 2022 at 11:20
  • 1
    @hmhuang, The full list of options can be found in the fontspec documentation. They are called 'font features'. At a minimum, you probably want to do BoldFont and ItalicFont, though there are also options like BoldItalicFont. The top of page 14 in that pdf shows all of them. You'll need to look at the selection of computer modern fonts and decide which one you want for each option, and find the correct abbreviation of the name. Apr 1, 2022 at 11:37
  • @baileythegreen One more question: What does cmunbto mean? I don't find it in the documentation of fontspec. Apr 1, 2022 at 14:20

You must log in to answer this question.

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