1/52

Progress of fontspec andunicode-math
Will Robertson

July 22, 2018

2/52

Setting the scene

2/52

Setting the scene

3/52

How long has it been??
[XeTeX] Package for font loading
Will Robertson will at guerilla.net.au
Fri Oct 15 12:04:24 CEST 2004
Hi allI've got a first release ready of a package for XeLaTeX that allows
dynamic font loading, supporting all of the rich font features in AAT.
It doesn't yet support OpenType, but that's coming.
It allows you to use a commands like\typespec[NumberCase=OldStyle, NumberSpacing=Monospaced]{Hoefler Text}
or\typespec[Variant=5]{Zapfino}
to select a very broad selection of fonts.
It's only new, so it will definitely be improved!

4/52

Introduction
unicode-math – modern expl3 package development
Code structure
CHANGES ﬁleexpl3 conventions
Git branches
Test suite
Release checklist
fontspec – selecting fonts
Font loading
The interface for font features
Typical example‘Strong’ emphasis
Custom encodings
Conclusion

Introduction

Evolution• LATEX was my introduction to software engineering —scarily enough• fontspec and unicode-math were initially released pre-expl3• expl3 was needed to advance them beyond crude
data-structures and algorithms• Their programming styles evolved with expl3• Has taken quite some time to become ‘respectable’ !

5/52

Introduction

To discuss• fontspec – selecting fonts• unicode-math – learning from my mistakes in bestpractices for TEX software development

6/52

unicode-math – modern expl3 package development

Introduction
unicode-math – modern expl3 package development
Code structure
CHANGES ﬁleexpl3 conventions
Git branches
Test suite
Release checklist
fontspec – selecting fonts
Font loading
The interface for font features
Typical example‘Strong’ emphasis
Custom encodings
Conclusion

7/52

unicode-math – modern expl3 package development(Live demo to re-introduce the package.)

8/52

unicode-math – modern expl3 package development
Code structure

Introduction
unicode-math – modern expl3 package development
Code structure
CHANGES ﬁleexpl3 conventions
Git branches
Test suite
Release checklist
fontspec – selecting fonts
Font loading
The interface for font features
Typical example‘Strong’ emphasis
Custom encodings
Conclusion

9/52

unicode-math – modern expl3 package development
Code structure• Once upon a time: monolithic dtx ﬁles
• Now: (thanks Joseph!)• ⟨pkg⟩.dtx: provide metadata

10/52

unicode-math – modern expl3 package development
Code structure• Once upon a time: monolithic dtx ﬁles
• Now: (thanks Joseph!)• ⟨pkg⟩.dtx: provide metadata• ⟨pkg⟩-code-⟨module⟩.dtx

10/52

unicode-math – modern expl3 package development
Code structure• Once upon a time: monolithic dtx ﬁles
• Now: (thanks Joseph!)• ⟨pkg⟩.dtx: provide metadata• ⟨pkg⟩-code-⟨module⟩.dtx• ⟨pkg⟩.ins: the standard Docstrip driver

10/52

unicode-math – modern expl3 package development
Code structure• Once upon a time: monolithic dtx ﬁles
• Now: (thanks Joseph!)• ⟨pkg⟩.dtx: provide metadata• ⟨pkg⟩-code-⟨module⟩.dtx• ⟨pkg⟩.ins: the standard Docstrip driver• ⟨pkg⟩-code.ltx: typeset code implementation

10/52

unicode-math – modern expl3 package development
Code structure• Once upon a time: monolithic dtx ﬁles
• Now: (thanks Joseph!)• ⟨pkg⟩.dtx: provide metadata• ⟨pkg⟩-code-⟨module⟩.dtx• ⟨pkg⟩.ins: the standard Docstrip driver• ⟨pkg⟩-code.ltx: typeset code implementation• ⟨pkg⟩.ltx: typeset user documentation

10/52

unicode-math – modern expl3 package development
Code structure• Once upon a time: monolithic dtx ﬁles
• Now: (thanks Joseph!)• ⟨pkg⟩.dtx: provide metadata• ⟨pkg⟩-code-⟨module⟩.dtx• ⟨pkg⟩.ins: the standard Docstrip driver• ⟨pkg⟩-code.ltx: typeset code implementation• ⟨pkg⟩.ltx: typeset user documentation• ⟨pkg⟩-doc-⟨chapter⟩.tex

