On 5/21/2024 4:40 PM, Ali Ali wrote:
Hi, hope everyone's doing well!

Is it possible to setup math font so that all the basic ascii characters (i.e. 
a..zA..Z0..9) glyphs are substituted with current serif (or sans) font. I tried 
playing with fallback thing but it didn't got me anywhere!

e.g. $x$ will use the 'x' glyph from current serif italic font, and $\bf x$ 
will use the 'x' glyph from current serif bold font!
I would appreciate any suggestions and help!

Suppose we have all the required font files in the 'font' directory of the 
working directory, and below is the minimal source code!
"""
\starttypescriptcollection[CustomFontSelection]
   \starttypescript [serif] [CustomFontSelection] [name]
     \setups[font:fallback:serif]
     \definefontsynonym [Serif]
         % [file:font/Lora-Regular.ttf]
         [file:font/Lora-Medium.ttf]
         [features=default,fallbacks=Serif]
     \definefontsynonym [SerifBold]
         [file:font/Lora-Bold.ttf]
         [features=default,fallbacks=SerifBold]
     \definefontsynonym [SerifItalic]
         % [file:font/Lora-Italic.ttf]
         [file:font/Lora-MediumItalic.ttf]
         [features=default,fallbacks=SerifItalic]
     \definefontsynonym [SerifBoldItalic]
         [file:font/Lora-BoldItalic.ttf]
         [features=default,fallbacks=SerifBoldItalic]
   \stoptypescript

   \starttypescript [math] [CustomFontSelection] [name]
     %%% \definefontfallback [MathRomanFallBack]
     %%%     [SansItalic]
     %%%     [extendedlatin]
     %%%     [force=yes]
     \definefontsynonym [MathRoman]
         [file:font/STIXTwoMath-Regular.otf]
         [features=math,fallbacks=MathRomanFallBack]
   \stoptypescript

   \starttypescript[CustomFontSelection]
     \definetypeface [CustomFontSelection] [rm] [serif] [CustomFontSelection]   
 [default] [rscale=0.9]
     \definetypeface [CustomFontSelection] [ss] [sans]  
[newcomputermodern-book] [default]
     \definetypeface [CustomFontSelection] [tt] [mono]  
[newcomputermodern-book] [default]
     \definetypeface [CustomFontSelection] [mm] [math]  [CustomFontSelection]   
 [default] [rscale=0.97]
   \stoptypescript
\stoptypescriptcollection

\setupbodyfont[CustomFontSelection]


\starttext

We use $X$, $Y$, $Z$ and $n$, $m$, etc. $\sin(x) \to \limsup x_n$ whatever.

\mathematics{%
   \delta_{ij} =
     \startmathcases
     \NC 1 \NC \text{if } i = j \NR
     \NC 0 \NC \text{otherwise} \NR
     \stopmathcases
}

We use $\bf X$, $\bf Y$, $\bf Z$ and $\bf n$, $\bf m$, etc. $\bf \sin(x) \gets 
\limsup x_n$ whatever.

\stoptext
"""

More like this (if you want decent math). Also, use a math font as base that matches the fallbacks, also metric wise.

\starttypescriptcollection[CustomFontSelection]

    \starttypescript [serif] [CustomFontSelection] [name]
        \setups[font:fallback:serif]
\definefontsynonym [Serif] [name:dejavuserif] [features=default] \definefontsynonym [SerifBold] [name:dejavuserifbold] [features=default] \definefontsynonym [SerifItalic] [name:dejavuserifitalic] [features=default] \definefontsynonym [SerifBoldItalic] [name:dejavuserifbolditalic] [features=default]
    \stoptypescript

    \starttypescript [math] [CustomFontSelection] [name]
        \definefontfallback [MathRomanFallBack]
            [name:dejavuserifitalic]
            [lowercaseitalic,uppercaseitalic]
            [force=yes]
        \definefontfallback [MathRomanFallBack]
            [name:dejavuserifbolditalic]
            [lowercasebolditalic,uppercasebolditalic]
            [force=yes]
        \definefontfallback [MathRomanFallBack]
            [name:dejavuserif]
            [lowercasenormal,uppercasenormal]
            [force=yes]
        \definefontfallback [MathRomanFallBack]
            [name:dejavuserifbold]
            [lowercasebold,uppercasebold]
            [force=yes]
        \definefontsynonym
            [MathRoman]
            [file:stixtwomath-regular.ttf]

[features={math\mathsizesuffix,stixtwomath,stixtwo:mathextra,mathextra},%
             fallbacks=MathRomanFallBack,%
             goodies=stixtwo-math]
        \definefontsynonym
            [MathRomanBold]
            [file:stixtwomath-regular.ttf]

[features={math\mathsizesuffix,stixtwo-math-bold,stixtwomath,stixtwo:mathextra,mathextra},%
             fallbacks=MathRomanFallBack,%
             goodies=stixtwo-math]
    \stoptypescript

    \starttypescript[CustomFontSelection]
\definetypeface [CustomFontSelection] [rm] [serif] [CustomFontSelection] [default] [rscale=0.9] \definetypeface [CustomFontSelection] [ss] [sans] [newcomputermodern-book] [default] \definetypeface [CustomFontSelection] [tt] [mono] [newcomputermodern-book] [default] \definetypeface [CustomFontSelection] [mm] [math] [CustomFontSelection] [default] [rscale=0.97]
    \stoptypescript

\stoptypescriptcollection

\setupbodyfont[CustomFontSelection]


\starttext

We use $X$, $Y$, $Z$ and $n$, $m$, etc. $\sin(x) \to \limsup x_n$ whatever.

We use $\bf X$, $\bf Y$, $\bf Z$ and $\bf n$, $\bf m$, etc. $\bf \sin(x) \gets \limsup x_n$ whatever.

\stoptext


-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------

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

maillist : ntg-context@ntg.nl / 
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