From LuaLaTeX unicode-math to ConTeXt typescript

contextfontsunicode-math

In LuaLaTeX I have this code (Please correct me if I have written something inappropriate.)

\usepackage{fontspec}
\usepackage[warnings-off={mathtools-colon,mathtools-overbracket}]{unicode-math}

\defaultfontfeatures{Scale=MatchLowercase,Scale=MatchUppercase}
\setmainfont[Path=./minion/,
   %Extension = .otf,
    UprightFont=*-Regular.otf,
    BoldFont=*-Bold.otf,
    %ItalicFont=EBGaramond-MediumItalic.ttf,
    ItalicFont=*-It.otf,
    %RawFeature=+cswh,
    ItalicFeatures={Scale=MatchUppercase},{Scale=MatchLowercase},%{Style=Swash},
    %BoldItalicFont=EBGaramond-BoldItalic.ttf,
    BoldItalicFont=*-BoldIt.otf
    ]{MinionPro}

\newfontface\Swash{MinionPro-It}[
    Path=./minion/,
    Extension = .otf,
    Contextuals=Swash]
    \DeclareTextFontCommand{\textsw}{\Swash}
    % \addfontfeature{ItalicFeatures={Style=Swash},{Scale=MatchUppercase},{Scale=MatchLowercase}},

%\newfontface\Cha[
%    Path=./minion/,
%    Extension = .ttf,
%    %UprightFont=*-Regular,
%    %AutoFakeSlant=0.15,
%    %AutoFakeBold=1.2,
%    ]{Chatelaine-Regular}
%\newfontface\MPI[
%    Path=./minion/,
%    Extension = .otf,
%   ]{MinionPro-It}

\setmathfont{Garamond-Math.otf}[Scale=1.09]
\setmathfont{Garamond-Math.otf}[
     range=up/{num},
     Scale=1]

\setmathfontface\Neo[
     Path=./minion/,
     Extension = .otf,
     UprightFont=*,
     AutoFakeSlant=0.15,
     AutoFakeBold=1.2,
     Scale=1.09
     ]{NeoEuler}
\newcommand{\me}{\ensuremath{\Neo e}}

\setmathfont{STIX Two Math}[
   range=bb,
   Scale=MatchUppercase,
   Scale=1.09
   ]

\unimathsetup{math-style=upright}
\setmathfont[
    range=up/{greek,Greek}, script-features={},% sscript-features{},
    Path=minion/,
    Extension=.otf,
    UprightFont=*,
    AutoFakeSlant=0.15,
    AutoFakeBold=1.2,
    Scale=0.91
    ]{NeoEuler}