10/52

unicode-math – modern expl3 package development
CHANGES ﬁleIntroduction
unicode-math – modern expl3 package development
Code structure
CHANGES ﬁleexpl3 conventions
Git branches
Test suite
Release checklist
fontspec – selecting fonts
Font loading
The interface for font features
Typical example‘Strong’ emphasis
Custom encodings
Conclusion

11/52

unicode-math – modern expl3 package development
CHANGES ﬁle

12/52

CHANGE HISTORY==============## v0.8m ()* Restore behaviour of legacy syntax `x_\mathrm{x}` (i.e.
While strictly ‘incorrectly’, this usage is widely used## v0.8l (2018/02/02)* Issue an error message if `\setmathfont{...}[range=...]
declaration inherently implies a subset, so a ‘main’ ma* Fix issue when nesting `\mathXX` and `\symZZ` commands.
* ...

unicode-math – modern expl3 package development
expl3 conventions

Introduction
unicode-math – modern expl3 package development
Code structure
CHANGES ﬁleexpl3 conventions
Git branches
Test suite
Release checklist
fontspec – selecting fonts
Font loading
The interface for font features
Typical example‘Strong’ emphasis
Custom encodings
Conclusion

13/52unicode-math – modern expl3 package development
expl3 conventions• ‘Auto-checking’:\usepackage[enable-debug]{expl3}\ExplSyntaxOn\debug_on:n {check-declarations,check-expressions,deprecation}\ExplSyntaxOff• Indentation• Variables deﬁned up front• Separation between internal and user-facing commands
• …

14/52

unicode-math – modern expl3 package development
Git branches

Introduction
unicode-math – modern expl3 package development
Code structure
CHANGES ﬁleexpl3 conventions
Git branches
Test suite
Release checklist
fontspec – selecting fonts
Font loading
The interface for font featuresTypical example‘Strong’ emphasis
Custom encodings
Conclusion

15/52

unicode-math – modern expl3 package development
Git branches

Branches

16/52

unicode-math – modern expl3 package development
Test suite

Introduction
unicode-math – modern expl3 package development
Code structure
CHANGES ﬁleexpl3 conventions
Git branches
Test suite
Release checklist
fontspec – selecting fonts
Font loading
The interface for font features
Typical example‘Strong’ emphasis
Custom encodings
Conclusion

17/52

unicode-math – modern expl3 package development
Test suite

Early days of the test suite:• XELATEX → pdf → png → ImageMagick• A horribly-fragile and hard-to-read Makeﬁle• Pixel by pixel comparisons• Slow, lots of false negatives• Nonetheless, a large number of tests produced

18/52

unicode-math – modern expl3 package development
Test suitel3build brought automated unit testing to the masses:• Just wrap \loggingoutout around everything is ﬁne?

19/52

unicode-math – modern expl3 package development
Test suitel3build brought automated unit testing to the masses:• Just wrap \loggingoutout around everything is ﬁne?
• It is really not ﬁne.

19/52

unicode-math – modern expl3 package development
Test suitel3build brought automated unit testing to the masses:• Just wrap \loggingoutout around everything is ﬁne?
• It is really not ﬁne.
• Slowly re-write all tests with custom, minimal, logging.

19/52

unicode-math – modern expl3 package development
Test suite

Example test input\input{umtest-preamble}\usepackage{fontspec}\setmathsf{texgyrecursor-regular.otf}\usepackage{unicode-math}\begin{document}\START\TESTBOX{$\mathsf{X}=X$}\end{document}

20/52

unicode-math – modern expl3 package development
Test suite

21/52

Example test output

