简体   繁体   English

MathJax,Rails 4,Markdown集成

[英]MathJax, Rails 4, Markdown integration

Does anyone have an idea of how i can integrate: 有没有人知道我如何整合:

Mathjax latest release(mathjax-MathJax-v2.2-8-g727332c), Rails 4 and Markdown? Mathjax最新发布(mathjax-MathJax-v2.2-8-g727332c),Rails 4和Markdown?

This whole asset pipeline thing is making it hard for me to get to grips with how i can configure mathjax so that it can work with Markdown. 这整个资产管道的事情让我很难掌握如何配置mathjax以便它可以与Markdown一起使用。

Any takers? 任何接受者?

If you don't want to implement MathJax via the CDN link download the latest version of Mathjax here: http://docs.mathjax.org/en/latest/installation.html 如果您不想通过CDN链接实现MathJax,请在此处下载最新版本的Mathjax: http ://docs.mathjax.org/en/latest/installation.html

(Via git: git clone git://github.com/mathjax/MathJax.git MathJax ) (通过git: git clone git://github.com/mathjax/MathJax.git MathJax

Create a new directory app/assets/javascripts/mathjax in your rails app and put the content from MathJax/unpacked into this new directory. 在rails应用程序中创建一个新目录app/assets/javascripts/mathjax ,并将MathJax/unpacked的内容放入这个新目录中。 ( You can remove unwanted config , localization , etc. files if you want ). 如果需要,您可以删除不需要的配置本地化等文件 )。

Also copy the entire MathJax/images directory and put it into your rails app under app/assets/images . 同时复制整个MathJax/images目录并将其放入app/assets/images下的rails应用app/assets/images

Now add the following code directly before the closing </head> tag like this: 现在直接在结束</head>标记之前添加以下代码,如下所示:

<head>
  ...
  <%= javascript_include_tag "mathjax/MathJax.js?config=TeX-AMS_HTML-full.js", "data-turbolinks-track" => true %>
</head>

To change your MathJax config just replace the content of the config parameter: ?config=my-config.js 要更改MathJax配置,只需替换config参数的内容: ?config=my-config.js

And voilà! 瞧!


I don't know which system you're using for processing markdown but MathJax states ( http://docs.mathjax.org/en/latest/tex.html#tex-and-latex-in-html-documents ) that the backtick (`) is used to mark verbatim text so it doesn't get processed by markdown before MathJax can lay its hand on it: 我不知道你使用哪个系统来处理markdown,但是MathJax声明( http://docs.mathjax.org/en/latest/tex.html#tex-and-latex-in-html-documents ) backtick(`)用于标记逐字文本,因此在MathJax可以放置它之前,它不会被markdown处理:

... we have `\(x_1 = 132\)` and `\(x_2 = 370\)` and so ...

I've been looking for the answer as well, and managed to finally figure it out. 我一直在寻找答案,并设法最终弄明白。

Add the Mathjax CDN to youtapplication.html.erb file 将Mathjax CDN添加到youtapplication.html.erb文件中

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

or add the rails gem (Although, it took me ~15 mins to install!) 或添加rails gem(虽然,我花了大约15分钟安装!)

https://github.com/manusajith/mathjax_rails https://github.com/manusajith/mathjax_rails


Then, just add your math stuff within a <div> and $$ like so, 然后,只需在<div>$$添加数学内容,就像这样,

<div>$$(Gamma(z) = \int_0^\infty t^{z-1}e^{-t}dt\,.$$</div>

That should be it! 那应该是它! Working for me and easier than I thought. 为我工作比我想象的更容易。 I'm sure there is a better way so we don't need that <div> in there, but I don't know it yet. 我确信有更好的方法,所以我们不需要那里的<div> ,但我还不知道。

Hope it helps :D 希望它有所帮助:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM