MathJax 中的 \newcommand 宏产生不需要的额外空间
当我使用 LaTeX 宏(例如 \newcommand)时,它会占用页面空间。这是一个示例代码来演示我面临的问题。
URL: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>
这是其自己页面中的输出:< a href="http://fiddle.jshell.net/Lkeus/show/" rel="noreferrer">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>
How can I get rode this extra space?
When I use a LaTeX macro (\newcommand for example), it occupies space in the page. Here is an example code to demonstrate the issue I am facing.
URL: http://jsfiddle.net/Lkeus/
Code:
<!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>
Here is the output in its own page: http://fiddle.jshell.net/Lkeus/show/
In the output, you can see that the first line begins after some space. This space comes from the use of macros there. Firebug shows this code created by MathJax as the cause of the extra space:
<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>
How can I get rid of this extra space?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从 MathJax 社区学到了这个问题的一些解决方案。
通过将所有
\newcommand
放入单个\(
...中,可以最小化由于
。示例: http://jsfiddle.net/qQ9P9/\newcommand
造成的空白\)可以通过定义完全删除所有额外的空格HTML 的
部分中的宏。示例: http://jsfiddle.net/tVyJz/
I learnt a few solutions to this problem from the MathJax community.
It is possible to minimize the whitespace due to
\newcommand
by putting all the\newcommand
s into a single\(
...\)
. Example: http://jsfiddle.net/qQ9P9/It is possible to remove all the extra whitespace completely by defining the macros in the
<head>
section of the HTML. Example: http://jsfiddle.net/tVyJz/我一直在做的是将
newcommand
定义放在自己的段落(或 div)中,然后将其display
属性设置为none
:What I've been doing is putting the
newcommand
definitions in their own paragraph (or div) and then setting itsdisplay
attribute tonone
: