11

In (Lua-)LaTeX with fontspec there is an option called Scale=MatchLowercase (as well as some similar ones like Scale=MatchUppercase) which would try to automatically detect a scale to match the fonts.

A LaTeX example:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{EB Garamond}
\setmonofont{Fira Mono}
\begin{document}
Test {\ttfamily Test}

\setmonofont{Fira Mono}[Scale=MatchUppercase]
Test {\ttfamily Test}
\end{document}

As one may see, the second line does look well-scaled in comparison to the first (I confess that with this font choice "well-scaled" is a very euphemistic term).

So in ConTeXt MkIV I would have the following setup:

\definefontfamily [testdoc] [rm] [EB Garamond]
\definefontfamily [testdoc] [tt] [Fira Mono]
\setupbodyfont    [testdoc]

\starttext
    Test {\tt Test}
\stoptext

Unfortunately, I only know of the rscale option. Is there a similar heuristic to determine a scale automatically?

(It does not have to be possible to change it mid-document, one that works at \definefontfamily would suffice. Also, I am not bound to simplefonts.)

11

Short answer: No

In MkII, you could pass the option rscale=auto to \definetypeface to get automatic scaling. This feature hasn't been ported to MkIV.

In MkIV, there was an experimental feature to support automatic scaling of fonts, but it has been disabled. The following example is taken from font-ini.mkvi

\enableexperiments[fonts.autorscale]

\starttypescript[mscore]
    \definetypeface [mscore] [rm] [serif] [mscoretimes]   [default]
    \definetypeface [mscore] [ss] [sans]  [mscorearial]   [default] [rscale=auto] % 0.860]
    \definetypeface [mscore] [tt] [mono]  [mscorecourier] [default] [rscale=auto] % 1.065]
    \definetypeface [mscore] [mm] [math]  [times]         [default] [rscale=auto] % 1.020]
\stoptypescript

\starttext
   \setupbodyfont[mscore,12pt]
   \startTEXpage
       test \ss test \tt test
   \stopTEXpage
\stoptext

but it does not work because the relevant code is commented out from font-ctx.lua

 -- if enable_auto_r_scale and relativeid then -- for the moment this is rather context specific (we need to hash rscale then)
 --     local relativedata = fontdata[relativeid]
 --     local rfmdata = relativedata and relativedata.unscaled and relativedata.unscaled -- just use metadata instead
 --     local id_x_height = rfmdata and rfmdata.parameters and rfmdata.parameters.x_height
 --     local tf_x_height = tfmdata and tfmdata.parameters and tfmdata.parameters.x_height
 --     if id_x_height and tf_x_height then
 --         local rscale = id_x_height/tf_x_height
 --         delta = rscale * delta
 --         scaledpoints = rscale * scaledpoints
 --     end
 -- end

Some pros and cons (mostly cons) of automatic font scaling are discussed in this 2006 thread on ntg-context mailing list. I'll summarize some points:

  • Hans Hagen:

    hm, it's not that hard to do, but then the question is: what is the reference font; also, my experience is that an automated scaling in most cases looks as ugly as no scaling; it's a visual thing; the xheight is a factor but the 'boldness' too

  • Thomas Schmitz

    But will that work? What is the x-height of a Unicode font (and AFAIK, XeTeX can't handle any other font) that has Latin and Greek letters? You have to rely on the fact that the font designer will have implemented an equal x-height for all his characters - which is simply not the case for a majority of fonts, IMHO. So I'm not sure that this is a necessary or useful thing to have. When all is said and done, I still see no possibility other than looking at the printed page and deciding yourself whether the relation between both fonts is "right." Btw, most publishers don't seem to bother anymore and just set the fonts at whatever is their design size. OUP, e.g., uses Porson, which is a lot smaller than most Roman fonts, but they don't scale. I find this horrible, but what I want to say is: there doesn't seem to be an established typographical practice that could just be automated.

  • Hans Hagen

    Hm. Just typeset fontstrips, scale the doc up/down on the screen and find the best visual match. You need to do that only once for a given combination of fonts.

Let me explain how to use fontstrips that Hans mentions in his comment. I'll use a document with TeX Gyre Termes as the serif font, TeX Gyre Heros as the sansserif font, and Dejavu Sans Mono as the typewriter font:

\usetypescriptfile[dejavu]
\starttypescript[typeone]
  \definetypeface [typeone][rm][serif][termes]   [default]
  \definetypeface [typeone][ss][sans] [heros]    [default] 
  \definetypeface [typeone][tt][mono] [dejavu]   [default] 
  \definetypeface [typeone][mm][math] [modern]   [default] 
\stoptypescript

\setupbodyfont[typeone]

\starttext
\showfontstrip
\stoptext

which gives

enter image description here

Based on the x-height of the serif, sans serif, and typewriter fonts, one can calculate the "correct" values of rscale:

\starttypescript[typetwo]
  \definetypeface [typetwo][rm][serif][termes]   [default]
  \definetypeface [typetwo][ss][sans] [heros]    [default] [rscale=0.858]
  \definetypeface [typetwo][tt][mono] [dejavu]   [default] [rscale=0.822]
  \definetypeface [typetwo][mm][math] [modern]   [default] 
\stoptypescript

which gives

enter image description here

Note that the x-height matches closely (except for mathematics, which I did not scale). However, this does not necessarily mean that the combination looks good.

\ruledhbox{Test \sans{Test} \mono{Test}}

gives

enter image description here

But this is a start. To get a visually harmonious result, you'd have to experiment a bit with the values on a real document.

| improve this answer | |
  • Thanks, I haven't seen that fontstrip before, definitely a handy tool. – TeXnician Sep 13 '18 at 5:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.