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.
Best Answer
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 optionnomath
tolmodern
.If you are using the 2018 version of LaTeX, you can remove
\usepackage[utf8]{inputenc}
because UTF-8 is now the standard encoding.Run through
pdflatex
I get thisRun through
lualatex
I get this