如何在IPython Notebook中更改显示方程式的对齐方式? [英] How to change alignment of displayed equations in IPython Notebook?

查看:174
本文介绍了如何在IPython Notebook中更改显示方程式的对齐方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的MathJax显示的IPython Notebook中的方程在左侧对齐而不是居中对齐.如displayAlign 控制. >这里.

I would like my MathJax displayed equations in IPython Notebook to be aligned at the left instead of centered. This is controlled by a core configuration option displayAlign in MathJax as described here.

我试图通过将其添加到我的 config.js 文件

I have tried to set this option in IPython Notebook by adding this to my config.js file

MathJax.Hub.Config({ 
    displayAlign: "left"
});

但没有任何作用.

如何在IPython Notebook中设置MathJax核心配置选项?

How can I set MathJax core configuration options in IPython Notebook?

[更新]我发现一种有效的方法:将上述配置行添加到 config.js 中,而不是添加到 mathjaxutils.js 中.在我的情况下(Windows 8),可以在以下位置找到此文件:C:\Anaconda\Lib\site-packages\IPython\html\static\notebook\js\mathjaxutils‌​.js.不过,这并不是一个很好的解决方案,因为它涉及到修改文件,而该文件在下次我更新IPython时可能会被覆盖.

[Update] I have found one way that works: add the above configuration lines not to config.js but to mathjaxutils.js. In my case (Windows 8) this file is found here: C:\Anaconda\Lib\site-packages\IPython\html\static\notebook\js\mathjaxutils‌​.js. This is not a great solution though because it involves modifying a file that will presumably get overwritten the next time I update IPython.

[更新] @Ian在注释中建议的技术确实有效,但一次只能使用一个笔记本.总而言之,我创建了一个文件 my_css.css ,其内容为

[Update] The technique suggested by @Ian in the comments does work, but just one notebook at a time. To summarize, I created a file my_css.css whose content is

<script>
    MathJax.Hub.Config({
        displayAlign: 'left'
    });
</script>

在笔记本中,如果我运行此单元格

In the notebook, if I run this cell

from IPython.core.display import HTML
css_file = 'my_css.css'
HTML(open(css_file, "r").read())

显示的方程式确实按需保持左对齐.

displayed equations do get left aligned, as desired.

但是,我希望这是所有笔记本电脑的默认设置.我尝试将其添加到我的 custom.js

However, I would like this to be the default for all my notebooks. I tried adding this to my custom.js

MathJax.Hub.Config({
    displayAlign: 'left'
});

并已将其添加到我的 custom.css

<script>
    MathJax.Hub.Config({
        displayAlign: 'left'
    });
</script>

但是两者都没有任何作用.如果有一种方法可以在不修改核心IPython文件的情况下将所有笔记本的默认设置都设为默认设置,那将是完美的选择.

But neither has any effect. If there is a way to make this setting a default for all notebooks without modifying the core IPython files, that would be perfect.

推荐答案

使用\begin{align}\end{align}.这不能完全回答问题,但是可以达到预期的效果.例如,尝试:

Use \begin{align} and \end{align}. This does not exactly answer the question but it has the desired effect. For example try:

$
\begin{align}
\frac{1}{2} \times \frac{3}{2} = \frac{3}{4}
\end{align}
$

上面的渲染与

$$
\frac{1}{2} \times \frac{3}{2} = \frac{3}{4}
$$

除了左对齐.

这种方法的另一个优点是可以添加其他对齐方式,如:

This approach has the added advantage that other alignments can be be added, as in:

$
\begin{align}
\dot{x} & = \sigma(y-x) \\
\dot{y} & = \rho x - y - xz \\
\dot{z} & = -\beta z + xy
\end{align}
$

最后一个代码块来自 Jupyter Notebook文档中的激励示例.

有关对齐方程式的其他示例,请参见此处对齐多个方程式

Other examples of aligning equations can be found here Aligning several equations

这篇关于如何在IPython Notebook中更改显示方程式的对齐方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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