I am trying to avoid character clashing when the italic characters surrounded by brackets
[eg., (f)]
with the help of the link, I am getting correct output when the characters f surrounded by brackets (); At the same time I am getting the spaced characters when the character f followed by another alphabets eg., df.
How to avoid the extra space when character followed by other alphabets through macros?
How to add extra space between italic Greek characters and the super script characters (to avoid character clash) i.e.,
$\zeta^\prime$and$\psi^*$
MWE:
for MWE purpose I used CMR font, actually I am using, other font (Minion), when using CMR font there is no character clash
\documentclass{book}
\makeatletter
\AtBeginDocument{%
\Umathcharnumdef\math@f\Umathcodenumf \mathcodef=\string"8000}
\begingroup\lccode~=f
\lowercase{\endgroup
\def~{%
\mkern3mu\math@f
\ifnum\mathgroup=\m@ne
\expandafter@firstofone
\else
\expandafter@gobble
\fi
{@ifnextchar_{\relax}{\mkern3mu}}%
}
\Umathcharnumdef\math@j\Umathcodenumj \mathcodej=\string"8000}
\begingroup\lccode~=j
\lowercase{\endgroup
\def~{%
\mkern2mu\math@j
\ifnum\mathgroup=\m@ne
\expandafter@firstofone
\else
\expandafter@gobble
\fi
{@ifnextchar_{\relax}{}}%
}
\Umathcharnumdef\math@p\Umathcodenump \mathcodep=\string"8000}
\begingroup\lccode~=p
\lowercase{\endgroup
\def~{%
\mkern2mu\math@p
\ifnum\mathgroup=\m@ne
\expandafter@firstofone
\else
\expandafter@gobble
\fi
{@ifnextchar_{\relax}{}}%
}
\Umathcharnumdef\math@d\Umathcodenumd \mathcoded=\string"8000}
\begingroup\lccode~=d
\lowercase{\endgroup
\def~{%
\math@d
\ifnum\mathgroup=\m@ne
\expandafter@firstofone
\else
\expandafter@gobble
\fi
{@ifnextchar_{\relax}{\mkern1mu}}%
}
\Umathcharnumdef\math@g\Umathcodenumg \mathcodeg=\string"8000}
\begingroup\lccode~=g
\lowercase{\endgroup
\def~{%
\mkern1mu\math@g
\ifnum\mathgroup=\m@ne
\expandafter@firstofone
\else
\expandafter@gobble
\fi
{@ifnextchar_{\relax}{}}%
}
\Umathcharnumdef\math@l\Umathcodenuml \mathcodel=\string"8000}
\begingroup\lccode~=l
\lowercase{\endgroup
\def~{%
\math@l
\ifnum\mathgroup=\m@ne
\expandafter@firstofone
\else
\expandafter@gobble
\fi
{@ifnextchar_{\relax}{\mkern1mu}}%
}
%%%%%%%%%%%UPPER CASE%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Umathcharnumdef\math@V\Umathcodenum\V \mathcode\V=\string"8000}
\begingroup\uccode~=\V
\uppercase{\endgroup
\def~{%
\math@V
\ifnum\mathgroup=\m@ne
\expandafter@firstofone
\else
\expandafter@gobble
\fi
{@ifnextchar_{\relax}{\mkern2mu}}%
}
\Umathcharnumdef\math@N\Umathcodenum\N \mathcode\N=\string"8000}
\begingroup\uccode~=\N
\uppercase{\endgroup
\def~{%
\math@N
\ifnum\mathgroup=\m@ne
\expandafter@firstofone
\else
\expandafter@gobble
\fi
{@ifnextchar_{\relax}{\mkern1mu}}%
}
\Umathcharnumdef\math@X\Umathcodenum\X \mathcode\X=\string"8000}
\begingroup\uccode~=\X
\uppercase{\endgroup
\def~{%
\math@X
\ifnum\mathgroup=\m@ne
\expandafter@firstofone
\else
\expandafter@gobble
\fi
{@ifnextchar_{\relax}{\mkern2mu}}%
}
\Umathcharnumdef\math@Y\Umathcodenum\Y \mathcode\Y=\string"8000}
\begingroup\uccode~=\Y
\uppercase{\endgroup
\def~{%
\math@Y
\ifnum\mathgroup=\m@ne
\expandafter@firstofone
\else
\expandafter@gobble
\fi
{@ifnextchar_{\relax}{\mkern2mu}}%
}
\Umathcharnumdef\math@T\Umathcodenum\T \mathcode\T=\string"8000}
\begingroup\uccode~=\T
\uppercase{\endgroup
\def~{%
\math@T
\ifnum\mathgroup=\m@ne
\expandafter@firstofone
\else
\expandafter@gobble
\fi
{@ifnextchar_{\relax}{\mkern1mu}}%
}
\Umathcharnumdef\math@J\Umathcodenum\J \mathcode\J=\string"8000}
\begingroup\uccode~=\J
\uppercase{\endgroup
\def~{%
\mkern1mu\math@J
\ifnum\mathgroup=\m@ne
\expandafter@firstofone
\else
\expandafter@gobble
\fi
{@ifnextchar_{\relax}{\mkern1mu}}%
}
\Umathcharnumdef\math@K\Umathcodenum\K \mathcode\K=\string"8000}
\begingroup\uccode~=\K
\uppercase{\endgroup
\def~{%
\math@K
\ifnum\mathgroup=\m@ne
\expandafter@firstofone
\else
\expandafter@gobble
\fi
{@ifnextchar_{\relax}{\mkern1mu}}%
}
\Umathcharnumdef\math@U\Umathcodenum\U \mathcode\U=\string"8000}
\begingroup\uccode~=\U
\uppercase{\endgroup
\def~{%
\math@U
\ifnum\mathgroup=\m@ne
\expandafter@firstofone
\else
\expandafter@gobble
\fi
{@ifnextchar_{\relax}{\mkern1mu}}%
}
\Umathcharnumdef\math@W\Umathcodenum\W \mathcode\W=\string"8000}
\begingroup\uccode~=\W
\uppercase{\endgroup
\def~{%
\math@W
\ifnum\mathgroup=\m@ne
\expandafter@firstofone
\else
\expandafter@gobble
\fi
{@ifnextchar_{\relax}{\mkern2mu}}%
}
}
\makeatother
\begin{document}
$(f)$ $(p)$
$df$
$\inf$
$\exp$
$\zeta^\prime$ and $\psi^*$
\end{document}

\mathitalicsmode=1(or=2) in the preamble and see whether that fixes it. – Henri Menke Dec 18 '22 at 19:29