[Tex/LaTex] Best way of using the full range of full fonts/styles/faces for Latin Modern Roman

computer-modernfontsfontspeclatin-modern

The following is what I've put together as a way of making sure the full(est) range of fonts/styles are available when using Latin Modern as the mainfont using fontspec, including bold smallcaps, italics smallcaps, etc.:

\setmainfont[
    SmallCapsFont={Latin Modern Roman Caps},
    SlantedFont={* Slanted},
    ItalicFeatures  = {
        SmallCapsFont = {LMRomanCaps10-Oblique}
      },
    BoldFeatures = {
      SmallCapsFont = {CMU Serif-Bold},
      Letters=SmallCaps
      }    
    ]{Latin Modern Roman}

(Slightly cheating because it uses Computer Modern Unicode for the bold smallcaps.)

Is this reasonable, or is there a better way?

Full minimal example:

\documentclass{article}[12pt]

\usepackage[T1]{fontenc}
\usepackage{fix-cm}
\usepackage{fontspec}
\defaultfontfeatures{Renderer=Full,Ligatures=TeX,Numbers=OldStyle,Scale=MatchLowercase}
\setmainfont[
    SmallCapsFont={Latin Modern Roman Caps},
    SlantedFont={* Slanted},
    ItalicFeatures  = {
    SmallCapsFont = {LMRomanCaps10-Oblique}
      },
    BoldFeatures = {
      SmallCapsFont = {CMU Serif-Bold},
      Letters=SmallCaps
      }    
      ]{Latin Modern Roman}
\begin{document}

