How to change alignment of displayed equations in IPython Notebook? - jupyter-notebook

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.

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

You could try including a css file. For example, this set of notebooks pulls in this css file (see the final cell in the notebook) which does explicitly set the displayAlign tag, although it sets it to center.

Related

How to left-aling formulas and not center them in jupyter notebooks

I would like to know how to left-align formulas in jupyter notebooks and I would also like the formulas not to be centered, but to start at the left edge of the notebook.
I've already read many questions on the subject, but they all focus on saying how to align the formulas to the left, without explaining how to put them not centered.
This is what I have found so far:
$$
\begin{aligned}
& [-0.675\sigma - 1.5*(0.675\sigma-(-0.675\sigma)), 0.675\sigma + 1.5*(0.675\sigma-(-0.675\sigma))] =\\
& [-0.675\sigma - 2.025\sigma, 0.675\sigma + 2.025\sigma] =\\
& [ - 2.7\sigma, + 2.7\sigma]\\
\end{aligned}
$$
And this is what I get:
How can I make them not centered?
I don't know which version of MathJax Jupyter Noebook uses, but if you are using v3, you can use the flalign environment to do left alignment:
<script src="https://cdn.jsdelivr.net/npm/mathjax#3/es5/tex-chtml.js"></script>
\begin{flalign}
\,&[-0.675\sigma - 1.5*(0.675\sigma-(-0.675\sigma)), 0.675\sigma + 1.5*(0.675\sigma-(-0.675\sigma))] =&\\
\,&[-0.675\sigma - 2.025\sigma, 0.675\sigma + 2.025\sigma] =& \\
\,&[-2.7\sigma, + 2.7\sigma]&
\end{flalign}
Note that the first column has to be non-empty, which is why I put in the small spaces.

How to prevent Jupyter Notebook from cutting output?

When I print, for some reason Jupyter cuts some text out of the middle of output ( perhaps to make it more readable), but I need to see it.
What are the possible solutions?
Is there any option I can change in Jupyter to prevent if from cutting?
P.S. Sorry can't embed images yet. Use the link, thx.
enter image description here
my_pipeline = make_pipeline(ce.OneHotEncoder(use_cat_names=True),
SimpleImputer(),
XGBRegressor(n_estimators=1000,
learning_rate=0.01,
clf__early_stopping_rounds=10,
clf__eval_set=[(test_X, test_y)],
random_state=45,
verbose=True))
# fitting and predicting
print(my_pipeline.fit(train_X, train_y))
predictions = my_pipeline.predict(test_X)
print("Mean Absolute Error : " + str(mean_absolute_error(predictions,
test_y)))
OUTPUT:
Pipeline(memory=None,
steps=[('onehotencoder', OneHotEncoder(cols=['Neighborhood'], drop_invariant=False,
handle_unknown='impute', impute_missing=True, return_df=True,
use_cat_names=True, verbose=0)), ('simpleimputer', SimpleImputer(copy=True, fill_value=None, missing_values=nan, strategy='mean',
ver... reg_lambda=1, scale_pos_weight=1, seed=None, silent=True,
subsample=1, verbose=True))])
As you see on the OUTPUT by the "ver..." - it is cut. Thx.

How can I auto-indent double bracket notation using Atom, in my HTML files?

In my Atom editor, I have a simple shortcut on the keymap:
'atom-text-editor':
'alt-a': 'editor:auto-indent'
In my *.html files, it does not indent Blaze liquid-like tags, for example:
{{#if something}}
{{else}}
{{/if}}
I looked into Atom beautify, but it does not consider the double bracket notation. The beautifier currently attached to *.html is JS beautify. I tried to switch to pretty diff but, while it worked, it also corrupted the i18n helper nested in attributes, eg. title="{{_ "edit"}}" becomes title="{{_ " edit"}}"="edit"}}""
I installed the HTML beautifier gem as suggested in the Atom beautify readme but it does not appear in the list of available beautifiers for HTML in the settings.
Any idea to point me toward the right direction and have my double bracket notation correctly indented?
there’s a package called ‘file-types’, which works wonderfully for changing default syntaxes. file-types link
another solution
Select the code and head to Edit > Lines > Auto Indent.
To speed this up, created a custom keyboard shortcut, enabling me to use Ctrl + Cmd + ] at any point. (On Windows, I would opt for Ctrl + } — which is Ctrl + Shift + ] — as Ctrl + Alt + ] is already taken.)

Atom Hydrogen: How is "run cell" used?

How is the "run cell" syntax in Hydrogen for Atom used? I placed multiple
# %%
tags throughout my code following the official manual here, but when I press Shift+Enter in between any two of the tags, it still only executes that line, not the entire cell block. I also tried the other syntax formats the manual describes, but none of them execute the whole cell.
A-C-enter hydrogen:run-cell
A-S-enter hydrogen:run-cell-and-move-down
https://github.com/nteract/hydrogen/issues/304

How to prevent zsh prompt from collapsing

I have written my own zsh (actually, I'm using zsh with oh-my-zsh, if it's relevant to the subject) prompt, its code follows:
PROMPT="%{$fg[green]%n%}#%{%m%}:%{$fg[yellow]%~%} %{$fg[red]%#$reset_color%} "
Everything is fine except the only issue: when I use autocompletion (press Tab), prompt collapses to first few symbols.
Here's the screenshot, collapsed prompt is in the left Terminal window, and the normal prompt is in the right window.
http://i.imgur.com/a1iWHdA.png
I'm not sure whether I got it exactly as you wanted but try this for a start:
local gr=${1:-'green'}
local bl=${2:-'blue'}
local re=${3:-'red'}
local wh=${4:-'white'}
local cy=${5:-'cyan'}
local ye=${6:-'yellow'}
export PROMPT="%F{$gr}%n%f#%m:%F{$ye}%~%f %F{$re}%#%f "
I'm not sure exactly what you did wrong, but it appears that those curly braces were messing with your prompt. By approach to prompt customization uses %F{$ID} where ID is one of the identifiers I defined for starting colouring and %f for stopping colouring. You can make text bold using %B (remove bold using %b).

Resources