5

当我使用 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> 

这是它自己页面中的输出: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>

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

4

2 回答 2

5

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

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

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

<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> 
于 2012-02-20T15:15:37.637 回答
3

我一直在做的是将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> 
于 2014-01-23T18:15:53.413 回答