Fontspec Package With Other Font-Related Packages (charter, etc)

I am now switching over to lualatex (hence so many questions), partly in order to be able to use another font, partly to learn lua facilities.

\usepackage{fontspec}  %% should come before microtype
\newfontfamily{\andika}
[Ligatures=TeX, % recommended
UprightFont={*},
ItalicFont={* Italic},
BoldFont={* Bold},
BoldItalicFont={* Bold Italic}]{Andika}
\newcommand{\textandikabf}[2][20]{{\andika\bfseries\fontsize{#1}{#1}\selectfont#2}}



Like most people, I have hamstered together style files I have used for years, which include fonts I have used for years, most of which I don't fully understand. I believe fontspec tinkers/overrides some of them. I am trying to figure out what is good practice now.

\usepackage[T1]{fontenc} --- presumably, I still leave this.

\usepackage{charter} --- was my main font because it is heavier than modern roman, has good math fonts, and is free whereever latex is installed. alas, fontspec seems to override this one, even though I do not use \setmainfont. I am also not sure whether the macos (or other computer system) charter fonts are as good as those included with texlive.

\usepackage[mdbch,ttscaled=true]{mathdesign} --- to match the charter on the math font side.

\usepackage{textcomp} --- text companion fonts, presumably also still ok. For stuff like the Yen symbol.

\usepackage{microtype} --- I believe this has to be loaded after package fontspec.

Ergo, my primary question is how to get back my good latex-native charter font now (and still use andika for highlights). My secondary question is how to deal with these other mentioned font-related packages. Advice [as always] highly appreciated.

PS: (If anyone knows of another good universal and free font on all TeX systems with good math support that would be better for a textbook, feel free to drop me a hint, too. The font catalog lists fonts with mathsupport in https://tug.org/FontCatalogue/mathfonts.html .)

• For math, are you aware of unicode-math package? The manual is very good. Fonts are a deep well. Nov 4, 2021 at 5:34
• Tip of the iceberg: tex.stackexchange.com/questions/58098/… Screen images of the unicode math alphabets: tex.stackexchange.com/questions/619785/… Nov 4, 2021 at 5:46
• Ther's a font set of OpenType files for XCharter, sitting under \texmf-dist\fonts\opentype\public\xcharter, if that helps. Other questions/answers intimate that Charis SIL is a charter clone. And Erewhon is available: Erewhon tex.stackexchange.com/questions/530983/… Nov 4, 2021 at 6:06
• You can still use legacy/NFSS fonts with (or without) fontspec - it's not totally an either/or issue. Depends on what you want to do. Nov 4, 2021 at 6:10
• I would strongly advice against using legacy fonts in LuaLaTeX (except for maths). They might work in simple cases, but the hyphenation patterns are wrong for them and the input handling is not designed to handle them either. (E.g. entering ß would just output the wrong character) It probably works more or less if you don't care about correct hyphenation and don't use non ASCII character in your source file, but it's very easy to introduce hidden errors. Nov 4, 2021 at 6:21

You would not use fontenc together with fontspec. It’s mostly harmless, but it won’t work. The fontspec package switches from 8-bit legacy encodings to Unicode. It is still possible to mix and match if you really want to. You also do not need to load textcomp, with or without fontspec. It’s now part of the LaTeX kernel.

What you actually want to do is load a TrueType or OpenType version of Charter, together with your math font. There are several clones in the TeX Live distribution, including XCharter.

\documentclass{article}
\usepackage[mdbch,ttscaled=true]{mathdesign}
\usepackage{fontspec}

\usepackage[paperwidth=10cm]{geometry} % To format the MWE for TeX.SX
\pagestyle{empty}

\defaultfontfeatures{ Scale=MatchUppercase, Ligatures=TeX }

% There is an XCharter.fontspec file in TeX Live,
% so this command is unnecessary:
%
%\defaultfontfeatures[XCharter]{
%  Ligatures=Common,
%  UprightFont=*-Roman,
%  BoldFont=*-Bold,
%  ItalicFont=*-Italic,
%  SlantedFont=*-Slanted,
%  BoldItalicFont=*-BoldItalic,
%  BoldSlantedFont=*-BoldSlanted,
%  Extension=.otf}

% Andika is available from:
\defaultfontfeatures[Andika]{
Ligatures=Common,
UprightFont={*},
ItalicFont={* Italic},
BoldFont={* Bold},
BoldItalicFont={* Bold Italic}}

\setmainfont{XCharter}
\newfontfamily\andika{Andika}

\newcommand{\textandikabf}[2][20]{{\andika\bfseries\fontsize{#1}{#1}\selectfont#2}}

\begin{document}
An \textit{example} of Charter and \textandikabf[10]{Andika}.

$x = ma$
\end{document}


This uses Math Design Charter as the math font and the OTF version of XCharter as the text font. Since both were cloned from the same original font, they match.

There isn’t always an exact match for your text font in a TeX math package, though. When there isn’t, you can use your modern font for letters in math mode. You can set up mathastext, mathspec or unicode-math to do it. If all you need to do is set up the \mathnormal alphabet to use the main text font in italic style, something like this works:

\usepackage{mathdesign} % Or your legacy 8-bit math package
\usepackage{fontspec} % Or any modern font package
\setmainfont{...}
\usepackage[italic]{mathastext}

• I like mathastext with normal shapes, but presumably I still need something like mathdesign[mdbch...] for operators, greeks, etc. are the others you mention (mathspec, unicode-math) better substitutes for mathdesign? Nov 4, 2021 at 22:44
• @ivoWelch There are some technical ways that unicode-math is objectively “better,” but whether you like the appearance is a matter of opinion. If you really want Charter, you might combine \setmathfont{TeX Gyre Bookman Math}, or some other font whose weight you think matches well, with \setmathfont{XCharter-Italic.otf}[range=it, Scale=Matchlowercase], etc. Nov 4, 2021 at 22:54

Three comments -- the first two are specific to Andika.

• If Andika is going to be the document's main sans-serif font, I would use

\setsansfont{Andika}[<options>]


rather than

\newfontfamily{\andika}{Andika}[<options>]


That way, all of your old commands that employ the document's basic sans-serif font faces will continue to work without modification.

• Unless you employ some bespoke, non-standard version of the Andika font family, it should suffice to execute

\setsansfont{Andika}


without bothering to state the four font face options -- UprightFont, BoldFont, etc.; they should be redundant. On the other hand, do think carefully whether you want Scale=MatchUppercase or Scale=MatchLowercase; you may not anticipate just how different the outcomes can be.

• (This has already been mentioned by others.) Under LuaLaTeX, don't employ the inputenc, fontenc, and textcomp packages. It shouldn't matter whether you load microtype before or after fontspec (or its "big brother", viz., unicode-math.)

• Loading a font by its display name is deprecated. It’s definitely much more readable, though, and sometimes you even have to for compatibility. Nov 4, 2021 at 8:30
• @Davislor [Citation needed]? Especially for fonts like Andika which are not distributed with TeX I would recommend to load them by name for XeTeX compatibility, but even in a pure LuaTeX document it makes it much easier to setup optical sizes/font styles/etc. You are a bit more likely to hit some unexpected cases this way since different programs might use different names, but I wouldn't consider them deprecated. Nov 4, 2021 at 8:59
• @MarcelKrüger That’s reasonable. Here you go. Nov 4, 2021 at 9:45
• @MarcelKrüger It takes up a few megabytes of space (our good friends the missionaries at SIL had the droll wit to make all the Andika files 666 kilobytes in size) but backup storage is extremely cheap. Nov 4, 2021 at 12:14
• @MarcelKrüger Actually, though, I see that in this case there is an XCharter.fontspec file that ships with TeX Live, so \setmainfont{XCharter} should always be superior to what I wrote. Nov 4, 2021 at 12:20

You can use the XCharter OpenType font available in TeX Live and the companion math fonts developed by the same author.

I'm not sure what the \textandikabf command is supposed to do, but…

\documentclass{article}
\usepackage{fontspec}
\usepackage[xcharter]{newtxmath}

\setmainfont{XCharter}[
Scale=0.9274,% to match the math fonts
Extension=.otf,
UprightFont=*-Roman,
ItalicFont=*-Italic,
BoldFont=*-Bold,
BoldItalicFont=*-BoldItalic,
]

\newfontfamily{\andika}{Andika}[
Ligatures=TeX,
Extension=.ttf,
Path=./,% because I don't have it in my system and downloaded it
UprightFont=*-Regular,
ItalicFont=*-Italic,
BoldFont=*-Bold,
BoldItalicFont=*-BoldItalic,
]

\newcommand{\textandikabf}[2][20]{%
{\fontsize{#1}{0}\andika\bfseries#2}%
}

\begin{document}

This is in Charter \textit{a}$a+b=c$
$\int_{-\infty}^\infty e^{-x^2}\,dx=\sqrt{\pi}$

This is \textandikabf{Andika}

\end{document}


As the comment says, Path=./ is just because I put the Andika fonts in the working directory.

I computed the scaling factor by comparing an italic “a” with the math character.

• I like this font Andika. :-) Nov 4, 2021 at 22:23