2

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 .)

ivo Welch
  • 3,766
  • 2
    For math, are you aware of unicode-math package? The manual is very good. Fonts are a deep well. – Cicada Nov 04 '21 at 05:34
  • 1
    Tip of the iceberg: https://tex.stackexchange.com/questions/58098/what-are-all-the-font-styles-i-can-use-in-math-mode Screen images of the unicode math alphabets: https://tex.stackexchange.com/questions/619785/what-do-the-unicode-math-range-labels-mean – Cicada Nov 04 '21 at 05: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 https://tex.stackexchange.com/questions/530983/implement-a-special-font-and-looking-its-name/530991#530991 – Cicada Nov 04 '21 at 06: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. – Cicada Nov 04 '21 at 06:10
  • 3
    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. – Marcel Krüger Nov 04 '21 at 06:21

3 Answers3

5

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: % https://software.sil.org/andika/download/ \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}

XCharter/Andika/MathDesign sample

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}
Davislor
  • 44,045
  • 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? – ivo Welch Nov 04 '21 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. – Davislor Nov 04 '21 at 22:54
4

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.)

Mico
  • 506,678
  • Loading a font by its display name is deprecated. It’s definitely much more readable, though, and sometimes you even have to for compatibility. – Davislor Nov 04 '21 at 08:30
  • 1
    @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. – Marcel Krüger Nov 04 '21 at 08:59
  • @MarcelKrüger That’s reasonable. Here you go. – Davislor Nov 04 '21 at 09:45
  • @Davislor Thanks, I missed that. Will certainly has a point, but I don't think that for system fonts using filenames (which on some systems might not even be easy to determine for the user) is really practicable. – Marcel Krüger Nov 04 '21 at 10:34
  • @MarcelKrüger Agreed. The different filenames of fonts on different systems was what I meant above by "sometimes you even have to." However, with a libre font like Andika and XCharter, you do have the option of archiving the version you want in a subdirectory, along with your project files. Then you never have to try to figure out what version worked a dozen years ago when you got it to compile, and where on the Internet you might find that specific version. – Davislor Nov 04 '21 at 12:11
  • 1
    @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. – Davislor Nov 04 '21 at 12:14
  • 1
    @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. – Davislor Nov 04 '21 at 12:20
  • @Davislor - I think that your claim that "Loading a font by its display name is deprecated" is unsupported. Will Robertson having a mild preference for a different syntax does not make \setsansfont{Andika} or, for that matter, \setmainfont{Latin Modern Roman} syntactically deprecated. – Mico Nov 06 '21 at 11:42
  • @Mico I don’t have the time to watch the entire talk again right now, but my recollection is that he did say at one point that the old way is deprecated. Newer font packages on CTAN now supply .fontspec files. Also, I just last night had to answer someone’s question about why XeTeX could not find a font by its display name, and the solution was very complicated. – Davislor Nov 06 '21 at 15:20
2

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.

enter image description here

egreg
  • 1,121,712