1

I'm using plain TeX with the luatex engine (actually it is OpTeX, but you can just assume it is the "plain" luatex). For my document I'm using the font EBGaramond. When I have a fomula like $(f+g)$, the letter f slightly overlaps the left parenthesis, and I don't like it. Here is how I am triying to fix it, by adding some space in between the two characters.

\def \adef #1{\catcode`#1=13 \begingroup \lccode`\~=`#1\lowercase{\endgroup\def~}}


\edef\lp{(}
\adef({\futurelet\next\dolp}
\def\dolp{\lp\ifmmode\ifx\next f\mskip1.5mu\fi\fi}

Now there is some space between the parenthesis and the f, $(f+g)$.

\bye

I reported the macro \adef from OpTeX, which basically is equivalent to making the character active (in this case the parenthesis) and then defining it. This works, but I was wondering: is it the "proper" way to deal with this problem? Or should I make the fix in the font by adding some kernigs? If so, how?

Regarding my solution, what if I want to add a space also for other letters? Suppose I have a list \def\list{fgj} of characters (in this example the three characters f,g,j), how should I write the \ifx part so that it is true for any of the characters in \list? What I unsuccessfully tried is

\def\dolp{\lp\ifmmode\ea\isinlist\ea\list\next\iftrue\mskip1.5mu\fi\fi}

where \ea is the OpTeX abbreviation for \expandafter and \isinlist is a OpTeX macro (you can look for it if needed). I don't know why this doesn't work.

2 Answers 2

2

I mean that best way is to give kerning exceptions for the Garamond-Math font. This is possible by following \directlua code:

\fontfam[garamond]

\directlua
  {fonts.handlers.otf.addfeature 
    {
    name = "kerncorr",
    type = "kern",
    data = {
    ["("] = { ["𝑓"] = 80, ["𝑔"] = 50 },
    }
  }
}
\_def\_normalmath{%
    \_loadumathfamily 1 {[Garamond-Math]}{+kerncorr} % Base font
    \_loadmathfamily  4 rsfs              % script
    \_setunimathdimens
}%
\normalmath % we must reload Math font collection with {+kerncorr} again.

Test: $(f+g)$.

\bye

Note that the "f" and "g" at line 9 in the example above are not normal f and g. They are math italic f and g, Unicode U+1D453, U+1D454.

8
  • Thank you! Just as additional curiosity, in the line of code where I use your \isinlist macro, do you know why it doesn't work? With the expandfaters I try to expand first \next, but it doesn't work as expected
    – User
    Jan 27, 2021 at 13:45
  • I have just noticed that your solution doesn't work in display mode. Try $$(f+g)$$, please
    – User
    Jan 27, 2021 at 14:29
  • Ad 1: \next is declared by \futurelet, so \ea has no effect to it and (of course) \next (this control sequence) is not in \list. Ad 2: I am not sure but is seems as a bug in the luaotfload implementation. There is no reason why display mode behaves differently. You can try to rewrite the example to pure luatex example (without OpTeX) and open an issue in luaotfload project at github.
    – wipet
    Jan 27, 2021 at 15:22
  • 1
    As mentioned in the linked luaotfload issue, kerning of \mathopen followed by \mathord noads is not supported in TeX's math layout. That it works in some cases related to inline math is a sideeffect which should not be relied upon. Jan 27, 2021 at 21:54
  • 1
    OK, thanks. I added a notice about luatex engine in this issue. And workaround for this case of Garamond font: you can re-declare \Umathcode `( = 0 1 "28 and \Umathcode `) = 0 1 "29. The spacing is different in very special cases: (=) for example but kerning works.
    – wipet
    Jan 28, 2021 at 1:46
1

Another solution is using active character (. I tried to use math-only active character, i.e. \mathcode`(="8000 but this solution does not work in such constructions like \bigl(. So, global active ( seems to be better:

\fontfam[garamond]

\adef({\string(\futurelet\next\addmkern}
\def\addmkern{\ifmmode\cs{mu:\meaning\next}\fi}

\sdef{mu:\meaning f}{\mkern1.5mu}
\sdef{mu:\meaning g}{\mkern1mu}

Test: $(f+g), (x)$, in text: (f).

\bye

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .