网络上的数学方程
如何在网络上呈现数学方程? 我已经熟悉 LaTeX 的数学模式了。
How can I render Math equations on the web? I am already familiar with LaTeX's Math mode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何在网络上呈现数学方程? 我已经熟悉 LaTeX 的数学模式了。
How can I render Math equations on the web? I am already familiar with LaTeX's Math mode.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(16)
其他答案已经过时了。 截至 2012 年,美丽的数学很容易编写和呈现。 该技术称为 MathJax。 您可以在 MathOverflow 和数百个数学博客上看到它的安静运行。
Mathjax 可靠且不引人注目,因此您只需编写数学即可。 您可以使用 Tex (Latex) 来完成此操作,这是一种大多数科学家和数学家都熟悉的简洁语法(并且已经分享了数十年的优秀教程)。 对于 Mathjax,您只需在 HTML 中的双美元符号之间内嵌 Tex 代码,例如。
要使用 Mathjax 渲染数学,请在 HTML 标头中放入 Javascript 行:
如果您在 Wordpress、Tumblr 或 Blogger 等平台上发布内容,他们的库中有插件可以执行此操作(Wordpress)。
Mathjax 如何渲染数学? 使用 Javascript,它可以在几分之一秒内将您的数学呈现为漂亮的 HTML 和 CSS(非常类似于 Latex)。 如果浏览器支持 MathML,它也可以通过它呈现数学,但这并不重要。 它之所以获得广泛的成功,是因为最终用户的工作流程很简单,而不是因为其背后的技术。
如果您有帐户,您可以选择在维基百科上使用 Mathjax(通过 png 图像)。 寻找
特殊:首选项
/外观。MathML 很荒谬。 它既不是人类可读的,也不是人类可写的(二次方程采用 800 个字符 - 在 Tex 中是 50)。 它只是另一种毫无意义的XML语言。 值得庆幸的是,在大多数浏览器支持它之前它就已经过时了。 它甚至看起来不如Tex或Mathjax的HTML-CSS!
The other answers are out-of-date. As of 2012, beautiful math is easy to write and render. The technology is called MathJax. You can see it in quiet action on MathOverflow and hundreds of math blogs.
Mathjax is reliable and unobtrusive, so you just need to write the math. You do so in Tex (Latex), a concise syntax with which most scientists and mathematicians are familiar (and have shared decades of good tutorials). For Mathjax, you simply write Tex code in-line in your HTML between double dollar signs, eg.
To use Mathjax to render your math, put a Javascript line in your HTML header:
If you publish on a platform such as Wordpress, Tumblr or Blogger there are plug-ins in their galleries to do this (Wordpress).
How does Mathjax render math? With Javascript it renders your math to beautiful HTML and CSS (remarkably resembling Latex) in a fraction of a second. If a browser supports MathML, it can render math through that too, but that's not important. It's a popular success because the end-user workflow is easy, not because of the technology behind it.
You can choose to use Mathjax (over png images) on Wikipedia if you have an account. Look for
Special:Preferences
/ Appearance.MathML is ridiculous. It's neither human-readable nor human-writable (the quadratic equation takes 800 characters - it's 50 in Tex). It's just another pointless XML language . Thankfully, it's obsolete before most browsers support it. It doesn't even look as good as Tex or Mathjax's HTML-CSS!
事实证明这有点痛苦。
您可以使用 MathML,但浏览器支持仍然存在问题。 如果您从 Latex 开始,您有一些转换为 html 的选项,但它们通常最终都会将实际方程渲染为图像并内联它们。
没有什么那么漂亮(除非你求助于pdf之类的东西)。 什么是最好的,这在一定程度上取决于内容的类型、方程的数量以及方程的复杂程度。
这里是一个不错的总结。
It turns out this is a bit of a pain.
You can use MathML, but browser support is still iffy. If you are starting with latex you've got a few options for converting to html, but they'll all typically end up rendering the actual equations to images and inlining those.
Nothings all that pretty (unless you resort to pdf or something). What's best will depend a bit on what sort of content, how many equations, and how complicated the equations are.
Here is a decent summary.
我最喜欢的两种方法:
客户端:MathJax。 请参阅此处的一些示例。 它非常易于使用和安装,其开发由 AMS 和 SIAM 等科学机构支持 。 我希望这成为在网络上显示数学的事实标准。
服务器端:LaTeXML。 这用于生成NIST 数学函数数字库。 如果您的 TeX 源代码中有自定义宏,它往往会出现问题,但总的来说,它确实会给出非常好的结果。
My two favorite approaches:
Client-side: MathJax. See some examples here. It is very easy to use and install and its development is backed by the AMS and SIAM among other scientific institutions. I expect this to become the defacto standard for displaying math on the Web.
Server-side: LaTeXML. This is used for producing the NIST Digital Library of Mathematical Functions. It tends to hiccup if you have custom macros in your TeX sources but in general it does give very good results.
Katex
来自 Khan Academy 发布了一个基于 Tex 的速度极快库,名为 Katex:
看起来是一个很棒的现代选择。
Katex
A couple of developers from the Khan Academy released a blazing quick library based off of Tex called Katex:
Looks like a great modern option.
jsMath 包是另一个使用 LaTeX 标记和原生字体的选项。 引用他们的网页 http://www.math.union.edu/~dpvc/jsMath/ :
例如,请参阅此页面或那个。
The jsMath package is another option that uses LaTeX markup and native fonts. Quoting from their webpage http://www.math.union.edu/~dpvc/jsMath/:
See for example this page or that one.
您可以直接在 HTML 中完成比大多数人想象的更多的数学运算。 请参阅这些注释。
渲染 LaTeX 的唯一安全方法是将输出保存为图像。 有些网站尝试使用工具来即时执行此操作,但它们从来都无法可靠地工作。 例如,在某些博客上,如果您直接访问网页,则此方法有效,但如果您通过 Feedburner/Google Reader 则无效。
我在 Firefox 和 IE 中的 MathML 浏览器支持方面经历过糟糕的经历。 甚至不要尝试。 还没有。 也许几年后。
这是我用来将 LaTeX 编译为 gif 的站点。
如果您愿意使用 PDF 而不是 HTML,事情就会变得容易得多。 只需创建您的 LaTeX 文档并使用 pdflatex 将其编译为 PDF。 如果您选择 PDF 路线,您可能会对 如何在 LaTeX 文件中包含 PDF 属性,例如作者、关键字等。 另外,此页面< /a> 解释了如何标记 LaTeX 以在 PDF 中建立链接。
You can do more math directly in HTML than most people realize. See these notes.
The only safe way to render LaTeX is to save the output as an image. Some sites try to use tools to do this on the fly, and they never work reliably. For example, on some blogs, this works if you visit the web page directly but not if you go through Feedburner/Google Reader.
I've had terrible experience with MathML browser support, both in Firefox and IE. Don't even try it. Not yet. Maybe in a few years.
Here's the site I use to compile LaTeX to gifs.
If you're willing to use PDF instead of HTML, things get much easier. Just create your LaTeX document and use
pdflatex
to compile it to PDF. If you do go the PDF route, you may be interested in how to include PDF properties such as author, keywords, etc. in your LaTeX file. Also, this page explains how to mark up the LaTeX to make links in your PDF.texvc 可以将 LaTeX 数学方程转换为 png 或 HTML。
texvc can convert LaTeX math equations to png or HTML.
LaTeX 和 MathML 是执行此操作的唯一“正确”方法。 然而,每种方法都有严重的局限性。 其他选项是图像(如果您稍后需要编辑方程,则不是最佳选择)或复杂的 HTML(需要一些培训,但可以完成)。
LaTeX and MathML are the only "right" ways to do this. However each has severe limitations. The other options are images (not really optimal if you need to edit the equations later) or complex HTML(requires some training but can be done).
我确实在我的 wiki 中“按需”呈现 LaTeX 公式。 基本上,我从每个 wiki 部分中提取乳胶代码并将其放入 .tex 文件中(其文件名是乳胶的 md5sum,因此如果再次使用相同的代码,则将使用相同的 tex,因此将使用相同的图像) 。
然后,每分钟由 cron 任务对 tex 文件进行 Latex 编译,首先生成 .ps,然后使用转换程序生成 .png(再次使用原始 md5 命名)。 wiki 条目将 Latex 文本替换为引用该 png 的 img 标签(将原始 Latex 代码作为替代,供文本阅读器使用)。
如果您想这样做,请非常小心地尽可能对乳胶进行消毒。 Latex 中有一些命令,例如 \input,您绝对不想让它通过,因为任何能够使用它们的人都可以在您的服务器磁盘中包含任何可读文件,并将其包含在生成的 Latex 输出中。
为了解决这个问题,Mediawiki(维基百科名声大噪)有一个特殊的插件,可以清理乳胶输入,但我不想使用它有两个原因:首先我没有使用 mediawiki,其次它是用 OCaml 编写的,我没有使用它不想搞乱我不懂的语言。
I do render LaTeX formulas "on demand" in my wiki. Basically, I extract the latex code from each wiki section and put it into a .tex file (whose filename is an md5sum of the latex, so if the same code is used again, the same tex and therefore the same image will be used).
The tex file is then latex compiled by a cron task every minute, to produce first a .ps, then with the convert program a .png (named again with the original md5). The wiki entry replaces the latex text with an img tag referring to this png (with the original latex code as an alt, for text readers).
If you want to go this way, be very careful to sanitize your latex as much as you can. there are commands in latex, like \input, that you definitely do not want to let go through, as anybody able to use them would be able to include any readable file in your server disk and include it in the resulting latex output.
To solve this issue, Mediawiki (of wikipedia fame) has a special plugin which sanitizes the latex input, but I didn't want to use it for two reasons: first I did not use mediawiki, second it's written in OCaml and I didn't want to mess with a language I don't know.
我过去曾使用 ASCIIMathML 来完成此任务。 它本质上是一个 JavaScript 库,可以在 IE 中使用插件来优化性能,但也可以在 IE 和 Windows 中没有它的情况下工作。 Firefox/Mozilla(虽然慢一点)。 该语法支持 LaTeX 的子集,但差异会导致一些混乱,因此可能会让您的用户感到困惑,具体取决于他们来自哪里。
这里有一些链接,您可以自己查看:
并不完美,不适用于所有浏览器(Safari 等),但至少在今天它是有效的,尽管是在网络的一个有选择性的子集中。
I've used ASCIIMathML for this in the past. It's essentially a JavaScript library and can use a plugin in IE to optimize performance, but also works without it in IE & Firefox/Mozilla (although a bit slower). The syntax supports a subset of LaTeX, but the differences cause some confusion, so it may confuse your users, depending on where they are coming from.
Here are some links so you can check it out yourself:
Not perfect and doesn't work in all browsers (Safari, etc) but it's something that works today at least, albeit in a somewhat selective subset of the web.
我编写了一个开源 JavaScript 模块来执行此操作,名为 jqmath。 请参阅http://mathscribe.com/author/jqmath.html。 您可以使用简化的类似 TeX 的语法输入方程,jqmath 会将它们转换为 MathML 或简单的 HTML 和 CSS,具体取决于浏览器。 这比使用图像更有效且更易于访问。
顺便说一句,这里其他答案中提到的一些摘要和注释现在已经相当过时了。 此外,Firefox 现在支持 MathML,而 webkit(Chrome 和 Safari)在其夜间版本中也有它,尽管他们还没有发布它。 如果您有 MathPlayer 插件,则 Internet Explorer 会呈现 MathML。 Opera 用样式表伪造了 MathML。 MathML 是 HTML 5 标准的一部分,因此想必所有这些浏览器迟早都会原生支持它。 确实,在那之前,jqmath 的输出看起来不会像 TeX 那样好,但它肯定是可读的,并且绝对是未来网页的更好解决方案。
I've written an open source javascript module to do this, named jqmath. See http://mathscribe.com/author/jqmath.html. You type equations in a simplified TeX-like syntax, and jqmath converts them to MathML or simple HTML and CSS, depending on the browser. This is more efficient and accessible than using images.
By the way, some of the summaries and notes mentioned in the other answers here are pretty outdated now. Also, Firefox supports MathML now, and webkit (Chrome and Safari) have it in their nightly builds, though they haven't released it yet. Internet Explorer renders MathML if you have the MathPlayer plugin. Opera fakes MathML with a stylesheet. MathML is part of the HTML 5 standard, so presumably all these browsers will natively support it sooner rather than later. It's true that until then, jqmath's output will not look as good as TeX's, but it's certainly readable, and is definitely a better solution for web pages going forward.
如果您确实使用图像,盲人用户的读者是否能够阅读方程式? 有些人可能想要。
If you do use images, will a reader for a blind user be able to read the equation? Some may want to.
有一个名为 LatexIt 的小 Mac 应用程序,可以非常轻松地将 LaTeX 方程转换为 PDF、PNG 等
(我用它为 Keynote 或 PowerPoint 中的幻灯片创建方程。它非常好,支持拖放,因此您只需将方程“拖动”到任何位置即可插入它们。)
There is a little Mac App called LatexIt that makes it very easy to convert LaTeX equations to PDF, PNGs etc.
(I use it to create equations for my slides in Keynote or PowerPoint. It's very nice, with drag 'n drop support, so you can just 'drag' the equations anywhere to insert them.)
我的印象是 MediaWiki 将允许您输入 LaTeX 标记(或类似的东西)并动态决定显示它的最佳方式。 目前,我认为对于小型表达式,应尽可能使用 HTML;对于无法用其他方式表示的更复杂的表达式,应使用图像; 我怀疑有一天,如果浏览器开始支持它,它可能会利用任何其他最先进的方法,即 MathML。 因此,我认为您可能会发现,如果您使用 MediaWiki,就好像它是您的网站引擎一样,您将与未来出现的任何内容向前兼容。
I have the impression that MediaWiki will allow you to enter LaTeX markup (or something similar) and dynamically decide the best way to display it. Currently I think that uses HTML where possible for small expressions and images for more complicated expressions that cannot be represented otherwise; I suspect that one day it may take advantage of whatever other methods become state of the art, i.e., MathML if browsers start supporting it. So I think you might find that if you use MediaWiki as if it were your website engine you'll be forward-compatible with whatever comes in the future.
您可以通过 LaTeX 服务器即时生成方程图像。
http://www.forkosh.com/mimetex.html
如果您使用的是 WordPress,则可以使用 LaTeX for WordPress (http://wordpress.org/extend/plugins/latex/) 插件。
You can generate equation image on-the-fly via a LaTeX server.
http://www.forkosh.com/mimetex.html
If you are using WordPress, you can use LaTeX for WordPress (http://wordpress.org/extend/plugins/latex/) plugin.
目前,客户端 MathML 渲染的状态尚未准备好广泛采用。 这意味着您确实需要将 MathML 渲染为图像。 如何执行此操作取决于您的环境。
您有自己服务器的 root 访问权限吗? 您可以在上面安装软件吗? 在这种情况下,您可以渲染自己的图像。 如果您正在运行博客软件或维基,通常您可以找到一个可以利用您平台功能的插件。 如果您计划编写大量数学表达式,这通常是您的想法场景。
如果您托管自己的图像,则可以预先渲染它们,或使用 mimetex.cgi 等扩展名。 如果您允许渲染任意 MathML 表达式,则您将面临其他网站热链接到您的图像渲染器的风险。 如果您在网络服务器上放置过滤器以防止热链接,那么通过提要阅读器查看您网站的人也将被阻止。
如果您无法渲染自己的图像,或者您只想渲染几个表达式,那么您通常可以让其他服务生成图像,然后在您的网站上热链接该图像。 当然,缺点是您依赖另一个网站,而该网站为您提供图像不会得到任何回报。
其他服务的示例(如其他评论中提到的)包括:
* http://www.artofproblemsolving.com/LaTeX/AoPS_L_TeXer.php : < a href="http://alt2.artofproblemsolving.com/Forum/latexrender/pictures/a/f/c/afc183343d84d030898f589bac12a8d9cf04558a.gif" rel="nofollow noreferrer">替代文本 http://alt2.artofproblemsolving.com/Forum /latexrender/图片/a/f/c/afc183343d84d030898f589bac12a8d9cf04558a.gif
* http://www.forkosh.com/mimetex.html : mimetex.cgi http://www.forkosh.dreamhost .com/mimetex.cgi?c=%5Csqrt%7Ba%5E2+b%5E2%7D
使用 mimetex 的优点是可以轻松更改公式并重新渲染。
Currently the state of client side MathML rendering isn't ready for broad adoption. The means you really need to render the MathML as an image. How you do this will depend on your environment.
Do you have root access to your own server? Are you comfortable installing software on it? In this case, you can render your own images. If your running blogging software or a wiki, generally you can find a plugin which will take advantage of your platforms capabilities. This is usually the idea scenario if you plan to write a lot of math expressions.
If you host your own images, you can either pre-render them, or use an extension like mimetex.cgi. If you allow arbitrary MathML expressions to be rendered, you run the risk of other websites hot linking to your image renderer. If you put a filter in on your web server to prevent hot linking, then people viewing your site through a feed reader will also be blocked.
If you can't render your own images, or if you only have a few expressions you want to render, then you can usually have another service generate the image, and you hot link the image on your site. The downside of course is your dependent on another site, who gets nothing in return for serving up images for you.
Examples of other services (as mentioned in other comments) include:
* http://www.artofproblemsolving.com/LaTeX/AoPS_L_TeXer.php : alt text http://alt2.artofproblemsolving.com/Forum/latexrender/pictures/a/f/c/afc183343d84d030898f589bac12a8d9cf04558a.gif
* http://www.forkosh.com/mimetex.html : mimetex.cgi http://www.forkosh.dreamhost.com/mimetex.cgi?c=%5Csqrt%7Ba%5E2+b%5E2%7D
The advantage of using mimetex is one can easily change the formula and have it re-rendered.