Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html MathJax中\newcommand宏不需要的额外空间_Html_Mathjax - Fatal编程技术网

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

Html MathJax中\newcommand宏不需要的额外空间,html,mathjax,Html,Mathjax,当我使用LaTeX宏(例如\newcommand)时,它会占用页面中的空间。下面是一个示例代码来演示我所面临的问题 网址: 代码: <!DOCTYPE html> <html> <head> <title>MathJax Example</title> <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js

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

网址:

代码:

<!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> 

MathJax示例

\(\newcommand{\N}{\mathbb{N}}\)
\(\newcommand{\R}{\mathbb{R}}\)
\(\newcommand{\Z}{\mathbb{Z}}\)
让\(x\in\N\)。那么\(x^2\)被称为完美正方形。

让\(x\in\N\)。那么\(x^2\)被称为完美正方形。

以下是其自身页面中的输出:

在输出中,您可以看到第一行在一些空格之后开始。这个空间来自于宏的使用。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>


我怎样才能去掉这个多余的空间呢?

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

通过将所有
\newcommand
放入一个
\(
..
\)
中,可以最小化由于
\newcommand
而产生的空白。例如:

通过在HTML的
部分定义宏,可以完全删除所有多余的空白。例如:


MathJax.Hub.Config({
特克斯:{
宏:{
N:“\\mathbb{N}”,
R:“\\mathbb{R}”,
Z:“\\mathbb{Z}”
} 
} 
}); 

我一直在做的是将
newcommand
定义放在它们自己的段落(或div)中,然后将其
display
属性设置为
none

<p style="display:none"> 
\(\newcommand{\N}{\mathbb{N}}\) 
\(\newcommand{\R}{\mathbb{R}}\) 
\(\newcommand{\Z}{\mathbb{Z}}\) 
</p>
<p>
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> 

\(\newcommand{\N}{\mathbb{N}}\) \(\newcommand{\R}{\mathbb{R}}\) \(\newcommand{\Z}{\mathbb{Z}}\)

让\(x\in\N\)。那么\(x^2\)被称为完美正方形。

让\(x\in\N\)。那么\(x^2\)被称为完美正方形。


FWIW,这至少有一个缺点:您不能以这种方式使用
\def
-风格的分隔参数,因为您只能说宏接受了多少个参数。因此,在文本中使用
\def
更为灵活。未来注意:cdn.mathjax.org的生命即将结束,请查看迁移提示(也许还可以为未来读者更新您的帖子)。
<script type="text/x-mathjax-config"> 
MathJax.Hub.Config({ 
    TeX: { 
        Macros: { 
            N: "\\mathbb{N}", 
            R: "\\mathbb{R}", 
            Z: "\\mathbb{Z}" 
        } 
    } 
}); 
</script> 
<p style="display:none"> 
\(\newcommand{\N}{\mathbb{N}}\) 
\(\newcommand{\R}{\mathbb{R}}\) 
\(\newcommand{\Z}{\mathbb{Z}}\) 
</p>
<p>
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>