This is a generated file for the l3build validation system.
Don't change this file in any respect.
> \box...=\hbox(0.0+0.0)x0.0.\mathon.\TU/texgyrecursor-regular.otf(0)/m/n/10 glyph#116.\glue(\thickmuskip) 2.77779 plus 2.77779.\TU/latinmodern-math.otf(1)/m/n/10 glyph#30.\glue(\thickmuskip) 2.77779 plus 2.77779.\TU/latinmodern-math.otf(1)/m/n/10 glyph#1293.\kern0.51.\mathoff! OK.
<to be read again>\relaxl. ...\TESTBOX{$\mathsf{X}=X$}

unicode-math – modern expl3 package development
Release checklist

Introduction
unicode-math – modern expl3 package development
Code structure
CHANGES ﬁleexpl3 conventions
Git branches
Test suite
Release checklist
fontspec – selecting fonts
Font loading
The interface for font features
Typical example‘Strong’ emphasis
Custom encodings
Conclusion

22/52

unicode-math – modern expl3 package development
Release checklist
1. Finish ﬁnal changes on working branch
2. Ensure CHANGES.md is up-to-date with a new version number
3. build setversion
4. Update local distro fully with tlmgr
5. Run build check locally
6. git push
7. Check Travis build status
8. Install prerelease versions of fontspec and latex3 and re-check9. git checkout master; git rebase working
10. build ctan
11. Upload to CTAN
12. texlua tagrelease.lua to tag release with version number, annotated withchanges
13. git push — assuming tags are pushed by default (might need a local gitconﬁg)
14. git checkout working
15. build install
16. Check latex3/contrib/testfiles/unicode-math001.lvt and update ifnecessary
17. build uninstall

23/52

fontspec – selecting fonts

Introduction
unicode-math – modern expl3 package development
Code structure
CHANGES ﬁleexpl3 conventions
Git branches
Test suite
Release checklist
fontspec – selecting fonts
Font loading
The interface for font features
Typical example‘Strong’ emphasis
Custom encodings
Conclusion

24/52

fontspec – selecting fonts

fontspec’s interface• Originally very simple• Based around aat font features, not OpenType!
• The Graphite font renderer needs more attention• A rewrite probably won’t happen, but a slimmed-down‘LATEX3’ version might

25/52

fontspec – selecting fonts
Font loading

Introduction
unicode-math – modern expl3 package development
Code structure
CHANGES ﬁleexpl3 conventions
Git branches
Test suite
Release checklist
fontspec – selecting fonts
Font loading
The interface for font features
Typical example‘Strong’ emphasis
Custom encodings
Conclusion

26/52

fontspec – selecting fonts
Font loading

How do I load a font in fontspec?
• \fontspec• \setmainfont• \newfontfamily• \defaultfontfeatures
As the package has grown it is probably less than clear!

27/52

fontspec – selecting fonts
Font loading

Font names

XETEX was originally written to load fonts from the OS:\setmainfont{Hoefler Text}% -- `just works'
luaotfload followed, and now:
\setmainfont{TeX Gyre Pagella}% -- `just works'

28/52

fontspec – selecting fonts
Font loading

File names
But also:\setmainfont{texgyrepagella-regular.otf}[ItalicFont= texgyrepagella-italic.otf,BoldFont= texgyrepagella-bold.otf,
BoldItalicFont = texgyrepagella-bolditalic.otf ,]
(or)

29/52

fontspec – selecting fonts
Font loading

File names
But also:\setmainfont{texgyrepagella}[Extension= .otf,UprightFont= *-regular,
ItalicFont= *-italic,
BoldFont= *-bold,
BoldItalicFont = *-bolditalic ,]Which is better? This is the approach I now recommend.

30/52

fontspec – selecting fonts
Font loading

The case against font names
1. Edge cases• Sometimes the correct italic/bold shape isn’t picked up

2. Document portability• XETEX/luaotfload differences• Replicating font installation across computers• Differences in software/font versions → different names

3. Speed• Generating the font database is slow
• Installing 100s of fonts in a system directory can be slow

31/52

fontspec – selecting fonts
The interface for font features

Introduction
unicode-math – modern expl3 package development
Code structure
CHANGES ﬁleexpl3 conventions
Git branches
Test suite
Release checklist
fontspec – selecting fonts
Font loading
The interface for font features
Typical example‘Strong’ emphasis
Custom encodingsConclusion

32/52

fontspec – selecting fonts
The interface for font features\font\x="[EBGaramond12-Regular.otf]"

Theory 123\font\x="[EBGaramond12-Regular.otf]:+lnum;+dlig"

Theory 123

33/52

fontspec – selecting fonts
The interface for font features\fontspec{EBGaramond12-Regular.otf}

Theory 123\fontspec{EBGaramond12-Regular.otf}[Numbers= Lining,Ligatures = Discretionary ,]Theory 123

34/52

fontspec – selecting fonts
Typical example

Introduction
unicode-math – modern expl3 package development
Code structure
CHANGES ﬁleexpl3 conventions
Git branches
Test suiteRelease checklist
fontspec – selecting fonts
Font loading
The interface for font features
Typical example‘Strong’ emphasis
Custom encodings
Conclusion

35/52

fontspec – selecting fonts
Typical example

36/52

Consider Gill Sans Nova. Weights:• UltraLight• Light• Book• Medium• Semibold• Bold• Heavy• ExtraBold• UltraBold

Do people want to control these with commands like\textbolder and \textlighter?

fontspec – selecting fonts
Typical example

37/52‘Weight’ is relatively simple. Also have:• CnUltraLight• CnLight• CnBook• CnMedium• CnSemibold• CnBold• CnHeavy• CnExtraBold• CnUltraBoldfontspec – selecting fonts
Typical example

38/52

And then the variants:• Deco-Regular• Shadowed-Light• Shadowed-Medium• Shadowed-Outln• Inline-Cond• Inline-ExtraLt• Inline-Light• Inline-Regular• Inline-Boldfontspec – selecting fonts
Typical example• Most of the time I’m just after a ‘normal’ and a ‘bold’.

39/52

fontspec – selecting fonts
Typical example• Most of the time I’m just after a ‘normal’ and a ‘bold’.
• Create gill-sans-nova.fontspec:\defaultfontfeatures[gill-sans-nova]{
UprightFont= GillSansNova-Medium.otf,
ItalicFont= GillSansNova-MediumItalic.otf ,BoldFont= GillSansNova-Bold.otf,
BoldItalicFont = GillSansNova-BoldItalic.otf
,
}

39/52

fontspec – selecting fonts
Typical example• Most of the time I’m just after a ‘normal’ and a ‘bold’.
• Create gill-sans-nova.fontspec:\defaultfontfeatures[gill-sans-nova]{
UprightFont= GillSansNova-Medium.otf,
ItalicFont= GillSansNova-MediumItalic.otf ,BoldFont= GillSansNova-Bold.otf,
BoldItalicFont = GillSansNova-BoldItalic.otf,}• Now I can write \setmainfont{gill-sans-nova}.

39/52

fontspec – selecting fonts
Typical example• Most of the time I’m just after a ‘normal’ and a ‘bold’.
• Create gill-sans-nova.fontspec:\defaultfontfeatures[gill-sans-nova]{UprightFont= GillSansNova-Medium.otf,
ItalicFont= GillSansNova-MediumItalic.otf ,BoldFont= GillSansNova-Bold.otf,
BoldItalicFont = GillSansNova-BoldItalic.otf,}• Now I can write \setmainfont{gill-sans-nova}.
• Or, semantically,\newfontfamily\captionfont{gill-sans-nova}

39/52

fontspec – selecting fonts
Typical example

The full power of the nfss is supported:\defaultfontfeature+[gill-sans-nova]{
FontFace = {uu}{m}{ GillSansNova-UltraLight.otf } ,FontFace = {ll}{m}{ GillSansNova-Light.otf} ,FontFace = {hh}{m}{ GillSansNova-Heavy.otf} ,FontFace = {xx}{m}{ GillSansNova-ExtraBold.otf } ,}40/52

fontspec – selecting fonts‘Strong’ emphasis

Introduction
unicode-math – modern expl3 package development
Code structure
CHANGES ﬁleexpl3 conventions
Git branches
Test suite
Release checklist
fontspec – selecting fonts
Font loading
The interface for font features
Typical example‘Strong’ emphasis
Custom encodings
Conclusion

41/52

