I want to use the KP fonts for the maths in my document. ConTeXt recognises the files:

mtxrun --script fonts --list --all --pattern=kp         

identifier                  familyname           fontname                    filename         subfont   instances

kpcompanionitalic           kpcompanion          kpcompanionitalic           jkplmitc.afm
kpcompanionmedium           kpcompanion          kpcompanionmedium           jkpbnc.afm
kpcompanionmediumitalic     kpcompanion          kpcompanionmediumitalic     jkpbitc.afm
kpcompanionnormal           kpcompanion          kpcompanionregular          jkplmnc.afm
kpcompanionregular          kpcompanion          kpcompanionregular          jkplmnc.afm
kpexpertitalic              kpexpert             kpexpertitalic              jkplmite.afm
kpexpertmedium              kpexpert             kpexpertmedium              jkpbne.afm
kpexpertmediumitalic        kpexpert             kpexpertmediumitalic        jkpbite.afm
kpexpertnormal              kpexpert             kpexpertregular             jkplmne.afm
kpexpertregular             kpexpert             kpexpertregular             jkplmne.afm
kpitalic                    kp                   kpitalic                    jkplmit8a.afm
kplargesmallcapsmedium      kplargesmallcaps     kplargesmallcapsmedium      jkpkbsc.afm
kplargesmallcapsnormal      kplargesmallcaps     kplargesmallcapsregular     jkpkmsc.afm
kplargesmallcapsregular     kplargesmallcaps     kplargesmallcapsregular     jkpkmsc.afm
kpmedium                    kp                   kpmedium                    jkpbn8a.afm
kpmediumitalic              kp                   kpmediumitalic              jkpbit8a.afm
sfkpnormal                  sfkp                 sfkpregular                 jkpssmn8a.afm
sfkpregular                 sfkp                 sfkpregular                 jkpssmn8a.afm
sfkpscexpmedium             sfkpscexp            sfkpscexpmedium             jkpssbsce.afm
sfkpscexpnormal             sfkpscexp            sfkpscexpregular            jkpssmsce.afm
sfkpscexpregular            sfkpscexp            sfkpscexpregular            jkpssmsce.afm
sfkpscmedium                sfkpsc               sfkpscmedium                jkpssbsc8a.afm
sfkpscnormal                sfkpsc               sfkpscregular               jkpssmsc8a.afm
sfkpscregular               sfkpsc               sfkpscregular               jkpssmsc8a.afm
ttkp                        ttkp                 ttkpmedium                  jkpttbn8a.afm
ttkpcompmedium              ttkpcomp             ttkpcompmedium              jkpttbnc.afm
ttkpcompnormal              ttkpcomp             ttkpcompregular             jkpttmnc.afm
ttkpcompregular             ttkpcomp             ttkpcompregular             jkpttmnc.afm
ttkpexpmedium               ttkpexp              ttkpexpmedium               jkpttbne.afm
ttkpexpnormal               ttkpexp              ttkpexpregular              jkpttmne.afm
ttkpexpregular              ttkpexp              ttkpexpregular              jkpttmne.afm
ttkpmedium                  ttkp                 ttkpmedium                  jkpttbn8a.afm

I am not sure where to go from there. I've tried to setup the fonts like this:

\definefontfamily[font] [serif] [Baskervaldx]
\definefontfamily[font] [math]  [KP]
\definefontfamily[font] [sans]  [Baskervaldx]
\definefontfamily[font] [mono]  [Latin Modern]

However, compiling yields the error

Math error: parameter \Umathquad\displaystyle is not set

This post seems to suggest this means the KP fonts do not come with maths fonts, even though I am able to set equations in LaTeX using KP fonts just fine.

This problem is not new: this mailing list thread seems to deal with the same problem, but I don't understand the discussion well enough to see if there was a solution. It it possible to typeset equations in ConTeXt using KP fonts?

  • That's not how it works. You have to define a virtual math font which performs the mapping from Unicode to traditional 8-bit encoding. – Henri Menke Mar 6 '18 at 23:52

Mapping the text font is not so hard. Mapping the math font is much harder. Find below my humble attempt. The contents of the file kpfonts-math.lfg can be found here on the mailing list https://mailman.ntg.nl/pipermail/ntg-context/2014/076606.html. Here I present a simplified version.

local mathencodings = fonts.encodings.math

