2

What is the lualatex (via fontspec) equivalent of the css font-weight: 541; that allows us to choose continuously a font weight (bold/semi bold…) in a continuous fashion, when a font uses the "variable font" standard?

Also, how can I check if a font supports variable fonts, and what parameters I can tune? For instance, the Robotto flex font (download) listed on this page provides many tunable features like wght, wdth, opsz… as can be seen in https://v-fonts.com/

I found how to enable boolean fonts features (equivalent of css font-feature-settings), where the low-level feature (listed with otfinfo -f yourfile.ttf) is mapped to the high level option in table 4 of https://mirror.lyrahosting.com/CTAN/macros/unicodetex/latex/fontspec/fontspec.pdf, but I cannot find how to list/enable variable font options…

MWE

\documentclass[]{article}
\usepackage{xcolor}
\usepackage{fontspec}

\begin{document}

\NewDocumentCommand{\myText}{O{}O{}}{\makebox[4.5cm][l]{#1:} {#2{Here is a test of me changing fonts}}}

\myText[Default]

%% In optional argument, we can enable font features (the one that you can see when typing otfinfo -f yourfile.ttf), where
%% fontspec translates 4 letter features like "kern" into a more user-friendly interface. The map between low-level and high-level is given
%% in table 4 page 38 of https://mirror.lyrahosting.com/CTAN/macros/unicodetex/latex/fontspec/fontspec.pdf

\fontspec[]{Times New Roman} \myText[Times New Roman]

\fontspec[]{Times New Roman} \myText[Bold Times New Roman][\textbf]

\fontspec[AutoFakeBold=3]{Times New Roman} \myText[Fake Bold Times New Roman][\textbf]

\fontspec[AutoFakeBold=5]{Times New Roman} \myText[Fake Bold Times New Roman][\textbf]

%% Download here https://github.com/googlefonts/roboto-flex/blob/main/fonts/RobotoFlex%5BGRAD%2CXOPQ%2CXTRA%2CYOPQ%2CYTAS%2CYTDE%2CYTFI%2CYTLC%2CYTUC%2Copsz%2Cslnt%2Cwdth%2Cwght%5D.ttf
\fontspec{RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf} \myText[RobotoFlex]
\fontspec{RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf} \myText[Bold RobotoFlex][\textbf]

%% How to enable weight/width/opsz/… as we can in https://v-fonts.com/ for this font? 

\end{document}

%%% Local Variables: 
%%% mode: latex 
%%% TeX-engine: luatex
%%% TeX-master: t 
%%% End:

EDIT

As suggested in comments, I tried to use RawFeature={+axis={wght=900}} and it seems to work, except for some buggy letters, like i on weight 100 or o in weight 900:

https://imgur.com/682ULtS

(sorry I can't post any image here, seems to be broken)

I tried to use another PDF viewer (okular, firefox & chromium: all of them print the same buggy output). Also, do you know how to list all available axis and their default values?

MWE

\documentclass[]{article}
\usepackage{xcolor}
\usepackage{fontspec}

\begin{document}

\NewDocumentCommand{\myText}{O{}O{}}{\makebox[4.5cm][l]{#1:} {#2{Here is a test of me changing fonts}}}

\myText[Default]

%% In optional argument, we can enable font features (the one that you can see when typing otfinfo -f yourfile.ttf), where
%% fontspec translates 4 letter features like "kern" into a more user-friendly interface. The map between low-level and high-level is given
%% in table 4 page 38 of https://mirror.lyrahosting.com/CTAN/macros/unicodetex/latex/fontspec/fontspec.pdf
\fontspec[]{Times New Roman} \myText[Times New Roman]

\fontspec[]{Times New Roman} \myText[Bold Times New Roman][\textbf]

\fontspec[AutoFakeBold=3]{Times New Roman} \myText[Fake Bold Times New Roman][\textbf]

\fontspec[AutoFakeBold=5]{Times New Roman} \myText[Fake Bold Times New Roman][\textbf]

%% Download here https://github.com/googlefonts/roboto-flex/blob/main/fonts/RobotoFlex%5BGRAD%2CXOPQ%2CXTRA%2CYOPQ%2CYTAS%2CYTDE%2CYTFI%2CYTLC%2CYTUC%2Copsz%2Cslnt%2Cwdth%2Cwght%5D.ttf
\fontspec{RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf} \myText[RobotoFlex]

\fontspec{RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf} \myText[Bold RobotoFlex][\textbf]

\fontspec[RawFeature={+axis={wght=100}}]{RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf} \myText[Bold RobotoFlex][\textbf]

\fontspec[RawFeature={+axis={wght=900}}]{RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf} \myText[Bold RobotoFlex][\textbf]

%% How to enable weight/width/opsz/… as we can in https://v-fonts.com/ for this font? 

\end{document}

%%% Local Variables: 
%%% mode: latex 
%%% TeX-engine: luatex
%%% TeX-master: t 
%%% End:


8
  • 1
    Have you already tried something like tex.stackexchange.com/q/700597/36296 ? Jan 30 at 16:11
  • you can directly access the variable font parameters so use the same settings as css Jan 30 at 16:23
  • @samcarter_is_at_topanswers.xyz Oh good point, thanks! it seems to work more or less… except for some buggy letters. Is there some options I need to enable/disable to get this printed correctly?
    – tobiasBora
    Jan 30 at 17:13
  • @DavidCarlisle You meant using RawFeature={+axis={wght=900}}? (not so trivial, maybe the doc could add a line on this) Seems to work more or less, except for some buggy letters… do you know what got wrong (cf my edit)
    – tobiasBora
    Jan 30 at 17:14
  • 1
    can't you claim the phase-of-the-moon i is a feature and call it done? :-) Jan 30 at 17:18

1 Answer 1

4

The idea is to use:

\fontspec[RawFeature={+axis={wght=900}}, Renderer=Harfbuzz]{yourfont.ttf}

(the Renderer=Harfbuzz is just used to avoid some glitches I got, works out of the box with LuaLaTeX)

The wght is the name of the axis. You can have in variable fonts many axis, but also presets (aka instance) to set them automatically. For instance, you can load the ExtraBlack Italic preset using:

\fontspec[Renderer=Harfbuzz, RawFeature={instance={ExtraBlack Italic}}]{yourfont.ttf}

To get the list of these axis/instances, there are many different ways:

  • The easier if you have access to the documentation of the font is to use it. For instance, the page https://v-fonts.com/ specifies directly the list of axis like: enter image description here

  • If you do not have access to the documentation, but if it is loaded in the browser, you can use Firefox debug tools: right click on the text, and click "Inspect", then go to the right most pannel, make sure that "Font" is enabled (you might need to right click the arrow and enlarge the pannel), and you have all axis listed, even with the max/min values (you can even play with the cursor to find the ideal font setting for you): enter image description here

  • If your font is not loaded in your browser, you can also use a website like https://lorp.github.io/samsa/src/samsa-gui.html (open source, and extremely complete, the best one in my opinion) enter image description here or https://opentype.js.org/font-inspector.html (open source) and check the fvar section (sadly as far as I see on this website you cannot directly play with the cursor yourself), with the value of the axis and presets: enter image description here

    There are also other more fancy (closed source) websites like https://wakamaifondue.com/, https://fontdrop.info/ or https://www.axis-praxis.org/, where you can tune the value: enter image description here Unfortunately, for the last two websites, it seems like these tools only print the "pretty" version of the axis name instead of their true name. To get the true, 4 letter name, I use, again firefox: enter image description here

  • As far as I see, otfinfo can print features, with -f, but not the axis directly, you can only do otfinfo -t yourfont and check if there is a fvar table in the list (if you dump it, it will just be binary). With the command line, I could only find a solution using ttx from fontforge-fonttools (this is the name in nix package manager, you might need to install fonttools or something else for you): in that case run:

$ ttx -t fvar RobotoFlex\[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght\].ttf

and it will create a .ttx file (the name is in the output of this command), containing the presets and the axis names/default value/min/max, with something like:

<?xml version="1.0" encoding="UTF-8"?>
<ttFont sfntVersion="\x00\x01\x00\x00" ttLibVersion="4.38">

  <fvar>

    <!-- Optical Size -->
    <Axis>
      <AxisTag>opsz</AxisTag>
      <Flags>0x0</Flags>
      <MinValue>8.0</MinValue>
      <DefaultValue>14.0</DefaultValue>
      <MaxValue>144.0</MaxValue>
      <AxisNameID>256</AxisNameID>
    </Axis>

    <!-- Weight -->
    <Axis>
      <AxisTag>wght</AxisTag>
      <Flags>0x0</Flags>
      <MinValue>100.0</MinValue>
      <DefaultValue>400.0</DefaultValue>
      <MaxValue>1000.0</MaxValue>
      <AxisNameID>257</AxisNameID>
    </Axis>

…


    <!-- Thin -->
    <NamedInstance flags="0x0" subfamilyNameID="269">
      <coord axis="opsz" value="14.0"/>
      <coord axis="wght" value="100.0"/>
      <coord axis="GRAD" value="0.0"/>
      <coord axis="wdth" value="100.0"/>
      <coord axis="slnt" value="0.0"/>
      <coord axis="XOPQ" value="96.0"/>
      <coord axis="YOPQ" value="79.0"/>
      <coord axis="XTRA" value="468.0"/>
      <coord axis="YTUC" value="712.0"/>
      <coord axis="YTLC" value="514.0"/>
      <coord axis="YTAS" value="750.0"/>
      <coord axis="YTDE" value="-203.0"/>
      <coord axis="YTFI" value="738.0"/>
    </NamedInstance>

    <!-- ExtraLight -->
    <NamedInstance flags="0x0" subfamilyNameID="270">
      <coord axis="opsz" value="14.0"/>
      <coord axis="wght" value="200.0"/>
      <coord axis="GRAD" value="0.0"/>
      <coord axis="wdth" value="100.0"/>
      <coord axis="slnt" value="0.0"/>
      <coord axis="XOPQ" value="96.0"/>
      <coord axis="YOPQ" value="79.0"/>
      <coord axis="XTRA" value="468.0"/>
      <coord axis="YTUC" value="712.0"/>
      <coord axis="YTLC" value="514.0"/>
      <coord axis="YTAS" value="750.0"/>
      <coord axis="YTDE" value="-203.0"/>
      <coord axis="YTFI" value="738.0"/>
    </NamedInstance>

See also https://www.overleaf.com/learn/latex/Articles/An_overview_of_technologies_supporting_the_use_of_colour_emoji_fonts_in_LaTeX

MWE:

\documentclass[]{article}
\usepackage{xcolor}
\usepackage{fontspec}

\begin{document}

\NewDocumentCommand{\myText}{O{}O{}}{\makebox[4.5cm][l]{#1:} {#2{Here is a test of me changing fonts}}}

\myText[Default]

%% In optional argument, we can enable font features (the one that you can see when typing otfinfo -f yourfile.ttf), where
%% fontspec translates 4 letter features like "kern" into a more user-friendly interface. The map between low-level and high-level is given
%% in table 4 page 38 of https://mirror.lyrahosting.com/CTAN/macros/unicodetex/latex/fontspec/fontspec.pdf
\fontspec[]{Times New Roman} \myText[Times New Roman]

\fontspec[]{Times New Roman} \myText[Bold Times New Roman][\textbf]

\fontspec[AutoFakeBold=3]{Times New Roman} \myText[Fake Bold Times New Roman][\textbf]

\fontspec[AutoFakeBold=5]{Times New Roman} \myText[Fake Bold Times New Roman][\textbf]

%% Download here https://github.com/googlefonts/roboto-flex/blob/main/fonts/RobotoFlex%5BGRAD%2CXOPQ%2CXTRA%2CYOPQ%2CYTAS%2CYTDE%2CYTFI%2CYTLC%2CYTUC%2Copsz%2Cslnt%2Cwdth%2Cwght%5D.ttf
\fontspec{RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf} \myText[RobotoFlex]

\fontspec{RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf} \myText[Bold RobotoFlex][\textbf]

\fontspec[Renderer=Harfbuzz, RawFeature={+axis={wght=100}}]{RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf} \myText[Weight 100 RobotoFlex][\textbf]

\fontspec[Renderer=Harfbuzz, RawFeature={+axis={wght=300}}]{RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf} \myText[Weight 300 RobotoFlex][\textbf]

\fontspec[Renderer=Harfbuzz, RawFeature={+axis={wght=500}}]{RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf} \myText[Weight 500 RobotoFlex][\textbf]

\fontspec[Renderer=Harfbuzz, RawFeature={+axis={wght=700}}]{RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf} \myText[Weight 500 RobotoFlex][\textbf]

\fontspec[Renderer=Harfbuzz, RawFeature={+axis={wght=900}}]{RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf} \myText[Weight 900 RobotoFlex][\textbf]

\fontspec[Renderer=Harfbuzz, RawFeature={instance={ExtraBlack Italic}}]{RobotoFlex[GRAD,XOPQ,XTRA,YOPQ,YTAS,YTDE,YTFI,YTLC,YTUC,opsz,slnt,wdth,wght].ttf} \myText[ExtraBlack Italic][\textbf]

\end{document}

%%% Local Variables: 
%%% mode: latex 
%%% TeX-engine: luatex
%%% TeX-master: t 
%%% End:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .