Erroneous text layer. Mismatch between kerning in fontforge and in {xe|lua}latext
Running xelatex (or lualatex) on the input
\\documentclass{standalone}
\\usepackage{unicode-math}
\\setmathfont[Ligatures=TeX]{texgyretermes-math.otf}
\\begin{document}
\\(\\{f\\}\\)
\\end{document}
should produce some form of
{f}
in the text layer of the PDF. But it produces
{f }
with a space between f and }. This space shouldn't be there. How to get rid of it?
As for the visible output, here it is:

As you see, the left brace and f overlap in the PDF. However, when you open the font with fontforge, and put the left brace with the florin into the metrics window, they don't overlap! The output is inconsistent. What am I missing? How to increase the kerning properly once and for all for the occurrences of "{f" in my huge document (which is not an MWE)? I would be ready to hack the font myself (given that the developers don't react), but it should lead somwhere...
1 Answer
The space in the "text layer" of the PDF is inserted by a heuristic of your PDF viewer because there is some distance between the f and the }. In the long term tagged PDF files should solve that problem, but especially for math formulas I wouldn't hold my breadth. So in the short term, you either specify replacement texts for every math formula using e.g. repltext or you live with this space.
Regarding the "inconsistency" in FontForge: The florin sign (U+0192) and the mathematical italic small letter f (U+1D453) are not the same glyph. Comparing both in FontForge shows the same appearance as in TeX:
(Mathematical Italic Small F first, florin second)

But generally I wouldn't recommend FontForge's metric window for Math output, because Math isn't formatted in the same way as normal text. Especially "classical kerning" like in this case doesn't really exists, because { and f are separate objects and nor part of a word.
Of course, if you prefer the florin sign over the mathematical f, you can use
\\Umathcode`\\f 7 0 "192
after \\begin{document} such that LaTeX insets the florin sign insteaf of U+1D453 in math mode for a "f". One downside is that the textlayer will contain the florin sign too. You could also modify U+1D453 directly in FontForge.
-
Oh, I did not scroll that much down to 𝑓 (U+1D453) previously. You are right. Thank you! I didn't quite get it: is there a "proper" way to change kerning between { and 𝑓 (U+1D453) in FontForge? You say you don't recommend FontForge's metric window for math output and at the same time you say that one can modify U+1D453 directly in FontForge. – MdAyq6 3 hours ago
-
it doesn't look as if tagging would improve the copy&paste with the adobe reader: the heuristic stays and the space is inserted (even in text, e.g. with
\\emph{f})) – Ulrike Fischer 2 hours ago -
@MdAyq6 I meant that you can modify kerning between { and U+1D453 (because normal kerning isn't applied AFAIK, but you could modify U+1D453 to be slightly more on the right in general. This would be independent from the left character though, so you would basically e.g. redesign U+1D453 to look more like the florin sign. – Marcel Krüger 1 hour ago
-
@MdAyq6 If you were using LuaTeX you could always use Lua to add such small changes. – Marcel Krüger 1 hour ago