fontspec – selecting fonts‘Strong’ emphasis

Emphasis and inner emphasis• LATEX 2𝜀 supports \eminnershape for markup with nested
emphasis

42/52

fontspec – selecting fonts‘Strong’ emphasis

Emphasis and inner emphasis• LATEX 2𝜀 supports \eminnershape for markup with nestedemphasis• fontspec supports arbitrary nesting using (say)\emfontdeclare{\itshape,\upshape\scshape,\itshape}

42/52

fontspec – selecting fonts‘Strong’ emphasis

Emphasis and inner emphasis• LATEX 2𝜀 supports \eminnershape for markup with nestedemphasis• fontspec supports arbitrary nesting using (say)\emfontdeclare{\itshape,\upshape\scshape,\itshape}• Ex.:

Rm \emph{Aaa \emph{Bbb \emph{Iii}}}

42/52

fontspec – selecting fonts‘Strong’ emphasis

Strong and inner strong• And more recently…\strong!

43/52

fontspec – selecting fonts‘Strong’ emphasis

Strong and inner strong• And more recently…\strong!
• \strongfontdeclare{\bfseries,\fontseries{hh}\selectfont,\fontseries{xx}\selectfont,}

43/52

fontspec – selecting fonts‘Strong’ emphasis

43/52

Strong and inner strong• And more recently…\strong!
• \strongfontdeclare{\bfseries,\fontseries{hh}\selectfont,\fontseries{xx}\selectfont,}• Ex.:

Abc \strong{Abc \strong{Abc \strong{Abc}}}

fontspec – selecting fonts
Custom encodings

Introduction
unicode-math – modern expl3 package development
Code structure
CHANGES ﬁleexpl3 conventions
Git branches
Test suite
Release checklist
fontspec – selecting fonts
Font loading
The interface for font features
Typical example‘Strong’ emphasis
Custom encodings
Conclusion

44/52

fontspec – selecting fonts
Custom encodings• Although everything is now Unicode, LATEX’s idea of‘encodings’ is still useful

45/52

fontspec – selecting fonts
Custom encodings

46/52\newfontfamily\sanskitfont{charis}...{\sanskitfont KALITA\d M}...

% <- uses real accent

KALITAṂ

fontspec – selecting fonts
Custom encodings

47/52\newfontfamily\oopsfont {posterama}...{\oopsfont

KALITA\d M}...

% <- uses real accent

KALITAṂfontspec – selecting fonts
Custom encodings

48/52\newfontfamily\titlefont{posterama}[NFSSEncoding=fakedotaccent]...{\titlefont

KALITA\d M}...

% <- uses fake accent

KALITAM.

fontspec – selecting fonts
Custom encodings

In the preamble:\DeclareUnicodeEncoding{fakedotaccent}{\input{tuenc.def}\EncodingCommand{\d}[1]{%\hmode@bgroup\o@lign{\relax#1\crcr\hidewidth\ltx@sh@ft{-1ex}.\hidewidth}%\egroup}}

49/52fontspec – selecting fonts
Custom encodings

KALITAM.
(1901)

50/52

fontspec – selecting fonts
Custom encodings

KALITAM.
(1913)

50/52

fontspec – selecting fonts
Custom encodings

KALITAM.
(1919)

50/52

fontspec – selecting fonts
Custom encodings

KALITAM.
(1927)

50/52

fontspec – selecting fonts
Custom encodings

KALITAM.
(1933)

50/52

fontspec – selecting fonts
Custom encodings

50/52

KALITAM.
(1945)

fontspec – selecting fonts
Custom encodings

50/52

KALITAM.
(1984)

fontspec – selecting fonts
Custom encodings

KALITAM.
(2001)

50/52Conclusion

Introduction
unicode-math – modern expl3 package development
Code structure
CHANGES ﬁleexpl3 conventions
Git branches
Test suite
Release checklist
fontspec – selecting fonts
Font loading
The interface for font features
Typical example‘Strong’ emphasis
Custom encodings
Conclusion

51/52

Conclusion

Conclusion• Thanks to everyone(too many to count but especially [redacted])• Thanks for patience• Obrigado

52/52