2

Is it possible to add math kerns (aka cut-ins or staircase kerning) to OpenType math fonts? If yes, how?

I am personally looking for something which works for LuaLaTeX (using fonts.handlers.otf.addfeature?), but I would be happy for other solutions as well.

For example, I want to add a bottom right math kern to \lmathccal{O}.

\documentclass{article}

\usepackage[newcmbb]{fontsetup}

% Below code copied from here: https://tex.stackexchange.com/a/373539/128462.

\DeclareFontFamily{U}{mathc}{}
\DeclareFontShape{U}{mathc}{m}{it}%
{<->s*[1.03] mathc10}{}
\DeclareMathAlphabet{\lmathccal}{U}{mathc}{m}{it}
% \DeclareMathAlphabet\cmmathcal{OMS}{cmsy}{m}{n}
% \renewcommand{\symcal}{\lmathccal}

\begin{document}
    \(\lmathccal{O}_i\) \(\symcal{O}_i\)
\end{document}

newcm lualatex adding math kerns

1
  • (1) you should not use ulrike's answer with a unicode maths setup. U changes the encoding so it is no longer unicode. (2) kerning pairs, as far as I know, are always intra-font so would not apply unless you created a combination virtual font. Commented 5 hours ago

1 Answer 1

2

Too long for a comment, and it might or might not help you (you have to test), but in the ConTeXt testsuite there is a file kerns-002.tex (here with a line typing the file out in the pdf removed):

\startluacode

    local kerns = {
        ["TeXGyrePagellaMath-Regular"] = {
            [0x1D449] = { bottomright = { { kern = -200 } } }, -- math italic V
            [0x1D44A] = { bottomright = { { kern = -100 } } }, -- math italic W
        }
    }

    local function addkerns(tfmdata)
        if tfmdata.mathparameters then
            local kerns = kerns[tfmdata.properties.fontname]
            if kerns then
                local characters = tfmdata.characters
                for unicode, specification in pairs(kerns) do
                    local character = characters[unicode]
                    if character and not character.mathkerns then
                        character.mathkerns = specification
                    end
                end
            end
        end
    end

    fonts.handlers.otf.features.register {
        name         = "mathkerns",
        description  = "additional math kerns",
        default      = true,
        initializers = {
            position = 1,
            base     = addkerns,
            node     = addkerns,
        }
    }

\stopluacode

\setupbodyfont[pagella] \showglyphs

\starttext

    Don't use this method in \ConTeXt\ as we have
    other mechanisms for it!

    \startformula V^i_j = W^i_j \stopformula

\stoptext

As you see in the end there is a warning to ConTeXt users not to do this. But it has an effect also in ConTeXt (with luametatex and luatex). With luatex the relevant part looks like this:

cut-ins

Compare with the same file, without the lua snipped enabled:

without cut-ins

Good luck!

1
  • actually, maybe the op is trying to use opentype. I always forget what fontsetup does ... but then switching to U encoding looks very wrong? edit: no, my apologies. I think they are using MATH, but are then kind of ignoring that fact ... Commented 5 hours ago

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.