3

How do I switch from the default Computer Modern for text and math to Latin Modern for text and Latin Modern Math for math?

In the preamble I put \usepackage{lmodern} to switch to Latin Modern for text. But what should I add to the preamble so that the document uses Latin Modern Math for math?

The Latin Modern Math download page seems to be for downloading the font for use with MS Word or Adobe or something.

3 Answers3

5

If you use pdflatex, then just

\usepackage{lmodern}

will completely replace Computer Modern with Latin Modern for text and math, because its code is

\ProvidesPackage{lmodern}[2015/05/01 v1.6.1 Latin Modern Fonts]

\renewcommand{\rmdefault}{lmr} \renewcommand{\sfdefault}{lmss} \renewcommand{\ttdefault}{lmtt}

\DeclareOption{nomath}{\endinput} \DeclareOption{variablett}{% \renewcommand{\ttdefault}{lmvtt} } \DeclareOption{lighttt}{% \let\lmtt@use@light@as@normal@empty } \ProcessOptions\relax

\SetSymbolFont{operators} {normal}{OT1}{lmr} {m}{n} \SetSymbolFont{letters} {normal}{OML}{lmm} {m}{it} \SetSymbolFont{symbols} {normal}{OMS}{lmsy}{m}{n} \SetSymbolFont{largesymbols}{normal}{OMX}{lmex}{m}{n} \SetSymbolFont{operators} {bold} {OT1}{lmr} {bx}{n} \SetSymbolFont{letters} {bold} {OML}{lmm} {b}{it} \SetSymbolFont{symbols} {bold} {OMS}{lmsy}{b}{n} \SetSymbolFont{largesymbols}{bold} {OMX}{lmex}{m}{n}

\SetMathAlphabet{\mathbf}{normal}{OT1}{lmr}{bx}{n} \SetMathAlphabet{\mathsf}{normal}{OT1}{lmss}{m}{n} \SetMathAlphabet{\mathit}{normal}{OT1}{lmr}{m}{it} \SetMathAlphabet{\mathtt}{normal}{OT1}{lmtt}{m}{n} \SetMathAlphabet{\mathbf}{bold} {OT1}{lmr}{bx}{n} \SetMathAlphabet{\mathsf}{bold} {OT1}{lmss}{bx}{n} \SetMathAlphabet{\mathit}{bold} {OT1}{lmr}{bx}{it} \SetMathAlphabet{\mathtt}{bold} {OT1}{lmtt}{m}{n}

\def\mathsterling{\mathit{\mathchar"70BF}}

However, when used in combination with amsmath it has a problem: with amsmath (and no font package), the largesymbols font is scalable, but with lmodern it becomes fixed size.

Minimal example:

\documentclass{article}
\usepackage{amsmath}
%\usepackage{lmodern}

\begin{document}

[ X_{\sum_i a_i} ]

\end{document}

enter image description here

If you uncomment the \usepackage{lmodern} line you get

enter image description here

which is unacceptable. The usage of a fixed font size for largesymbols has other nasty consequences, so I recommend adding \usepackage{fixcmex} (that was written exactly for solving this problem). It will revert the largesymbols font to Computer Modern, precisely cmex10 and other sizes, but lmex10 is a straightforward copy if cmex10, so there will be essentially no difference.

\documentclass{article}
\usepackage{amsmath}
\usepackage{lmodern}
\usepackage{fixcmex}

\begin{document}

[ X_{\sum_i a_i} ]

\end{document}

Don't load lmodern if you're using XeLaTeX or LuaLaTeX. If you use these engines, the default font is Latin Modern (with Computer Modern for math) even if you don't load fontspec; loading also unicode-math will use Latin Modern Math.

egreg
  • 1,121,712
2

If you want to use the actual font named Latin Modern Math, which is an OpenType font, you need LuaLaTeX or XeLaTeX. Add

\usepackage{unicode-math}

You do not need any other commands or packages. You can, if you feel like it, additionally set

\setmainfont{Latin Modern Roman}
\setsansfont{Latin Modern Sans}
\setmonofont{Latin Modern Mono}
\setmathfont{Latin Modern Math}

However, these are already the default in unicode-math.

You do not need to use lmodern, or any other legacy 8-bit font package, along with unicode-math. All they will do is waste a very tiny amount of time.

Davislor
  • 44,045
1

Here there is a minimal working example in XeLaTeX and LuaLaTeX. You can see the \mathcal and \mathbb are differents from by default of CM.

\documentclass[12pt]{article}
\usepackage{unicode-math}
\defaultfontfeatures{Scale=MatchLowercase}
\setmathfont{Latin Modern Math}[version=lm]
\begin{document}
This is a short formula
\[abc\sum_{i=0}^Na_i=\mathcal{C}\mathbb{R}\]
\end{document}

enter image description here

Addendum:

In this link you can see the union between Latin modern text and math.

https://tug.org/FontCatalogue/latinmodernroman/

Sebastiano
  • 54,118