如何僅在數學模式下將“'”和“\prime”更改為設定字體中的符號以及如何在斜體“f”兩側添加間距?

如何僅在數學模式下將“'”和“\prime”更改為設定字體中的符號以及如何在斜體“f”兩側添加間距?

首先,一個最小的工作示例如下:

\documentclass{article}
\usepackage{amsmath,amsfonts,amssymb,mathrsfs}
\usepackage{mathspec}
\setallmainfonts(Digits,Latin){Times}%a replacement of the font that I am using now
\title{Test}
\begin{document}
\maketitle

$a'+b=c^\prime$ and $(f),[f],\{f\}$.

\end{document}

它的輸出xelatex

在此輸入影像描述

所以我的問題是:

  1. 圖中的素數由程式碼生成'\prime兩者皆來自預設Computer Modern字體。那麼如何更改'設定字體\prime中的符號呢Times?希望是全球環境,而不是本地環境。
  2. 數學模式下斜體兩邊的空格f太小,導致括號 和f太近。那麼如何f僅在數學模式下(而不是在文字模式下)向斜體兩側添加間距呢?希望是全球環境,但也不是本地環境。

問題2已解決如下,那麼問題1誰能幫我?

答案1

您應該使用"f(對於其他字母也類似),如 手冊中提到的mathspec

請注意,'與 相同^{\prime}

\documentclass{article}
\usepackage{amsmath,amsfonts,amssymb,mathrsfs}
\usepackage{mathspec}
\setallmainfonts(Digits,Latin){Times}%a replacement of the font that I am using now
\title{Test}
\begin{document}
\maketitle

$a'+b="f^\prime$ and $("f),["f],\{"f\}$.

\end{document}

在此輸入影像描述

答案2

對於問題 2,我得到的答案來自連結在@egreg 的幫助下。我把答案貼在這裡:

\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}}%
    }
}
\makeatother

以下是修訂版的輸出:

在此輸入影像描述

相關內容