# [NTG-context] issue with italic correction (again)

Taco Hoekwater taco at elvenkind.com
Thu Jun 27 10:54:01 CEST 2019


> On 26 Jun 2019, at 21:53, Pablo Rodriguez <oinos at gmx.es> wrote:
>
> On 6/25/19 10:08 PM, Taco Hoekwater wrote:
>>> Op 25 jun. 2019 om 21:42 heeft Pablo Rodriguez het volgende geschreven:
>>>
>>> BTW, I wonder why the second definition of \DesiredFont doesn’t change
>>> the font for the buffer used after it.
>>
>> Using \switchtobodyfont instead of \setupbodyfont for all except the
>> first call should help. You may need to add a
>> \usebodyfont[mainface_corrected] as well (in the setup block). I
>> cannot actually test right now, on a mobile device...
>
>
> I’m afraid that I cannot make it work.
>
> I guess I must be doing something wrong.

No, it is not you.

The problem is that \definefontfamily always expands its arguments
completely, so by the time you call the body font up, it will already
contain the actual font name instead of the macro \DefinedFont.

(I had to test that for myself first)

Also, it seems that \definefontfamily does not like redefinitions.

(I had to test that for myself as well)

>
> I’d like to know which are the differences among \setupbodyfont,
> \switchtobodyfont and \usebodyfont.

Generally, you use \setupbodyfont exactly once, in the setup area.
This sets up the fonts for the whole document, and it also sets up
some values for the ‘global environment’ (various internals use the body
font size, for instance).

If you do not call \setupbodyfont yourself, then ConTeXt will do an implicit

\setupbodyfont[modern,12pt]

at the \starttext command, just to make sure there is a valid
body font defined.

If you want to use other body font definitions as well, you can use

\usebodyfont[mainface_corrected] % etc.

which temporarily switches to the specified body font set, but immediately
switches back to whatever was active before. It exists mostly for
cosmetic reasons. ;)

When you want to switch to any of the preloaded body font sets inside your
document, you normally would use \switchtobodyfont. This only affects the
document text, not headers and footers, and does also not do the global setup.

You could use \setupbodyfont instead, but \switchtobodyfont is usually what
you want, and it is also a bit faster.

Anyway, about your example: here is a version that does do the switching:

\definefontfeature[italic][itlc=yes,textitalics=yes]
\setupitaliccorrection[global, always]
\starttext
\startbuffer[chars]
\definefontfamily
[mainface\DesiredFont]
[rm]
[\DesiredFont]
\definefontfamily
[mainface_corrected\DesiredFont]
[rm]
[\DesiredFont]
[features={italic}]
\startTEXpage[offset=1em]
\dorecurse{26}
{\switchtobodyfont[mainface\DesiredFont]%
[{\em \recurselevel}]
[{\em \characters{\recurselevel}}]
[{\em \Characters{\recurselevel}}]
({\em \characters{\recurselevel}})
({\em \Characters{\recurselevel}})
\hfill
\switchtobodyfont[mainface_corrected\DesiredFont]
[{\em \recurselevel}]
[{\em \characters{\recurselevel}}]
[{\em \Characters{\recurselevel}}]
({\em \characters{\recurselevel}})
({\em \Characters{\recurselevel}})
\par}
\stopTEXpage
\stopbuffer
\def\DesiredFont{TeX Gyre Termes}
\getbuffer[chars]
\def\DesiredFont{TeX Gyre Pagella}
\getbuffer[chars]
\stoptext

Best wishes,
Taco