MathJax 中 \newcommand 宏不需要的额外空间

Lon*_*ner 5 html mathjax

当我使用 LaTeX 宏(例如 \newcommand)时,它会占用页面中的空间。这是一个示例代码,用于演示我面临的问题。

网址:http : //jsfiddle.net/Lkeus/

代码:

<!DOCTYPE html> 
<html> 
<head> 
<title>MathJax Example</title> 
<script 
type="text/javascript" 
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=default"> 
</script> 
</head> 
<body> 
<p> 
\(\newcommand{\N}{\mathbb{N}}\) 
\(\newcommand{\R}{\mathbb{R}}\) 
\(\newcommand{\Z}{\mathbb{Z}}\) 
Let \(x \in \N\). Then \(x^2\) is called a perfect square. 
</p> 
<p> 
Let \(x \in \N\). Then \(x^2\) is called a perfect square. 
</p> 
</body> 
</html> 
Run Code Online (Sandbox Code Playgroud)

这是它自己页面中的输出:http : //fiddle.jshell.net/Lkeus/show/

在输出中,您可以看到第一行在一些空格之后开始。这个空间来自那里使用宏。Firebug 将 MathJax 创建的这段代码显示为额外空间的原因:

<span class="math" id="MathJax-Span-1"> 
<span style="display: inline-block; position: relative; width: 0em; 
height: 0pt; font-size: 130%;"> 
<span style="position: absolute; top: -1em; left: 0em; clip: 
rect(0.856em, 1000em, 1.144em, -0.433em);"> 
<span class="mrow" id="MathJax-Span-2"></span> 
<span style="display: inline-block; width: 0pt; height: 1em;"></span> 
</span></span> 
<span style="border-left: 0em solid; display: inline-block; overflow: 
hidden; width: 0pt; height: 0em; vertical-align: 0em;"></span></span>
Run Code Online (Sandbox Code Playgroud)

我怎样才能摆脱这个额外的空间?

Lon*_*ner 5

我从 MathJax 社区学到了一些解决这个问题的方法。

可以\newcommand通过将所有\newcommands 放入单个\(...来最小化空格\)。示例:http : //jsfiddle.net/qQ9P9/

\(\newcommand{\N}{\mathbb{N}}
\newcommand{\R}{\mathbb{R}}
\newcommand{\Z}{\mathbb{Z}}\)
Run Code Online (Sandbox Code Playgroud)

通过<head>在 HTML的部分中定义宏,可以完全删除所有额外的空格。示例:http : //jsfiddle.net/tVyJz/

<script type="text/x-mathjax-config"> 
MathJax.Hub.Config({ 
    TeX: { 
        Macros: { 
            N: "\\mathbb{N}", 
            R: "\\mathbb{R}", 
            Z: "\\mathbb{Z}" 
        } 
    } 
}); 
</script> 
Run Code Online (Sandbox Code Playgroud)