I have used the following code, which is a minor modification of @egreg's code provided in Making f active in math mode, to change the subscript kerning for specific letters (e.g. f in this example).
However, there are two concerns:
a) the kerning of superscripts is also affected e.g. in $f_{a}^{b}$
b) if a superscript precedes the subscript, as e.g. in $f^{b}_{a}$, nothing is affected.
I understand (at least in principle) what the code does and why these issues come up. However, I haven't been able to resolve them.
\documentclass{article}
\usepackage{fontspec}
\usepackage{xunicode}
\makeatletter
\DeclareRobustCommand{\fixsubkerning}[3]{
\AtBeginDocument{%
\edef\SAVEfCODE{\the\Umathcodenum`#1 } % just for the test
\Umathcharnumdef#3\Umathcodenum`#1
\mathcode`#1=\string"8000 }
\begingroup\lccode`~=`#1
\lowercase{\endgroup
\def~{%
#3
\ifnum\mathgroup=\m@ne
\expandafter\@firstofone
\else
\expandafter\@gobble
\fi
{\@ifnextchar_{\mkern-#2mu}{\relax}}%
}
}
}
\makeatother
\fixsubkerning{f}{5}{\mathf}
\begin{document}
\[
f_{a}
\]
\end{document}
Any help is appreciated.

fin pdflatex? I mean, I would like to get thefletter with negative space in subscript asf_{\!2}^2in an automatic manner. – mert Sep 03 '22 at 19:50