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

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

问题描述

我希望我的 MathJax 在 IPython Notebook 中显示的方程左对齐而不是居中.这由 MathJax 中的核心配置选项 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 文件中来在 IPython Notebook 中设置此选项

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:AnacondaLibsite-packagesIPythonhtmlstatic otebookjsmathjaxutils‌ .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:AnacondaLibsite-packagesIPythonhtmlstatic otebookjsmathjaxutils‌​.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.

推荐答案

使用 egin{align}end{align}.这并不能完全回答问题,但它具有预期的效果.例如尝试:

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

$
egin{align}
frac{1}{2} 	imes frac{3}{2} = frac{3}{4}
end{align}
$

上面的渲染完全一样,

$$
frac{1}{2} 	imes frac{3}{2} = frac{3}{4}
$$

除了它是左对齐的.

这种方法的额外优势是可以添加其他对齐方式,例如:

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

$
egin{align}
dot{x} & = sigma(y-x) \
dot{y} & = 
ho x - y - xz \
dot{z} & = -eta z + xy
end{align}
$

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

This last code block is from Motivating Examples in the Jupyter Notebook docs.

可以在此处找到对齐方程的其他示例 对齐多个方程

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

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

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