\renewcommand{\int}{\ensuremath{\char"222B}}
\setmathfont[range="222B,
      Scale=1.09
      ]{Erewhon Math}

to get MinionPro like main font, Garamond-math like math font with greeks letters from NeoEuler, blackboard math letters from STIX2, integral symbol from Erewhon Math font and a command for exponential e symbol due NeoEuler:

I was going through the documentation and some posts here to achieve the same in ConTeXt. Initially i wrote

\definefontfamily[mainface][mm][Garamond-Math]
\definefontfamily[mainface][rm][MinionPro]
\setupbodyfont[mainface,11pt]

and it works (with the otf's installed) but italics and bold letters are not returned either despite using {\it } and {\bf }. I don't have the greek letters nor the symbols of the other fonts either. With the otf files in folder I tried the following as a first step to get the symbols from the other fonts

\startenvironment mainface
    %0x80-0x97=GREEK
    \definefontfallback[Neo-fallback][file:NeoEuler.otf][0x80-x097][force=yes]
    %0x98-0xAF=greek
    \definefontfallback[Neo-fallback][file:NeoEuler.otf][0x98-0xAF][force=yes]
    \starttypescript [serif] [mainface]
        \definefontsynonym [Serif] [file:MinionPro-Regular.otf]
        \definefontsynonym [SerifCaps] [Serif] [features=smallcaps]
        \definefontsynonym [SerifItalic] [file:MinionPro-Italic.otf]
        \definefontsynonym [SerifSwash] [SerifItalic] [features=swash]
        \definefontsynonym [SerifBold] [file:MinionPro-Bold.otf]
        \definefontsynonym [SerifBoldItalic] [file:MinionPro-BoldItalic.otf]
    \stoptypescript
    \starttypescript [math] [mainface]
        \definefontsynonym [mathgreek] [file:Garamond-Math.otf] [fallbacks=Neo-fallback]
    \stoptypescript
    \definetypeface [mainface] [rm] [serif] [mainface] [default] [features=default]
    \definetypeface [mainface] [mm] [math] [mainface] [default] [features=default]
\stopenvironment
\usetypescript[mainface][default]
\setupbodyfont[mainface,rm,mm,11pt]

but the pdf cannot be generated. When I try to open the pdf file I only get the message: the pdf file is damaged. Installing the fonts, if I do [Neo Euler] instead of [file:NeoEuler.otf] and something similar for MinionPro and Garamond-Math:

\startenvironment mainface
    %0x80-0x97=GREEK
    \definefontfallback[Neo-fallback][Neo Euler][0x80-x097][force=yes]
    %0x98-0xAF=greek
    \definefontfallback[Neo-fallback][Neo Euler][0x98-0xAF][force=yes]
    \starttypescript [serif] [mainface]
        \definefontsynonym [Serif] [MinionPro-Regular]
        \definefontsynonym [SerifCaps] [Serif] [features=smallcaps]
        \definefontsynonym [SerifItalic] [MinionPro-Italic]
        \definefontsynonym [SerifSwash] [SerifItalic] [features=swash]
        \definefontsynonym [SerifBold] [MinionPro-Bold]
        \definefontsynonym [SerifBoldItalic] [MinionPro-BoldItalic]
    \stoptypescript
    \starttypescript [math] [mainface]
        \definefontsynonym [mathgreek] [Garamond-Math] [fallbacks=Neo-fallback]
    \stoptypescript
    \definetypeface [mainface] [rm] [serif] [mainface] [default] [features=default]
\usetypescript[mainface][default]
\setupbodyfont[mainface,rm,mm,11pt]

it is possible to generate the pdf file but the math fonts are not applied. The pdf file appears with MinionPro and latinmodern-math ({\it } and {\bf }no works).

It is clear that I am not considering something to get the results of the code for LuaLaTeX above, in ConTeXt. How can I achieve it?

Best Answer

There is too much code that I do not understand or that looks a bit odd, but let me show you a small (horrible) example where I use XCharter (I do not have Minion) as text, Garamond Math as math, and alter some alphabets/glyphs. This is likely not a complete answer, but it might get you going.

The file foo-math.lfg looks like this:

return {
    name = "foo-math",
    comment = "Goodies that complement foo.",
    author = "juanuni",
    mathematics = {
        tweaks = {
            aftercopying = {
              {
                tweak   = "replacealphabets",
                list    = {
                    {
                        source   = "uppercasescript",
                        target   = "uppercasecalligraphic",
                        filename = "latinmodern-math.otf",
                        rscale   = 1,
                    },
                    {
                        source   = "lowercasegreeknormal",
                        target   = "lowercasegreekitalic",
                        filename = "euler-math.otf",
                        rscale   = 1,
                    },
                    {
                        source   = { first = 0x222B }, -- integral
                        filename = "stixtwomath-regular.ttf",
                    },
                },
              }
            },
        },
    },
}

If you look in the ConTeXt distribution you will find some .lfg files, usually there is only one font that is used, and that one is tweaked. Above you only see one tweak, the replacealphabets one.

The small example file looks like this:

\definefontfamily [mainface] [rm] [XCharter]
\definefontfamily [mainface] [mm] [Garamond Math]

\definefontfeature[default][default][goodies=foo-math.lfg]

\setupbodyfont[mainface,11pt]

\starttext
\startTEXpage[offset=3pt]

Text

\im{ a+b+c }

\im{\mathcal{ABC}}

\im{\alpha\beta\gamma}
 
\im{\int}

\stopTEXpage
\stoptext

Not so much to be said about it. The output looks like this:

tweaked

Looking carefully, we notice that we have Latin Modern for calligraphic, Euler-Math for greek, and a Stix Two Math integral sign.

This can be compared with the output if the \definefontfeature line is commented:

only Garamond in math

Related Question