On Thu, Oct 22, 2026 at 09:02 (+0200), Hans Hagen via ntg-context wrote:

> On 10/22/2026 3:45 AM, Jim Diamond via ntg-context wrote:

>> I find this interesting because of the fact that it is inside a group.  I
>> suppose if there is some \global\def inside \switchtobodyfont (or some
>> other use of \global} it would explain the effect.

> yes, some things local, some things global, a \switch... assumes a \use...
> or \setup...

So I begin to wonder whether there is something inside \switchtobodyfont
(or some macro it calls) which should be global but is not.

>>> In that discussion, Hans and Wolfgang explained aspects of the relationship
>>> between |\setupbodyfont|, |\usebodyfont|, and |\switchtobodyfont|.

>>> In particular, Hans recommended preparing the required body-font families
>>> before |\starttext|.

>>> *2. April 2025* — Initializing a typeface inside a local group

> indeed
>>> https://lists.contextgarden.net/archives/list/[email protected]/thread/LRMIHD5PPSTDW2EOVBO76KHZJWS4HSPV/
>>>  
>>> <https://lists.contextgarden.net/archives/list/[email protected]/thread/LRMIHD5PPSTDW2EOVBO76KHZJWS4HSPV/>

>>> In this exchange, Wolfgang explained that when a typeface is initialized for
>>> the first time inside a local group, some settings may be lost when the
>>> group ends.
> indeed

>>> His suggested solution was to preload the relevant family globally, for
>>> example:

>>>> \usebodyfont[dejavu] \setupbodyfont[modern]|

>>> These discussions seem closely related to Jim's observations, although we
>>> cannot assume that the underlying mechanism is necessarily identical in the
>>> current LMTX implementation.

> indeed

>>>       _A possible first test?_

>>> Jim, would you be willing to try explicitly preloading Schola in the
>>> preamble?

>>> For example:

>>>> \usefontpath[NCMS] \usebodyfont[newcomputermodern] \usebodyfont[schola]
>>>> \setupbodyfont[modern]|

>> Adding the \usebodyfont[schola] does indeed fix the problem, thanks.

>> Unfortunately, that apparently (?) means that one has to
>>          \usebodyfont[XYZ]
>> for every font in the document.  This is problematic and error-prone in a
>> large document which uses many fonts.

> how many different fonts do you mix? a single font can en \definefont'd

Lots, as it turns out.

As mentioned in my recent mail to the list, this is for ANSS-CE.

ANSS-CE (like ANSS) has a table showing many of the fonts that are
available with ConTeXt stand-alone without having to install other fonts,
and without having to assume that your OS has some particular font.

So there are many fonts loaded.  I have been "picking on" Schola because it
is the first font table displayed in ANSS-CE after the table showing all
(most?) of the fonts available with stand-alone.  I am guessing that if I
tried adding font tables for some of the other fonts, equivalent Bad Things™
would happen.

>> Thus, while it is a pragmatic work-around, I feel that it is not an elegant
>> solution.

> well, you can load later on, but don't do it in a group .. \tracingall at
> the top of your document can educate you on what happens with fonts

Hmmm... 1,059,247 lines in the log file, and counting.
That is too much education for this morning. :-)

Even   grep font test-ncm-effects.log  has just under 74,000 lines.
There's a lot of stuff going on!

>>> The remainder of your minimal example could remain unchanged, including the
>>> grouped |\setbox0=\hbox{...}|line.

>>> If the resulting |\showbodyfont[schola,8pt]|table becomes correct, this
>>> would support the hypothesis that the problem is related to the first
>>> initialization of Schola inside a local group.

>> Indeed.  And why would that be?

> all depends on definitions being local, global, remembered, etc .. and also
> with having a system thst handles a lot and still has th be fast

Do you think it is possible that changing some definition to a \global
might help, or is that far too simplistic a question?

>>> Of course, it would not yet explain why preloading New Computer Modern seems
>>> to influence the behaviour.

>> Indeed.  And why would that be?

> when something is not found you are stuck with whatever font was active
> that time which then takes it place which of course is unpredictable

Hmmm... now we are on to something (I think).  New example at bottom.

>>>       _Comparing two LMTX releases:_

>>> There is another experiment that might help distinguish an existing feature
>>> of font initialization from a possible change introduced in a recent
>>> release.

>>> We could therefore compile the same minimal example under two different
>>> ConTeXt releases:

>>> Test        ConTeXt version         |\usebodyfont[schola]|
>>> A   2026.10.01      Absent
>>> B   2026.10.01      Present
>>> C   2026.10.16      Absent
>>> D   2026.10.16      Present

>>> For the comparison to be meaningful, the same font files and identical
>>> source code should be used, with separate caches and formats for each
>>> installation.

>> So far my tests on three different stand-alone versions all show the same
>> results.

>> The version in TL2026 works, but I suspect that is because TL2026 has the
>> New CM fonts already included.  The log file indicates those files are
>> read, rather than the ones supplied in ./NCMS.

> guess so, see other mail: put them in a known spot, one where the system
> searches for 'otf' files (tds compliant ...)

As mentioned, that is a local solution for me, but not a global solution.

>>> It would also be useful to retain the original grouped construction in all
>>> four tests:

>>>> {\setbox0=\hbox{\switchtobodyfont[schola] Schola!!!}}|

I should mention that even if the above line is
    \setbox0=\hbox{\switchtobodyfont[schola] Schola!!!}
the same issue happens.  Presumably entering internal horizontal mode to
create the hbox enters a group (or does actions similar to entering a group).

>>> We could then perform a second comparison in which Schola is selected once
>>> outside the group before this line is executed.

>>> Several outcomes would be informative.

