1

I am trying to use some fonts installed on my computer with typescript as explained in this post in order to create some fancy titles but I have a strange issue with \setuphead.

Here is an example with \switchtobodyfont in \setuphead's style:

\starttypescriptcollection [fira]
  \starttypescript [sans] [fira]
    \setups[font:fallback:sans]
    \definefontsynonym [Sans]           [file:FiraSans-Regular.otf]       [features=default]
    \definefontsynonym [SansItalic]     [file:FiraSans-RegularItalic.otf] [features=default]
    \definefontsynonym [SansBold]       [file:FiraSans-Bold.otf]          [features=default]
    \definefontsynonym [SansBoldItalic] [file:FiraSans-BoldItalic.otf]    [features=default]
    \definefontsynonym [SansCaps]       [file:FiraSans-Regular.otf]       [features={default,smallcaps}]
  \stoptypescript

  \starttypescript [mono] [fira]
    \setups[font:fallback:mono]
    \definefontsynonym [Mono]     [file:FiraMono-Medium.otf] [features=default]
    \definefontsynonym [MonoBold] [file:FiraMono-Bold.otf]   [features=default]
  \stoptypescript

  \starttypescript [math] [fira]
    \definefontsynonym [MathRoman] [file:Fira-Math.otf] [features=mathextra]
  \stoptypescript

  \starttypescript [fira]
    \definetypeface [\typescriptone] [rm] [serif] [modern] [default]
    \definetypeface [\typescriptone] [ss] [sans]  [fira]   [default]
    \definetypeface [\typescriptone] [tt] [mono]  [fira]   [default]
    \definetypeface [\typescriptone] [mm] [math]  [fira]   [default]
    \quittypescriptscanning
  \stoptypescript
\stoptypescriptcollection



\setuphead[section][style={\switchtobodyfont[fira,sans]}]

\starttext
  \section{section 1}
  \section{section 2}
  \section{section 3}
\stoptext

What do happens here?

3
  • 2
    The line endings for each \definefontsynonym settings add spaces when you load the font for the first time, to avoid this you can move the typescript settings in a separate file (e,g. type-fira.tex) which is loaded \switchtobodyfont or you preload the typescript with \usetypescript[fira]. Commented Jun 16, 2020 at 17:21
  • Neat, it works like a charm! Why does it add spaces for first load of the font? Commented Jun 16, 2020 at 17:27
  • @WolfgangSchuster: Your comment-answers are awesome. For posterity, it may be helpful to others to see them as answer-answers to make them more visible. Especially when there's a sweet checkmark for emphasis. (I sometimes overlook answers in comments, given the nature of the SE network's Q&A format.) Commented Jun 24, 2020 at 18:31

1 Answer 1

1

When you write typescripts for a new font ConTeXt stores these settings but no fonts are loaded at this point, this allows complicated typescript defintions where the upright, italic. etc styles can be changed when the fonts are loaded which is usefull for large font families.

Once you create a typeface with the \definetypeface commands ConTeXt loads all the necessary typescripts which can be a problem when you do this within regular text, because many line ends in typescripts blocks produce extra spaces with appear now in the output.

In the example below I create a simple typescript for the TeX Gyre Pagella font. The problem is that I load the font in a \hbox which flushes all spaces from my typescripts in horizontal mode.

\starttypescript [serif] [tex-gyre-pagella]
    \definefontsynonym [Serif]           [file:texgyrepagellaregular]    [features=default]
    \definefontsynonym [SerifItalic]     [file:texgyrepagellaitalic]     [features=default]
    \definefontsynonym [SerifBold]       [file:texgyrepagellabold]       [features=default]
    \definefontsynonym [SerifBoldItalic] [file:texgyrepagellabolditalic] [features=default]
\stoptypescript

\starttypescript [tgy]
    \definetypeface [tgy] [rm] [serif] [tex-gyre-pagella]
\stoptypescript

\starttext

\ruledhbox{\strut\space}

\ruledhbox{\strut\space\switchtobodyfont[tgy]}

\ruledhbox{\strut\space\ntimes{\kern\spaceamount}{5}}

\stoptext

Each linebreak in my typescript at the end of the \definefontsynonym settings creates a visible space and a additional space is created from the \definetypeface setting.

enter image description here

To avoid this problem you can drop the typescript environment for the \definetypeface commands which loads all necessary typescript before you load the fonts, e.g.

\definetypeface [tgy] [rm] [serif] [tex-gyre-pagella]

or you preload the typescript you want to use before you load it in your document, e.g.

\usetypescript[tgy]

You must log in to answer this question.