I am trying to update a thesis template I got to work non only with pdflatex
, but also with lualatex
(to enable larger tikz-figures, mostly). Following the received comments to Mathdesign changes \mu-sign in siunitx when used with lualatex, but not with pdflatex I wrote the following MWE:
\documentclass[a4paper,11pt,openright]{book}
\usepackage[dvipsnames]{xcolor} % selecting text color
\usepackage{pdfpages} % including pdf files
%% PACKAGE LOADING
\usepackage{ifluatex}
\ifluatex
\DeclareSymbolFont{charteraccents}{T1}{XCharter-TLF}{m}{n}
\SetSymbolFont{charteraccents}{bold}{T1}{XCharter-TLF}{b}{n}
\DeclareMathAccent{\grave}{\mathalpha}{charteraccents}{0}
\DeclareMathAccent{\acute}{\mathalpha}{charteraccents}{1}
\DeclareMathAccent{\hat}{\mathalpha}{charteraccents}{2}
\DeclareMathAccent{\tilde}{\mathalpha}{charteraccents}{3}
\DeclareMathAccent{\ddot}{\mathalpha}{charteraccents}{4}
\DeclareMathAccent{\mathring}{\mathalpha}{charteraccents}{6}
\DeclareMathAccent{\check}{\mathalpha}{charteraccents}{7}
\DeclareMathAccent{\breve}{\mathalpha}{charteraccents}{8}
\DeclareMathAccent{\bar}{\mathalpha}{charteraccents}{9}
\DeclareMathAccent{\dot}{\mathalpha}{charteraccents}{10}
\usepackage{amsmath}
\usepackage[no-math]{fontspec}
\usepackage[xcharter]{newtxmath}
\setmainfont{XCharter}[NFSSFamily=XCharter]
\defaultfontfeatures{Ligatures={TeX}}
\setsansfont[Scale=.88]{DejaVuSans}
\setmonofont[Scale=.82]{DejaVuSansMono}
\setmathrm{XCharter}
\setboldmathrm{XCharter Bold}
\else
\usepackage[utf8]{inputenc} % for special characters in input
\usepackage[T1]{fontenc} % modern font encoding
\usepackage[charter, cal=cmcal]{mathdesign} % main font with math support
\usepackage{XCharter}
\usepackage[scaled=.88]{berasans} % sans serif font
\usepackage[scaled=.82]{DejaVuSansMono} % monospace font (for code)
\usepackage{amsmath} % advanced math typesetting
\fi
\usepackage[english]{babel} % language specifics
\usepackage{siunitx}
\begin{document}
Hello World
$100\text{ coins are 100 coins}$
\SI{100}{\micro\meter} are 100 \textmu m
100/\num{100}=1
\end{document}
When compiling with pdflatex
, I get the following result:
but when compiling with lualatex
, I get a slightly different result:
The math font is obviously slightly off. What can I do to make the result of lualatex
at least comparable, if not equal, to pdflatex
? And are there other mistakes?
\mathrm
is defaulting to CMR under lualatex. Best might be to\renewcommand\rmdefault{..}
before loadingnewtxmath
, however I am unsure of the correct font naming {..} to get you XCharter at that point; perhaps someone else can help. A few other notes:ifluatex
should be replaced with the more recentiftex
;newtxmath
requiresamsmath
, so you don't need to load it separately; andnewtx
documentation recommends loadingfontspec
afternewtxmath
.