如何获取MathJax以在ipython Notebook中启用mhchem扩展 [英] How do I get MathJax to enable the mhchem extension in ipython notebook

查看:134
本文介绍了如何获取MathJax以在ipython Notebook中启用mhchem扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,对我来说,这是一次非常令人沮丧的冒险.我已经连续几天花了很多时间试图让MathJax在ipython Notebook的Markdown单元中启用和识别mhchem扩展.数学表达式可以正常工作,但是无法识别mhchem宏\ce \cf \cee.我尝试在MathJax/config/default.js文件中启用扩展名.我尝试将以下脚本代码放入Markdown窗口

Okay, this has been a very frustrating adventure for me. I have spent many hours over several successive days trying to get MathJax to enable and recognize the mhchem extension within a Markdown cell in ipython notebook. Math expressions worked fine, but the mhchem macros \ce \cf \cee just go unrecognized. I have tried enabling the extension in the MathJax/config/default.js file. I tried putting the following script code with the Markdown window

<script type="text/x-mathjax-config">
MathJax.Hub.Config({TeX: {extensions:["TeX/mhchem.js"]}
...
});
</script>

我尝试了在互联网上可以找到的所有技巧和窍门.似乎什么都没用.

I have tried every trick and tip I could find on the internet. Nothing seems to work.

我正在运行debian wheezy.我以为可能是默认的mhchem和MathJax软件包导致了这个问题,所以我将用于ipython笔记本的MathJax的自定义版本安装到我的profile_default/static目录中,并配置了ipython来使用它.再次,数学很好,化学是行不通的.我可以直接从TeX使用mhchem扩展名,但是MathJax只是拒绝加载该扩展名或拒绝识别\ce标记.

I am running debian wheezy. I thought maybe the default mhchem and MathJax packages were causing the problem, so I installed a custom version of MathJax for ipython notebook into my profile_default/static directory and configured ipython to use this. Again, math fine, chemistry a no go. I am able to use the mhchem extensions directly from TeX but MathJax just refuses to load the extension or recognize the \ce tags.

我很困惑!

有人有什么主意吗?

推荐答案

感谢您的回答.我曾尝试使用不带Tex/的加载脚本.我尝试过/ce \ce.几乎所有可以想象的.我终于找到了解决方法,它是这样的:

Thanks for your answer. I had tried loading the script with an without the Tex/. I had tried /ce \ce. Just about everything imaginable. I finally found a solution and it was as follows:

如果我在数学表达式中使用非标准" /require宏来强制加载mhchem扩展名,则一切正常.

If I use the 'non-standard' /require macro within a math expression to force load the mhchem extension everything works great.

我在Markdown单元的顶部添加了以下代码

I added the following code at the top of the Markdown cell

$$\require{mhchem}$$       

奇怪的是,一旦我在第一个markdown单元的第一行中完成了此操作,它似乎就可以在整个笔记本电脑上正常工作了.甚至在我执行以下代码以测试mhchem扩展的代码页中:

Strangely, once I have done this in the first line of the first markdown cell, it seems to work flawlessly throughout the notebook. Even from within a code page where I was executing the following to test the mhchem extensions:

from IPython.display import display, Math, Latex                                                                                                                                                                                             
display(Math(r'F(k) = \int_{-\infty}^{\infty} f(x) e^{2\pi i k} dx'))                                                                                                                                                                     
display(Math(r'\ce{H2O}'))   

没有/require宏,上面的代码将正确生成数学函数,但是化学式将简单地呈现为'\ ceH2O'

Without the /require macro, the above code would generate the math function correctly but the chemistry formula would simply be rendered as '\ceH2O'

通过包含/require行,笔记本中的所有mhchem用法似乎都可以正常工作.

By including the /require line, all mhchem usage in the notebook seems to work fine.

另外,我应该注意,我正在运行从Debian Jesse存储库安装的ipython软件包.原来仍然是0.13.最后,我删除了这些软件包,并使用setuptools直接安装了1.10. MathJax在安装后即开即用.

Also, I should note that I was running the ipython packages installed from the Debian Jesse repositories. Turns out that is still 0.13. In the end, I removed these packages and installed 1.10 directly using the setuptools. The MathJax worked out of the box with this install.

无论如何,希望这可以为其他一些化学反应较差的用户节省一些挫败感

Anyway, hopefully, this will save some other poor chemistry user some frustration

这篇关于如何获取MathJax以在ipython Notebook中启用mhchem扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