1

Continuing https://chat.stackexchange.com/rooms/97632/discussion-between-marcel-kruger-and-mdayq6, running lualatex on

\documentclass{article}
\usepackage{fontspec}
\usepackage{unicode-math}
% \setmathfont{texgyretermes-math.otf}
\setmathfont[Kerning=On]{TeXRygeTermesMath-Regular.otf}%%% same as Tex Gyre Termes Math, with an attempt to improve kerning
\begin{document}
\(\{f\}\)
\[
  \{f\}
\]
\end{document}

where the font is taken from http://filebin.net/36gqo82z5evv2869 (our attempts to improve tex gyre termes math), produces

left kerning

As we see, the kerning is applied in the first case but not in the second. What to do to get the proper kerning also in the second case?

Further, trying to reduce the kerning between f and } ends in nowhere: whichever value I enter into kern offset

no right kerning

, the resulting PDF is unchanged.

Any idea on how to adjust the kerning between f and }?

Last but not least, any idea of how to reduce the kerning in $\sigma_0$ and \[\sigma_0\] using Fontforge? As of now, this kerning is enormously large...

EDIT: Following Marcel's suggestions, I abandoned the search for a good solution for {f} and created a TeX Ryge Termes Math font with new kernings improving the right subscripts for italics \sigma and \tau in math mode. Let's consider the input

\documentclass{article}
\pagestyle{empty}
\usepackage{unicode-math}
%\setmathfont[Ligatures=TeX]{TeX Gyre Termes Math}
\setmathfont[Ligatures=TeX]{TeXRygeTermesMath-Regular.otf} %%% Name changed to comply with the license. The shapes are (hopefully) the same, and the math kernings are new.
\begin{document}
\newcommand{\test}[1]{#1_{abc} #1_0^a #1^b_b #1_1^c #1^d_⊤ #1_⟂^e #1_T^f #1_k^g #1_{\mathup{k}}^h #1_{h}^j}
\newcommand{\testtest}{\test{\sigma}\test{\tau}}
\(\testtest\)
\[\testtest\]
\end{document}

With the original Gyre fonts, the above produces the output

original xelatex output

for xelatex and

original lualatex output

for lualatex.

When using the kerned Ryge fonts, we get

output of xelatex using the Ryge font with kernings

when compiled with xelatex and

output of lualatex using the Ryge font with kernings

when compiled with lulatex.

With the new Ryge font, xelatex does a generally good job on kerning, and lualatex does almost no job on kerning except the subscript "abc". Why so?

Further improvements deem necessary:

  • slightly increase the kerning for subscripts ⊤, 𝑇, and k of both 𝜎 and 𝜏

  • slightly increase the kerning in 𝜏_0 (but not in 𝜎_0)

  • slightly decrease the kerning in 𝜏_⟂ and 𝜎_⟂

such that all the kernings still remain nonpositive.

After that, 𝜎^𝑓, 𝜏^𝑓, 𝜎^𝑗, and 𝜏^𝑗 need small positive kernings.

Is it possible to do so on the font level?

  • Please stop asking multiple questions in every question. That doesn't fit to the format of the site and makes all answers harder to find. – Marcel Krüger Aug 20 at 19:41
  • @MarcelKrüger I see your problem and apologize. Would you expect filing a but report concerning the absence of help and reasonable tutorials to fontforge developers? They know it already. They made a good attempt in the past, but what they show on their Web pages as of now is insufficient or outdated or both... So, I'm kinda desperate alone. – user49915 Aug 20 at 19:50
7

For your two problems read my answer to your other question: Normal kerning is not the right tool for Math and will normally not be applied. That LuaTeX sometimes does apply it probably happens because TeX no longer knows that the characters used to be math. After the f italic correction is inserted, so the f and } do not directly follow each other -> no kerning. Also in display math LuaTeX doesn't expect to find something requiring kerning, so kerning is skipped.

Anyway, your last question is more interest:

The kerning between a character and it's subscript is known in OpenType Math as Math kerning. See https://docs.microsoft.com/en-us/typography/opentype/spec/math#mathkerninfo-table for the details. In your case you only need to adjust the sigma.

Open a math font in FontForge. Then you can change math related parameters through Element->Other Info->MATH Info. A windows like this opens: enter image description here

Select "Math Kern" and press to add math kerning for a new glyph. Enter the name of your glyph, in your case "u1D70E" (MATHEMATICAL ITALIC SMALL SIGMA). Then press change to adjust the values.

enter image description here

This brings you to the Math Kerning dialog:

enter image description here To add new points, go to "Textual" and then select "Bottom Right". Press three times to add three points and go back to "Graphical". Here click on the sigma below Bottom Right to select this block. Your kerning point appears and you can drag it to an appropriate location. Roughly, every point means that if a subscript is attached at this height or lower, then it should get this amount of kerning. For example you can set your points like this:

enter image description here

Now confirm with OK, Ok again and generate your font.

If you placed your points in the same way as I did, $\sigma_0$ becomes

enter image description here

Of course, if you do not want to change your font, LuaTeX also allows you to use Lua code to change mathkerns:

\documentclass{standalone}
\usepackage{unicode-math}
\usepackage{luacode}
\begin{luacode*}
  -- First create a table specifying the mathkerns we want to set:
  local mathkerns = {
    ["TeXGyreTermesMath-Regular"] = { -- This should be the PostScript name of the font
      [0x1D70E] = { -- If the character would have a regular name, you could also use the glyphname here
        bottomright = {
          {height=0,kern=-175},
          {height=216,kern=-76},
          {kern=0},
        },
      },
    },
  }
  local function initmathkern(tfmdata)
    local values = mathkerns[tfmdata.properties.psname]
    if not values then return end
    for cp, value in next, values do
      local tcp = type(cp)
      if tcp == 'string' then
        cp = tfmdata.resources.unicodes[cp]
      end
      local char = tfmdata.characters[cp]
      if char then
        local mathkern = char.mathkerns
        if not mathkern then
          mathkern = {}
          char.mathkerns = mathkern
        end
        for corner, v in next, value do
          mathkern[corner] = v
        end
      end
    end
  end
  fonts.constructors.newfeatures'otf'.register{
    name = 'mathkern',
    description = 'Overwrite mathkern values',
    initializers = {
      base = initmathkern,
    },
  }
\end{luacode*}
\setmathfont[RawFeature=mathkern]{texgyretermes-math.otf}
\begin{document}
$\sigma_0$
\end{document}
  • Wow. What are the images. An editor or software to create the fonts? – Sebastiano Aug 20 at 22:34
  • @Sebastiano Yes, the question was how to change this in FontForge, so these are FontForge screenshots – Marcel Krüger Aug 20 at 23:19
  • I think there was once a question on the context list how to add or change the mathkerns with lua, but it was never answered. – Ulrike Fischer Aug 21 at 6:40
  • @UlrikeFischer mailman.ntg.nl/pipermail/ntg-context/2019/094714.html There is an answer, but it is “use goodies“ which are not available in generic. – Henri Menke Aug 21 at 9:00
  • @HenriMenke I knew I had forgotten something. I wanted to transfer the issues in lua-fond-pond to luaotfload before moving the repo to latex. I have an issue about goodies there. That is something that should be addressed if possible. – Ulrike Fischer Aug 21 at 9:23

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.