# TeX (LuaTeX, XeTeX, fontspec) support for OpenType variable fonts

Is anyone working on implementing support for the new OpenType variable fonts in any TeX/LaTeX implementation like XeTeX or LuaTeX? Will fontspec support accessing the new tables?

• It is in harfbuzz 1.4 so I assume it will get into xetex one way or another once xetex gets to that version of harfbuzz github.com/behdad/harfbuzz/releases – David Carlisle Feb 22 '17 at 11:30
• for luatex it's been asked: tug.org/pipermail/luatex/2016-September/006204.html – David Carlisle Feb 22 '17 at 12:43
• @DavidCarlisle: Note that HarfBuzz is only concerned about the layout part, one still needs to handle generating font instances to be embedded in the PDF, which means xdvipdfmx will need to support that before being able to use variable fonts in XeTeX (same is true for LuaTeX as well). There is also the possibility of an external program creating the instances and being called some how by XeTeX/LuaTeX on demand, then the instances will be used like any other fonts. – Khaled Hosny Feb 28 '17 at 21:32
• beta version of context supports variable fonts, but it is still experimental. see mailman.ntg.nl/pipermail/ntg-context/2017/088343.html – michal.h21 Apr 23 '17 at 17:52
• – stone-zeng Dec 18 '19 at 17:15

It is supported in luatex now(version 1.13.0):

\documentclass[a4paper,12pt]{article}
\usepackage{fontspec}
\defaultfontfeatures{RawFeature={+axis={wght=100}}}
\setmainfont[
ItalicFont=SourceSansVariable-Italic.otf,
BoldFont=SourceSansVariable-Roman.otf,
BoldItalicFont=SourceSansVariable-Italic.otf,
BoldFeatures={RawFeature={+axis={wght=900}}},
BoldItalicFeatures={RawFeature={+axis={wght=900}}}
]{SourceSansVariable-Roman.otf}
\begin{document}
\par the quick brown fox jumps over the lazy dog.
\par\textit{the quick brown fox jumps over the lazy dog.}
\par\textbf{the quick brown fox jumps over the lazy dog.}
\par\textbf{\textit{the quick brown fox jumps over the lazy dog.}}
\end{document}


It works pretty well in most of cases, but when the font width is changed(including some of fonts that will change width according to weight), the space between some of the characters, like double quotes and ligaments(fi, fl), will become too wide(when the actual width of changed font is smaller than regular) or too narrow(when the actual width of changed font is bigger than regular).

The document of luaotfload(version 3.17) says that varible fonts are only supported in base and node mode, not in harf mode.

• Tried it (with source serif 4 variable) and got a Type2 Charstring Parser: subroutine called but no subroutine found error. Any clue? – Callegar Apr 13 at 14:03
• @Callegar: I‘ve test source serif 4 variable, which works well. I don't know what the error "Type2 Charstring Parser" means, but from other questions in stackexchange, it seems that this error is related to symbols not supported by the used font. – lamda05 Apr 13 at 16:37
• @lambda05, thanks for commenting. I'll give it another try based on your feedback, using a minimal document. So far I tried with a document I had already but that is a bit complex, making it hard to try to identify the culprit when something goes wrong. What makes me wonder is that the document does actually compile fine with the non-variable version of Source Serif 4, so all the used symbols should actually be present in the font. – Callegar Apr 14 at 14:22
• @lambda05... even something as simple as \documentclass{article} \usepackage{fontspec} \setmainfont{Source Serif 4 Variable} \begin{document} This is a text \end{document} fails for me... – Callegar Apr 15 at 9:33
• @lambda05 Weird enough, your example with source sans variable works (my font name is SourceSans3VF, but it is enough to fix that to have the code work) – Callegar Apr 15 at 9:40

A little addendum to the answwer by @lambda05 that is quite good. Be careful that the

\defaultfontfeatures{RawFeature={+axis={wght=100}}}


appears to be absolutely needed (at least with the lualatex, fontspec, luaotfload combination available in Apr 2021). Otherwise LuaLaTeX errors out with an error:

(cff): Type2 Charstring Parser: subroutine called but no subroutine found


This is due to the fact that while luaotfload has now support for variable fonts, activation of this support is not yet automatic and only happens following the presence of an axis or instance parameter. According to bug 120 on the luaotfload tracker attempts at making the activation automatic should be made soon.

• if you think there is a bug, open an issue at the luaotfload issue tracker. – Ulrike Fischer Apr 23 at 13:55