为了避免数学中的字符冲突,特别是用括号括起来的字符“f”

为了避免数学中的字符冲突,特别是用括号括起来的字符“f”

我试图避免斜体字符被括号括起来时发生字符冲突 [例如,(f)]

在...的帮助下链接,当字符f被括号括起来时,我可以得到正确的输出();同时,当字符f后面跟着另一个字母时,我可以得到有空格的字符,例如df

  1. 如何通过宏避免字符后面跟着其他字母时出现的多余空格?

  2. 如何在斜体希腊字符和上标字符之间添加额外的空格(以避免字符冲突),$\zeta^\prime$$\psi^*$

在此处输入图片描述

梅威瑟:

为了 MWE 目的,我使用了 CMR 字体,实际上我正在使用其他字体(Minion),当使用 CMR 字体时不会出现字符冲突

\documentclass{book}


\makeatletter

\AtBeginDocument{%
    \Umathcharnumdef\math@f\Umathcodenum`f
    \mathcode`f=\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\Umathcodenum`j
    \mathcode`j=\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\Umathcodenum`p
    \mathcode`p=\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\Umathcodenum`d
    \mathcode`d=\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\Umathcodenum`g
    \mathcode`g=\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\Umathcodenum`l
    \mathcode`l=\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}

相关内容