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

发布于 2025-01-06 22:44:12 字数 1628 浏览 0 评论 0原文

当我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月静好 2025-01-13 22:44:12

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

通过将所有 \newcommand 放入单个 \(...中,可以最小化由于 \newcommand 造成的空白\)。示例: http://jsfiddle.net/qQ9P9/

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

可以通过定义完全删除所有额外的空格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> 

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 \newcommands into a single \(...\). Example: http://jsfiddle.net/qQ9P9/

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

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/

<script type="text/x-mathjax-config"> 
MathJax.Hub.Config({ 
    TeX: { 
        Macros: { 
            N: "\\mathbb{N}", 
            R: "\\mathbb{R}", 
            Z: "\\mathbb{Z}" 
        } 
    } 
}); 
</script> 
人间不值得 2025-01-13 22:44:12

我一直在做的是将 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> 

What I've been doing is putting the newcommand definitions in their own paragraph (or div) and then setting its display attribute to 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> 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文