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.
I have tried to set this option in IPython Notebook by adding this to my config.js file
MathJax.Hub.Config({ displayAlign: "left" });
but it doesn't have any effect.
How can I set MathJax core configuration options in IPython Notebook?
[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.
[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.
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' });
and for good measure added this to my custom.css
<script> MathJax.Hub.Config({ displayAlign: 'left' }); </script>
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.
You separate lines in the equations with a double backslash ( // ). Insert an ampersand ( & ) in each line at the alignment point. All equations will be aligned at the location of the ampersand symbols (and, of course, the ampersands will not appear in the rendered equations).
You can select the line with mouse in jupyter notebook. Drag it up or down before the line where you want to move it. Press > button on keyboard while your text is still selected. This will bring the cursor to end of selected line, but before the text of line being replaced.
Any text in between \begin{flushleft}... \end{flushleft} will be aligned with the left-hand margin, but have a ragged right-hand edge. This is another case of a LaTeX environment. If you are already in an environment you can switch this style of alignment on in a different way using \raggedright .
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} $
The above renders exactly the same as,
$$ \frac{1}{2} \times \frac{3}{2} = \frac{3}{4} $$
except that it is left justified.
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} $
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
In Jupyter lab, I find that using a single $
left aligns, whereas double $
centers the equations
$ \begin{align} c & = (0,\mu)+(a,b)\\ & =(a, b+\mu) \end{align} $
is left aligned whereas
$$ \begin{align} c & = (0,\mu)+(a,b)\\ & =(a, b+\mu) \end{align} $$
is centered
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With