![如何在所有内联方程式周围添加空格,调整标点符号](https://linux22.com/image/310628/%E5%A6%82%E4%BD%95%E5%9C%A8%E6%89%80%E6%9C%89%E5%86%85%E8%81%94%E6%96%B9%E7%A8%8B%E5%BC%8F%E5%91%A8%E5%9B%B4%E6%B7%BB%E5%8A%A0%E7%A9%BA%E6%A0%BC%EF%BC%8C%E8%B0%83%E6%95%B4%E6%A0%87%E7%82%B9%E7%AC%A6%E5%8F%B7.png)
答案这个问题解释了如何在内联方程式周围添加空格,但它没有考虑标点符号。您可以在下图中看到我的意思。
有没有办法把空格放在逗号后面,而不是前面?将逗号放在公式环境中的明显解决方案,例如,$A = \pi r^2,$
由于字体不同(我使用的是 XeLaTeX),所以不起作用。也就是说,除非您每次都手动指定逗号应该是不同的字体,但我希望有一个更懒惰的解决方案(它考虑了所有正常标点符号:句号、逗号、分号等)。
答案1
如果使用非零值\mathsurround
,则应在公式内添加标点符号,然后恢复空间因子。
\documentclass{article}
\newcommand{\fp}[1]{%
\mbox{#1\xdef\fpsf{\the\spacefactor}}%
\aftergroup\setfpsf
}
\newcommand\setfpsf{\spacefactor\fpsf\relax}
\begin{document}
The area of a circle is given by $A=\pi r^2$, where $r$ is its radius.
The length of the circumference is $C=2\pi r$. Easy.
\mathsurround=6pt \xspaceskip=10pt
The area of a circle is given by $A=\pi r^2$, where $r$ is its radius.
The length of the circumference is $C=2\pi r$. Easy.
The area of a circle is given by $A=\pi r^2,$ where $r$ is its radius.
The length of the circumference is $C=2\pi r.$ Easy.
The area of a circle is given by $A=\pi r^2\fp{,}$ where $r$ is its radius.
The length of the circumference is $C=2\pi r\fp{.}$ Easy.
\end{document}
这里的设置被夸大了\xspaceskip
,只是为了测试在适当的时候插入额外的空间(第四段)。
以下是输出
The area of a circle is given by $A=\pi r^2\fp{,}$ where $r$ is its radius.
The length of the circumference is $C=2\pi r\fp{.}$ Easy.
何时\mathsurround=3pt
使用:
答案2
虽然我无法在命令中不带虚假空格的情况下重现您的示例\text
(参见注释),但您可以使用\kern
(数学模式之外)或\mkern
(数学模式之内)来微调间距。请注意,\mkern
需要一个特殊单位,mu
而不是您通常的pt
。
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\text{The area }A\text{ of a circle is given by } A=\pi r^2\text{ , where $r$ is its radius.}% notice the space between the opening brace and the comma.
\]
The area $A$ of a circle is given by $A=\pi r^2$, where $r$ is its radius.
\[
\text{The area }A\text{ of a circle is given by } A=\pi r^2\text{\kern-4pt , where $r$ is its radius.}% kerning inside mathmode
\]
The area $A$ of a circle is given by $A=\pi r^2$\kern-4pt, where $r$ is its radius.% kern outside of math mode
\[
V=\sum\int \mkern25mu \frac{4\pi r^3\!\mathop{}\mathrm dx}{3}% example of math kerning (command \mkern). 18 mu = 1 em
\]
\end{document}
答案3
编辑:如果您使用 XeLaTeX,这个答案似乎不正确。
我没看到你的问题。这
\documentclass{article}
\begin{document}
The Area $A$ of a circle is given by $A=\pi r^2$, where $r$ is the radius.
\end{document}
结果是:
这绝对没问题。