\begin{tabular}{ll}
  Plain roman & Hello, world.\\
  Bold roman & \textbf{Hello, world.}\\
  Italics & \textit{Hello, world.}\\
  Bold italics & \textit{\textbf{Hello, world.}}\\
  Plain smallcaps & \textsc{Hello, world.}\\
  Bold smallcaps & \textbf{\textsc{Hello, world.}}\\
  Italics smallcaps & \textit{\textsc{Hello, world.}}\\
  Bold italic small caps & \textit{\textbf{\textsc{Hello, world.}}} [doesn't work]\\
&\textbf{\textit{\textsc{Hello, world.}}} [doesn't work]\\
  Typewriter & \texttt{Hello, world.}\\
  Italic typewriter & \textit{\texttt{Hello, world.}}\\
  Bold typewriter & \textbf{\texttt{Hello, world.}}\\
  Bold italic typewriter & \textit{\textbf{\texttt{Hello, world.}}}\\
  Slanted & \textsl{Hello, world.}\\
  Bold slanted & \textbf{\textsl{Hello, world.}}\\
\end{tabular}

\end{document}

output of above

The bold, italics, smallcaps combos don't work (I don't know that I ever need that combination anyway), and I do get some warnings:

Package fontspec Warning: OpenType feature 'Letters=SmallCaps' (smcp) not
(fontspec)                available for font 'Latin Modern Roman/B' with
(fontspec)                script 'Latin' and language 'Default'.

(./test5.aux)

LaTeX Font Warning: Font shape `TU/lmtt/bx/it' in size <10> not available
(Font)              Font shape `TU/lmtt/b/sl' tried instead on input line 38.

Is there any better way of setting up Latin Modern with fontspec?

[Edit: To make the goal explicit, I'm looking for the widest character coverage, the widest face/style coverage, with the best rendering (ranking in order of importance) while using the Latin/Computer Modern family of typefaces.]

Best Answer

You’re off to a good start, but that doesn’t even scratch the surface of all the typefaces in the Computer Modern family. If you see Appendix A of “The LaTeX Font Installation Guide”, which expands on a scheme in The LaTeX Companion, there are official, standardized names for many more widths, weights and shapes. Several are present in Latin Modern, Computer Modern Unicode, or both.

For reference, here are the full lists of fonts in the Latin Modern collection and in the Computer Modern Unicode collection. There is also, of course, Latin Modern Math to replace the math and math symbol fonts. The program otfinfo (which works on the .ttf fonts from CMU as well) is useful to see which CMU fonts contain small-caps.

Of the extra faces in Latin Modern, I treat Demi as an additional weight, which I call sb (because sb is the only weight between m and b in the second edition of The LaTeX Companion.), and Unslanted as an additional shape, ui. I add the commands \sbseries and \textsb corresponding to \bfseries and \texbf, and \uishape and \textui corresponding to \itshape and \textit. You can use these as templates to add any other series or shape.

If you want to be able to set the font weight and extent separately, so that you can select bold in the middle of a block of Latin Modern Sans Cond, you might want to check out the package nfssext-cfr for inspiration.

Both Latin Modern and the Computer Modern Unicode fonts include several other families. Of these, CMU Concrete is a conversion of a completely different font originally commissioned for DEK’s book, Concrete Mathematics. I also treat Latin Modern Roman Dunhill and CMU Classical Serif as different families. It might, however, make sense to treat CMU Bright as a lighter weight of the sans-serif font.

CMU contains one series not present in Latin Modern: bold non-extended. For these purposes, I’ll give it the series bc, for bold condensed. It does not come with either italic, slanted or small caps. Other than that, I use some of its bold small-caps.

Here’s a sample for just the Latin Modern Roman family.

\documentclass[varwidth]{standalone}
\usepackage{amsmath}
\usepackage{unicode-math}
\usepackage{microtype}

\defaultfontfeatures{ Scale = MatchUppercase }

\setmainfont{Latin Modern Roman}[
  Scale = 1.0 ,
  Ligatures = {Common, Rare, TeX} ,
  UprightFont = {Latin Modern Roman} ,
  UprightFeatures = {
    Ligatures = Discretionary ,
    SmallCapsFeatures = { Ligatures = ResetAll } ,
    SmallCapsFont = {lmromancaps10-regular.otf}
  } ,
  BoldFeatures = {
    Ligatures = Discretionary ,
    SmallCapsFeatures = {Letters = SmallCaps } ,
    SmallCapsFont = {CMU Serif Bold}
  } ,
  ItalicFeatures = {
    Ligatures = Discretionary ,
    SmallCapsFeatures = { Ligatures = ResetAll } ,
    SmallCapsFont = lmromancaps10-oblique.otf
  } ,
  BoldItalicFeatures = {
    Ligatures = Discretionary ,
    SmallCapsFeatures = { % Ligatures = ResetAll ,
                          Letters = SmallCaps } ,
    SmallCapsFont = cmunbl.ttf
  } ,
  SlantedFont = {Latin Modern Roman Slanted} ,
  SlantedFeatures = {
    Ligatures = Discretionary ,
    SmallCapsFeatures = { Ligatures = ResetAll } ,
    SmallCapsFont = lmromancaps10-oblique.otf
  } ,
  BoldSlantedFont = lmromanslant10-bold.otf ,
  BoldSlantedFeatures = {
    Ligatures = Discretionary ,
    SmallCapsFeatures = { % Ligatures = ResetAll ,
                          Letters = SmallCaps } ,
    SmallCapsFont = cmunbl.ttf
  } ,
  FontFace = {sb}{n}{
    Font = {Latin Modern Roman Demi} ,
    Ligatures = Discretionary } ,
  FontFace = {sb}{sl}{
    Font = lmromandemi10-oblique.otf ,
    Ligatures = Discretionary } ,
  FontFace = {sb}{it}{
    Font = lmromandemi10-oblique.otf ,
    Ligatures = Discretionary } ,
  FontFace = {bc}{n}{CMU Serif Bold Non-Extended} ,
  FontFace = {m}{ui}{Latin Modern Roman Unslanted}
]

\setmathfont{Latin Modern Math}
\setmathfont[range=up]{Latin Modern Roman Unslanted}

\DeclareRobustCommand\sbseries{\fontseries{sb}\selectfont}
\DeclareTextFontCommand{\textsb}{\sbseries}
\DeclareRobustCommand\uishape{\fontshape{ui}\selectfont}
\DeclareTextFontCommand{\textui}{\uishape}

\begin{document}
  \begin{minipage}{10cm}

\textrm{
Latin Modern Roman \textit{Italic} \textsl{Slanted} \textui{Upright-Italic}
\textsb{Demibold \textit{Oblique}}
\textbf{Bold \textit{Italic} \textsl{Slanted}} {\fontseries{bc}\selectfont Non-extended}
\textsc{Small Caps \textit{Italic} \textsl{Slanted} \textbf{Bold \textit{Italic} \textsl{Slanted}}}
}
\[ \symup{e}^{\symup{i}x} = \cos x + \symup{i} \sin x \implies \symup{e}^{\symup{i}\muppi} + 1 = 0 \]
  \end{minipage}
\end{document}

Latin Modern Roman Font Sample

I threw in an example of how the Upright Italic style is useful: it’s great for setting mathematical constants such as e, π and i upright, in ISO style. Compare the imaginary unit i in i sin x with the i in sin and the italic variable name x. You can also take that as an example of how to use any other font face in math mode.

You could eliminate some of the warnings by removing the Ligatures commands. For whatever reason, possibly a bug in fontspec, SmallCapsFeatures = {Ligatures = ResetAll} does nothing and Ligatures = NoDiscretionary only produces a second error message saying that the font does not support dlig. However, the warning is harmless.

If you want more kinds of small caps, you might apply the FakeBold feature to a different weight, or you might find this code useful.