Ruby on Rails 中的 LaTeX 方程
如何
\frac{1}{2}
在 Ruby on Rails 应用程序中渲染 LaTeX 内容?我的意思是获取图像? 谢谢!
How can I render LaTeX stuff like
\frac{1}{2}
in a Ruby on Rails application? I mean to get an image?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您始终可以尝试 http://www.mathjax.org/,将渲染留给客户端!
You could always try http://www.mathjax.org/, leaving the rendering to the client!
要在网络上渲染 LaTeX,在我看来就像
mathTeX
是选择的应用程序。还有许多其他选项,所有这些选项似乎都以dvipng
为基础。MathTeX
似乎是最精致和最有能力的,并且很容易配置为 CGI 服务,因此您的 Rails 应用程序可以生成普通的 HTML标记复杂的 src 属性。
编辑:安装了 mathTeX 后,我可以说代码不灵活,它违反了 Linux 文件系统层次结构标准,而且它是业余工作——无论是好是坏。代码很复杂,没有明显的错误。我将寻找替代方案。
To render LaTeX for the web, it looks to me like
mathTeX
is the application of choice. There are many other options, all of which seem to build ondvipng
as a foundation.MathTeX
appears to be the most polished and capable, and it is easy to configure as a CGI service, so your Rails application can generated ordinary HTML<img>
tags with rather complexsrc
attributes.EDIT: Having installed mathTeX, I can say that the code is inflexible, that it violates the Linux Filesystem Hierarchy standard, and that it is amateur work—in both the good and bad senses of that word. The code is so complex that there are no obvious faults. I will be looking for alternatives.
通过调用为您进行处理的外部程序,例如
tex2png
或tex2png.pl
。再说一次,对于这样的简单公式,您可能还希望考虑使用 jsmath。下一步是让您的用户选择他们想要查看的版本......
By invoking an external program that does the processing for you, such as
tex2png
ortex2png.pl
.Then again, for simple formulas like that, you may also wish to consider using jsmath. The next step then would be to let your users choose which version they want to see …
Katex
看看 Katex。它来自 Khan Academy 背后的几个人,看起来非常合法。
它使用 Javascript 生成一个漂亮的公式 HTML 视图,因此我仍在研究将其方便地转换为图像的最佳方法。
Katex
Take a look at Katex. It's from a couple of people behind Khan Academy and it looks extremely legit.
This uses Javascript to generate a nice HTML view of the formulas so I'm still working out the best method to turn this into an image conveniently, though.
katex gem 可以在服务器端渲染这些内容,因此您甚至不需要任何 JavaScript,并且它比图像更小、质量更好。
The katex gem can render these server-side so you don't even need any JavaScript, and it's smaller and better quality than an image.
还有 数学 gem 可以将 TeX 数学转换为 SVG、PNG 或 MathML。
There is also mathematical gem that converts TeX math to SVGs, PNGs, or MathML.