[Home] [GRP] [RES] [PUB] [ETC] [LEC] [S/W]
 

XeLaTeX or LuaLaTeX Font Setup Tips

Background

My (Jochen’s) textbook, QTCA, was written in LaTeX. See this page for some thoughts regarding the pros and cons of using TeX/LaTeX/etc. for writing documents on a computer (how else? ...).

For the textbook manuscript, I used pdflatex with Adobe Times as the main text font, and the STIX Math fonts in their originally released version (v. 1), along with the stix LaTeX support package. My book’s publisher later chose a style based on MinionPro as the main text font, and a variety of other fonts for different elements on the pages. I learned eventually that they were using the xetex engine, i.e., xelatex for compiling the sources, to produce the PDF from which the book was printed. Therefore, I decided to replicate that same setup locally for my book manuscript. I cannot share all details of the setup here. However, I was unfamiliar with fontspec and xelatex until recently, and learned a few things along the way that may be of interest to some.

XeLaTeX / LuaLaTeX setup with STIX Two fonts

I’m rather fond (font?) of the typefaces provided by the STIX project. Version 1, using the stix LaTeX support package, looks great when paired with a Times or Times New Roman base font, or with MinionPro. The math italic glyphs that come with the newer STIX v. 2 (STIX Two) package look different, at least to me, such that when using STIX Two I prefer a setup that uses the STIX Two fonts consistently for math and text.

Below is a setup that works on my Linux PCs, using a recent version of TexLive, with STIXTwo (or STIX2) Text and Math fonts, TeX Gyre Heros for sans serif, and the stix2 LaTeX support package. The same setup should work with other TeX installations or operating systems, as long as the relevant packages are installed. I also load the packages amsmath, bm (see a usage example), and several other useful packages, and re-define the Math commands for the Real and Imaginary part of a complex number, because I don’t like the defaults using Gothic types (Fraktur).

An article template for my research group, with some nonsense Math and other stuff to test the font features defined below, compiles fine on my system both with xelatex and lualatex (see compiled PDF). For convenience, you can download the required open-type font files and the stix2 LaTeX support package here. In TexLive 2019, the otf font files used names with ‘STIX2’ instead of ‘STIXTwo’. I have packaged the 2019 font files and the 2019 stix2 support package here also, for backward compatibility. Please note that all LaTeX support files packaged here come from the TexLive 2021 or 2019 distribution and are subject to the LaTeX Project Public License.

% AMS Math needs to be loaded before font packages: 
\usepackage{amsmath} 
 
\usepackage{fontspec} 
\defaultfontfeatures{Ligatures=TeX} 
 
% Select the text fonts that come with STIX Two. The way it is done 
% below is by selecting the font files by name. The files are 
% STIXTwoText-Regular.otf 
% STIXTwoText-Italic.otf 
% STIXTwoText-Bold.otf 
% STIXTwoText-BoldItalic.otf 
% 
% you may need to replace STIXTwo by STIX2 below,, depending on your local 
% installation. I recommend searching for the font file names 
% in your TeX installation 
% 
% see also https://tug.org/TUGboat/tb39-2/tb122robertson-fontspec.pdf 
% and 
% https://tex.stackexchange.com/questions/503826/fontspec-help-combining-fonts/503836#503836 
% 
\setmainfont{STIXTwoText}[ 
Extension = {.otf}, 
UprightFont = {*-Regular}, 
ItalicFont = {*-Italic}, 
BoldFont = {*-Bold}, 
BoldItalicFont = {*-BoldItalic} 
] 
 
% TeX Gyre Heros for sans. You can either select the fonts by using 
% \setsansfont{TeX Gyre Heros}[<options>] , as above, specify the 
% file names, as done below. The files are 
% texgyreheros-regular.otf 
% texgyreheros-bold.otf 
% texgyreheros-italic.otf 
% texgyreheros-bolditalic.otf 
% 
\setsansfont{texgyreheros}[ 
Extension = {.otf}, 
UprightFont = {*-regular}, 
ItalicFont = {*-italic}, 
BoldFont = {*-bold}, 
BoldItalicFont = {*-bolditalic}] 
 
% Load STIX Two support package for Math 
% 
\AtBeginDocument{ 
  \usepackage[notextcomp,lcgreekalpha]{stix2} 
  \renewcommand{\Re}{\operatorname{Re}} 
  \renewcommand{\Im}{\operatorname{Im}} 
} 
 
% Bold math definitions: 
\usepackage{bm} 
 
% graphics import support: 
\usepackage{graphicx} 
 
% use 'cite' or 'overcite' to handle citations in a smart way: 
\usepackage{overcite} 
 
% use setspace commands such as 
% \onehalfspacing or \doublespacing or 
% \singlespacing in the text to control spacing: 
\usepackage{setspace} 
 
% Chemical formulas (e.g. \ch{H2O}): 
\usepackage{chemformula} 
 
% support for color: 
\usepackage{color} 
 
% Page layout: 
\usepackage[letterpaper,ignoreall,top=2.65cm,bottom=2.7cm,% 
left=2.65cm,right=2.65cm,foot=1cm,head=1.5cm]{geometry} 
 
% Smaller section headings. There is also the option 'compact': 
\usepackage[small]{titlesec} 

© 2021 – 2024 J. Autschbach.