
我一直在努力尋找這個問題的答案,但一直找不到。我正在寫一篇文章,我必須寫很多公式,對我來說,寫起來
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
不僅用在逗號之後,而且用在其他幾個地方,這些地方也會受到同樣擴大的空間的影響。