2

I have to make a document, which was originally written in LuaLaTeX, compatible for both pdfLaTeX and LuaLaTeX. Everything works except that the fonts differ. How can I force pdfLaTeX/fontenc to use the same fonts as fontspec?

Minimal example (omitted ifluatex to avoid clutter):

\documentclass[fontsize=11pt]{scrreprt}
% \usepackage{fontspec}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\begin{document}
    \chapter{Chapter}
    \section{Section}
    Text with some formulas: $a=1$.
\end{document}

By using lmodern, the fonts of the text seem to almost coincide, but the math fonts differ:

# pdffonts output for pdflatex with lmodern, fontenc and inputenc:
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
ZGMFNK+LMSans10-Bold                 Type 1            Custom           yes yes no       4  0
YIMXCY+LMRoman10-Regular             Type 1            Custom           yes yes no       5  0
GXEVRM+LMMathItalic10-Regular        Type 1            Custom           yes yes no       6  0
YIMXCY+LMRoman10-Regular             Type 1            Custom           yes yes no       7  0

# pdffonts output for lualatex with fontspec:
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
SSPBGH+LMSans10-Bold                 CID Type 0C       Identity-H       yes yes yes      4  0
XXBUAG+LMRoman10-Regular             CID Type 0C       Identity-H       yes yes yes      5  0
EDWHGC+CMMI10                        Type 1            Builtin          yes yes no       6  0
HVZLMP+CMR10                         Type 1            Builtin          yes yes no       7  0

So, the type and encoding differs, and the math fonts.

6

It is not possible to get the same font encodings for LuaTeX and pdfTeX, for the simple reason that LuaTeX with fontspec uses OpenType fonts, whereas pdfTeX uses Type 1 fonts. It is possible to get the same math fonts, though, by passing the option nomath to lmodern.

If you are using the 2018 version of LaTeX, you can remove \usepackage[utf8]{inputenc} because UTF-8 is now the standard encoding.

\documentclass[fontsize=11pt]{scrreprt}
\ifdefined\directlua
  \usepackage{fontspec}
\else
  \usepackage[T1]{fontenc}
  \usepackage[nomath]{lmodern}
\fi

\begin{document}
    \chapter{Chapter}
    \section{Section}
    Text with some formulas: $a=1$.
\end{document}

Run through pdflatex I get this

$ pdflatex test.tex
$ pdffonts test.pdf
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
ZGMFNK+LMSans10-Bold                 Type 1            Custom           yes yes no       4  0
KOIJYY+LMRoman10-Regular             Type 1            Custom           yes yes no       5  0
EDWHGC+CMMI10                        Type 1            Builtin          yes yes no       6  0
HVZLMP+CMR10                         Type 1            Builtin          yes yes no       7  0

Run through lualatex I get this

$ lualatex test.tex
$ pdffonts test.pdf
name                                 type              encoding         emb sub uni object ID
------------------------------------ ----------------- ---------------- --- --- --- ---------
SSPBGH+LMSans10-Bold                 CID Type 0C       Identity-H       yes yes yes      4  0
HXVMKT+LMRoman10-Regular             CID Type 0C       Identity-H       yes yes yes      5  0
EDWHGC+CMMI10                        Type 1            Builtin          yes yes no       6  0
HVZLMP+CMR10                         Type 1            Builtin          yes yes no       7  0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.