[Tex/LaTex] Difference between cfr-lm and lm package

latin-modernlm

For Latin Modern fonts, there are the packages lmodern and cfr-lm. Additionally, there are the font packages lm and lm-math. For a beginner, it is difficult to figure out the relations between these packages. The confusing thing is that lmodern documentation indirectly points to lm, but lm is "just" a font, not a thing directly being usable by \usepackage{lm}.

Best Answer

lm is a package which contains various things. Most importantly, it contains the Latin Modern fonts themselves, together with the files required to use them with TeX and friends. The fonts are provided in type1 format for use with TeX and pdfTeX, and in opentype format for use with XeTeX and LuaTeX, for example.

One element of the lm package is a set of support files for use of the type1 fonts with LaTeX or pdfLaTeX. This includes the lmodern.sty package which you use as \usepackage{lmodern}.

So far, so good.

Now, if you are using XeTeX or LuaTeX, then you may, if you wish, use lm-math which consists of an opentype maths font. unicode-math provides a means to use this. You don't have to do this - you can use the standard maths support - but you may.

If you are using TeX or pdfTeX, lm-math is irrelevant. You can't use it and you don't need it as lmodern already supports mathematics for these engines.

So far, that's all official support - or as official as it gets, anyway.

Now, if you are using TeX or pdfTeX with the type1 fonts, lmodern is somewhat limited. It supports only some of the features available in the fonts themselves. For example, it uses tabular, lining figures and, although you can access oldstyle numerals using special commands, these are still tabular and awkward to use. Moreover, there is no easy way to use italic small-caps, non-extended bold or upright italics, for example, as these are just not supported well by LaTeX by default. The variable width typewriter, the slashed zero and quotation sans are beyond reach and there is no easy, document-level command to access Latin Modern Dunhill.

For these engines, cfr-lm provides enhanced support. Insofar as possible, cfr-lm aims to provide access to everything in the fonts which might be useful through a fairly straightforward set of commands and options. cfr-lm is not just a package file, cfr-lm.sty. The bulk of cfr-lm consists of a set of TeX font files and LaTeX definition files. Essentially, these are files *.tfm, *.vf, *.fd and a new *.map file. This is all behind the scenes, though. All that matters to the end user is cfr-lm.sty and the documentation.

For example, you can pass options to the package saying whether you would prefer figures which are tabular or proportional, lining or oldstyle for each of typewriter, sans and serif. You can say which style of typewriter font you'd like. Moreover, you can switch between different styles within your document itself. For example, you can use oldstyle, proportional figures for text but switch to tabular, lining figures for a tabular.

If you don't want any of the features, use lmodern. Not only is that easier, it does not rely on virtual fonts which can be disadvantageous in some circumstances. (Don't ask me which circumstances - I haven't learnt this yet.)

If you want to use any of these features, however, cfr-lm will make life much easier. In some cases, it will make possible something which you could otherwise do only by creating the equivalent of cfr-lm yourself.

Note that cfr-lm uses just the same type1 fonts as lmodern. In addition, the support for maths is identical. cfr-lm just loads the maths support provided by lmodern. (The relevant parts of the package file are simply copied from lmodern.sty.

Note that cfr-lm will load fontenc with option T1. It will also load textcomp for access to the TS1 encoding.

Here's a sample:

cfr-lm sampler

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[rm={proportional,oldstyle},sf={proportional,oldstyle},tt={lining,tabular,monowidth}]{cfr-lm}


\begin{document}

1234567890\zeroslash (serif, oldstyle, proportional)

\textsf{1234567890\zeroslash} (sans, oldstyle, proportional)

\texttt{1234567890\zeroslash} (monowidth, tabular, lining typewriter)

\textpl{1234567890\zeroslash} (serif, proportional, lining)

\texttl{1234567890\zeroslash} (serif, tabular, lining)

\textsf{\tlstyle 1234567890\zeroslash} (sans, tabular, lining)

\textsl{This is oblique text.}

\textit{This is in regular italics.}

\textui{This text is in upright italics.}

\textsc{Here are some small-caps.}

\textsi{This is italic small-caps.}

Text weight and width (Medium)

\textsb{Text weight and width} (Bold)

\textbf{Text weight and width} (Bold Extended)

\textti{This is Latin Modern Dunhill.}

\texttt{Typewriter text.} (Monowidth)

\texttv{Typewriter text.} (Variable)
\end{document}

The documentation aims to be clear and comprehensive. If it is not, you could always try complaining to the package's maintainer.

texdoc cfr-lm