>>> If the behaviour is identical in both releases, it may reflect an
>>> established characteristic of font initialization and grouping.

>>> If the anomaly occurs only with the October 16 release, we may have
>>> identified a possible regression.

>> I think that turns out not to be the case.  Which is too bad, because if it
>> was we all know someone who would be keen to fix it.  ;-)

> the font system (unless wolfgang finds a bug) will not be made more complex
> than it already is

I fully support (for what my opinion is worth) not making things more
complex.  However, I also shy away from claiming any non-trivial piece of
software is bug-free.

> (we might at some point remove non-compct mode code which is not used;
> even drop the design sizes as one can just define additional typescripts
> and so a switch)

>>> If explicitly preloading Schola eliminates the anomaly in both versions, we
>>> would at least have a reproducible workaround and a clearer indication of
>>> where the problem originates.

>> You may have a clearer indication.  I remain boggled.  ;-)

>>> One remaining question:

>>> What I find particularly intriguing is the interaction between:

>>>> \usebodyfont[newcomputermodern]|

>>> and the first local invocation of:

>>>> \switchtobodyfont[schola]|

>>> Are we simply observing the consequences of delayed typeface
>>> initialization within a TeX group, or is something else involved in the
>>> way the different body-font collections are registered?

>> I look forward to someone answering that question.

> Just think of what needs to be done if we load local.  Do you really want to
> load all the stuff again and again when you do it in 50 boxes?

No, but... if it is difficult or impossible to ensure everything is
properly initialized globally when a font is introduced inside a group,
then (since I'm a bit obsessive-compulsive about this) I'd take correct
behaviour over speed.

Now that I think about it, I do recall that in some other system (probably
pdftex using plain TeX) I did run into some similar issue where, if
something was first used inside a group, Bad Things™ happened.  But the
specifics are currently lost in the depths of time.

> Normally a choice for a font is global.

Which makes good sense.

>>> The earlier explanations from Hans and Wolfgang suggest a possible
>>> direction, but I think the comparison between the two LMTX releases could
>>> help us establish what is actually happening.

> dunno, did font definition files change then? how do the logs compare
> (there's more than on the console)?

The difference between TeXlive and stand-alone is (apparently) that if
context finds the font in some cached "usual place" then it doesn't try to
use the font file in the \usefontpath directory.  Why exactly that works
when getting the font from the \usefontpath directory is another
interesting (to me) thing.

>>> I haven't reproduced the anomaly myself, so these are hypotheses rather than
>>> conclusions.

>> Lack of time or did the anomaly not happen for you?

>>> Still, the experiments seem straightforward enough, and the results might
>>> be useful to others working with several font families in the same
>>> document.

>>> Jim, perhaps an earlier ConTeXt release will prove useful for something more
>>> interesting than simply keeping a stable installation at hand!

>> Not in this case, although keeping a stable installation certainly has some
>> benefits.

>>> Many thanks to Wolfgang and Hans for their explanations, and to Jim for
>>> providing such a revealing example.

>> Thanks for your thoughts and pointers to those other discussions.

> Now, does the simple example i sent you work with fonts put in the right
> spot? No \hbox ... just a tufte test

You mean this one:

\usetypescriptfile[newcomputermodern]
\setupbodyfont[newcomputermodern]
\starttext
\startchapter[title={Fun with Fonts in \ConTeXt}]
\showbodyfont[8pt]
\stopchapter
\stoptext

Yes, that works fine with TL.

But this:
\usepath[allncmfonts]
\usetypescriptfile[newcomputermodern]
\setupbodyfont[newcomputermodern]
\starttext
\startchapter[title={Fun with Fonts in \ConTeXt}]
\showbodyfont[8pt]
\stopchapter
\stoptext
errors out on the \showbodyfont[8pt] line, even when the entire set of
fonts from newcm-8.1.1.txz is in ./allncmfonts.


Above I mentioned a "new example at bottom".  Here it is:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\setupbodyfont[modern]

\usefontpath[NCMS]
\usetypescriptfile[newcomputermodern]

\starttext

\startchapter[title=Fun with Fonts in \ConTeXt,]

Hello

% Commenting this out makes the table below higher: 131.45134 pt vs. 123.45783 
pt.
%\setbox0=\hbox{\switchtobodyfont[schola] Schola!!!}

\showbodyfont[schola,8pt]\bigskip

\setbox1=\vbox{\showbodyfont[schola,8pt]}
That box is \the\wd1 \ wide by \the\ht1 \ high.\blank

{\switchtobodyfont[newcomputermodern,small,ss]
 This is a line of text. {\sc This {\it is} 1 \tex{sc} {\em line} {\tt of} {\bf 
text.}}
}

\stopchapter
\stoptext
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Starting with \setupbodyfont[modern] makes the Schola table show up (more
or less (*)) correctly regardless of whether the \setbox0 line is commented.

So perhaps the solution to my original question is the following:
start with \setupbodyfont[modern] so that some things get defined

(*)

However, still something is a bit funny, because with the setbox0 line 
commented,
\box1 is 131+ pts high, whereas it is only 123+ pts high with the line
uncommented.

Since the same curious thing happens with the \usefontpath and
\usetypescriptfile lines commented out, I conclude that this peculiar thing
is not related to trying to use New CM.

But what parameters are changing (or not changing) when the first use of
Schola is inside an \hbox{}?


So many questions about fonts, so little time ...


                                Jim



___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : [email protected] / 
https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl
webpage  : https://www.pragma-ade.nl / https://context.aanhet.net (mirror)
archive  : https://github.com/contextgarden/context
wiki     : https://wiki.contextgarden.net
___________________________________________________________________________________

Reply via email to