return {
   name = "kpfonts-math",
   version = "1.00",
   comment = "kpfonts, math part.",
   author = "Chris",
   copyright = "ConTeXt development team",
   mathematics = {
      mapfiles = {
      virtuals = {
         ["kpfonts-rm"] = { -- MathRoman
            { name = "file:jkpmn8a", features = "virtualmath", main = true },
            { name = "jkpmia",  vector = "tex-mr", skewchar=0x7F },
            { name = "jkpmi", vector = "tex-mi", skewchar=0x7F },
            { name = "jkpmi", vector = "tex-it", skewchar=0x7F },
            { name = "jkpbn8a",  vector = "tex-bf", skewchar=0x7F },
            { name = "jkpbmi", vector = "tex-bi", skewchar=0x7F },
            { name = "jkpsy",  vector = "tex-sy", skewchar=0x30, parameters = true },
            { name = "jkpex",  vector = "tex-ex", extension = true },
            { name = "jkpsya",  vector = "tex-ma" },
            { name = "jkpsyb",  vector = "tex-mb" },
         ["kpfonts-bf"] = { -- MathRomanBold
            { name = "file:jkpbn8a", features = "virtualmath", main = true },
            { name = "jkpbmia",  vector = "tex-mr", skewchar=0x7F },
            { name = "jkpbmi", vector = "tex-mi", skewchar=0x7F },
            { name = "jkpbmi", vector = "tex-it", skewchar=0x7F },
            { name = "jkpbsy",  vector = "tex-sy", skewchar=0x30, parameters = true },
            { name = "jkpbex",  vector = "tex-ex", extension = true },
            { name = "jkpbsya",  vector = "tex-ma" },
            { name = "jkpbsyb",  vector = "tex-mb" },
\starttypescriptcollection [kpfonts]


  \starttypescript [serif] [kpfonts] [name]
    \definefontsynonym [Serif]            [file:jkpmn8a.pfb]  [features=default]
    \definefontsynonym [SerifItalic]      [file:jkpmit8a.pfb] [features=default]
    \definefontsynonym [SerifBold]        [file:jkpbn8a.pfb]  [features=default]
    \definefontsynonym [SerifBoldItalic]  [file:jkpbit8a.pfb] [features=default]
    \definefontsynonym [SerifCaps]        [file:jkpmsc8a.pfb] [features=default]
    \definefontsynonym [SerifBoldCaps]    [file:jkpbsc8a.pfb] [features=default]

  \starttypescript [sans] [kpfonts] [name]
    \definefontsynonym [Sans]           [file:jkpssmn8a.pfb]  [features=default]
    \definefontsynonym [SansItalic]     [file:jkpssmn8a.pfb]  [features=kpslant]
    \definefontsynonym [SansBold]       [file:jkpssbn8a.pfb]  [features=default]
    \definefontsynonym [SansBoldItalic] [file:jkpssbn8a.pfb]  [features=kpslant]
    \definefontsynonym [SansCaps]       [file:jkpssmsc8a.pfb] [features=default]
    \definefontsynonym [SansBoldCaps]   [file:jkpssbsc8a.pfb] [features=default]

  \starttypescript [mono] [kpfonts] [name]
    \definefontsynonym [Mono]           [file:jkpttmn8a.pfb] [features=default]
    \definefontsynonym [MonoItalic]     [file:jkpttmn8a.pfb] [features=kpslant]
    \definefontsynonym [MonoBold]       [file:jkpttbn8a.pfb] [features=default]
    \definefontsynonym [MonoBoldItalic] [file:jkpttbn8a.pfb] [features=kpslant]

  \starttypescript [math] [kpfonts] [all]
    \definefontsynonym [MathRoman]     [kpfontsrm@kpfonts-rm]
    \definefontsynonym [MathRomanBold] [kpfontsbf@kpfonts-bf]

  \starttypescript [kpfonts]
    \definetypeface [\typescriptone] [rm] [serif] [kpfonts] [default]
    \definetypeface [\typescriptone] [ss] [sans]  [kpfonts] [default]
    \definetypeface [\typescriptone] [tt] [mono]  [kpfonts] [default]
    \definetypeface [\typescriptone] [mm] [math]  [kpfonts] [default]



% make the unmapped glyphs yourself



  \starttheorem[title={Residue theorem}]
    Let $f$ be analytic in the region $G$ except for the isolated
    singularities $a_1,a_2,\dots,a_m$. If $\gamma$ is a closed
    rectifiable curve in $G$ which does not pass through any of the
    points $a_k$ and if $\gamma\approx 0$ in $G$, then
      \frac{1}{2\pi i}\int\limits_{\gamma}f\left(x^{{\mathbf N}\in\mathbb{C}^{N\times 10}}\right) = \sum_{k=1}^m
      n(\gamma;a_k){\mathrm Res}(f;a_k)\,.

  \starttheorem[title={Maximum modulus}]
    Let $G$ be a bounded open set in $\mathbb{C}$ and suppose that $f$
    is a continuous function on $G^-$ which is analytic in $G$. Then
      \max\{|f(z)|\:z\in G^-\} = \max\{|f(z):z\in \partial G\}\,.

  First some large operators both in text:
  $\iiint\limits_{Q}f(x,y,z)\,{\mathrm d}x\,{\mathrm d}y\,{\mathrm d}z$
  and also on display
    \iiiint\limits_{Q}f(w,x,y,z)\,{\mathrm d}w\,{\mathrm d}x\,{\mathrm d}y\,{\mathrm d}z\leq\oint_{\partial Q} f^\prime\left(\max\left\{\frac{\Vert w\Vert}{\vert w^2+x^2\vert};\frac{\Vert z\Vert}{\vert y^2+z^2\vert};\frac{\Vert w\oplus z\Vert}{\vert x\oplus y\vert}\right\}\right)


Of course I didn't do all your work and there will be some unmapped glyphs. I will not dig through the font tables to find the correct mappings. But to a first approximation it looks pretty good.

enter image description here

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.