在數學模式下逗號後留出空格

在數學模式下逗號後留出空格

我一直在努力尋找這個問題的答案,但一直找不到。我正在寫一篇文章,我必須寫很多公式,對我來說,寫起來 f(x, y)比寫更漂亮f(x,y)。我厭倦了\,在數學模式下總是在逗號後面寫一個薄空格,而且這也很令人困惑。有沒有辦法自動執行此操作?

答案1

如果您願意之後有更多空間每一個數學模式下的逗號。

\documentclass{article}

\AtBeginDocument{%
  \mathchardef\stdcomma=\mathcode`,
  \mathcode`,="8000
}
\begingroup\lccode`~=`, \lowercase{\endgroup\def~}{\stdcomma\,}

\begin{document}

$f(x,y)$

$a,b,c$

\end{document}

在此輸入影像描述

如果您只需要在指定變數時使用空格,則可以使用與 package 相同的方法icomma,但這需要輸入規則:如果逗號後面接空格(在數學模式下),則會新增一個薄空格。

\documentclass{article}

\makeatletter
\AtBeginDocument{%
  \mathchardef\stdcomma=\mathcode`,
  \mathcode`,="8000
}
\begingroup\lccode`~=`, \lowercase{\endgroup\def~}{%
  \futurelet\@let@token\spaced@comma
}
\newcommand{\spaced@comma}{%
  \stdcomma
  \ifx\@let@token\@sptoken\,\fi
}
\makeatother

\begin{document}

$f(x, y)$ % added space

$f(x,y)$ % compare with the standard

$a,b,c$ % no space is added

\end{document}

在此輸入影像描述

我會避免設定\thinmuskip為更大的值。原因如下。

\documentclass{article}

\thinmuskip=6mu

\begin{document}

$f(x,y)=\sin x-\sin y$ % with the new setting

\thinmuskip=3mu

$f(x,y)=\sin x-\sin y$ % with the standard setting

\end{document}

在此輸入影像描述

正如你所看到的,\thinmuskip不僅用在逗號之後,而且用在其他幾個地方,這些地方也會受到同樣擴大的空間的影響。

答案2

,\mathpunct除非您更改了設置,否則預設情況下空間很小。與之比較{,}

在此輸入影像描述

\documentclass{article}

\begin{document}

$f(x, y)$

$f(x{,} y)$

\end{document}

答案3

您也可以使用所需的空間定義自己的命令:

\documentclass{article}

\newcommand{\fxy}{$f(x,\,y)$}

\begin{document}
    \fxy, compared to
    

    $f(x,y)$
    
\end{document}

在此輸入影像描述

相關內容