Jupyter book - Change Image Size in Jupyter notebook - jupyter-notebook

I am creating a jupyterbook using
jb build my_report --builder=pdflatex
In my jupyter book, my output is written in the notebooks.ipynb.
Within this report I have
from IPython.display import Image
Image(filename='Images/my_image.png',width=600, height=400)
Here the width and height have no impact when building the book. How do I change the cell metadata to change the size?
Currently the cell metadata is as follows:
{
"tags": [
"remove-input"
]
}

I believe the only (working) way at the moment is to resize the source image.

Related

GTK 3.0 Evolution css theme gtk.css

I have looked all over the place and can't seem to find the CSS ID's for Evolution..
I want to be able to customize the colors in Evolution. I have found some CSS tags that were changing sizes but nothing to do with unread email.
My primary goal is to have unread email have a different font color... Any help is greatly appreciated!!
create file called gtk.css in directory ~/.config/gtk-3.0
Edit gtk.css with the following:
MessageList,* {
-MessageList-new-mail-bg-color: SteelBlue;
}
save changes made to gtk.css file and restart evolution mail client
If you prefer to change the font and not the background, you can use the foreground attribute to change just the text color.
Note the change from bg to fg below:
MessageList,* {
-MessageList-new-mail-fg-color: SteelBlue;
}
This is currently working for me on Evolution 3.36.5-0ubuntu1
As stated above, file location:
~/.config/gtk-3.0/gtk.css
If you clone the source code from github, the code is located in:
evolution/src/mail/message-list.c

Hiding code in jupiter in R

I would like to try to produce reports (pdf and probably html) in jupyter using R kernel. However, I would like to hide code in two ways, depending on audience:
all code cells
some code cells
When I have looked for this I found answers for python kernel. Is there a way to this in R (no python code)?
So I have started to combine python's answer:
How to hide code from cells in ipython notebook visualized with nbviewer?
with
How to render LaTeX / HTML in Jupyter (R)?
and it works.
If one puts the following code in a cell, will get a button for hiding code. From here I think I know where to start.
library(IRdisplay)
display_html(
'<script>
code_show=true;
function code_toggle() {
if (code_show){
$(\'div.input\').hide();
} else {
$(\'div.input\').show();
}
code_show = !code_show
}
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()">
<input type="submit" value="Click here to toggle on/off the raw code.">
</form>'
)
As you're talking about making HTML and PDF reports, you can do this by using a custom template with nbconvert, and using that to hide cells. This will work for any notebook, independent of the kernel you use.
Docs on nbconvert templates: http://nbconvert.readthedocs.org/en/latest/customizing.html
Examples including hiding code cells based on cell metadata: https://github.com/jupyter/ngcm-tutorial/tree/master/Day-2/nbconvert_templates
Add some CSS code in the first cell, change that cell to 'Raw NBConvert' and the format specified in the CSS will be applied to the HTML generated:
To hide input blocks:
<style type="text/css">
.input_hidden{
display: none
}
</style>
Other style definition can also go there.
Then run ipython nbconvert the_name_of_the_stuff.ipynb --to slides to generate the HTML (without the input blocks).

Standard scrollbars in Sublime Text 3

Is there any way to have standard Windows/system native scrollbars in Sublime Text 3 or do I have to get myself used to these tiny little ones?
For me, a person with medium eyes problems, current scrollbars are just to tiny and I'm having problems, from time to time, with catching them. I heard, that eveything is configurable in Sublime Text 3, so I'd like to ask, if scrollbars can be changed as well?
As Miles Zhang suggests,
you can try some third part themes
... you can find more themes from Package Control
And you can change the size of the scroll-bars for most of them as well. Create a file in your packages directory with the same name as your theme.
I like to use Cyanide theme, so I would create a new file in (packages dir)/User/Cyanide.sublime-theme. then set the attributes you want. In this case, you want to set scroll_bar_control : content_margin.
My Cyanide.sublime-theme file looks like this:
[
{
"class": "scroll_bar_control",
"attributes": ["horizontal"],
"content_margin": [3, 4] //makes horiz scrollbar taller
},
{
"class": "scroll_bar_control",
"content_margin": [1, 3] //makes vert scrollbar taller
},
{
"class": "tab_label",
"parents": [{"class": "tab_control", "attributes": ["selected"]}],
//"fg": [30,30,30],
"fg": [255,131,0] //change highlighted tab color
}
]
Most of my info was learned here
I don't think you can change the scrollbars to system native style, but you can try some third part themes that with bright color scheme.
For example: Numix Theme. You can find more themes from Package Control.

Centering Headings in IPython notebook

I would like to center heading cells in IPython notebook.
I know it is possible to create centered headlines by writing HTML, but then I can't get a reference to the cell when using table of contents (nbtoc ext.)
Is there a way to write HTML headings with reference or heading cells with centered text?
Thanks!
If you want to center a heading without custom css, you can surround your text with center tags.
For example, if you wanted to make a centered h1 title cell:
# <center>Title</center>
Another option is to use:
<h3 align="center">This is a centered header</h3>
as shown here.
This could be done using a custom css; see this question for more details on setting up the profile and the appropriate files.
An example custom css can be found in Barba's 12 Steps to Navier Stokes course although the actual file may contain more detail than you need. The actual ipython notebooks there directly load the css, rather than using a profile method, which also works. To center the headings, just modify the css file to
h1 {
...
text-align: center;
}
as usual.

Adding custom styled paragraphs in markdown cells

I want to add more formatting elements than provided by the Markdown synthax in an IPython Notebook.
For example, I want to add a "Warning Box" or a "Memo Box" that are basically paragraph with different styles (for example different background color, border, an icon, etc...).
I guess I can add HTML code in the cell, for example a <div> with an inline style. But what is the "proper" way to do that, I mean the one that ipython developer promote?
Examples appreciated.
NB: I'm using the current 1.0dev version from git master.
Answering to my own question...
Other solutions
Jim proposed to add some custom CSS style in a markdown cell of each notebook. This solution works, but is not convenient since you need to embed the style on each notebook. In my case I want a global style and I don't want to modify all the notebooks after every the style modification.
A natural solution would be using a custom file (custom.css) containing the style. However after trying these instructions
the style is not applied to the notebook (it can be downloaded from the server though).
Best solution (so far)
I found a solution looking at this impressive book written as a collection of IPython notebooks. The author adds at the end of each notebook the following code cell:
from IPython.core.display import HTML
def css_styling():
styles = open("./styles/custom.css", "r").read()
return HTML(styles)
css_styling()
Putting a file custom.css in your notebook folder (in the styles subfolder), the style will be loaded after the first cell execution. Moreover the style will be magically loaded every time the notebook is opened, without the need to execute the cell again!
This magic trick works because the style is saved in the ouput cell the first time we execute it, and although being invisible, will be saved like any other output. So when we load the notebook, and conseguentely the output cells, the style will be applied.
Sample CSS
To complete the answer I post a CSS style I used to create a "Warning box":
<style>
div.warn {
background-color: #fcf2f2;
border-color: #dFb5b4;
border-left: 5px solid #dfb5b4;
padding: 0.5em;
}
</style>
Save this style and load it using the code cell shown before. Now, to insert a warning box in your notebook use this syntax:
<div class=warn>
**Warning:** remember to do bookeping
</div>
That will be rendered like this:
For more general notebook styling you can take inspiration from the custom.css
of the book mentioned above.
A simple way to add warning, note, success (etc...) boxes (also called admonition or alert boxes) is simply using the bootstrap classes already included with the notebook. The only caveat is that links and other styles (e.g. bold) must be specified in HTML inside the box.
Example
A markdown cell containing this code:
# Upload data files
<p class="lead">This Jupyter notebook
shows how to upload data files to be converted
to [Photon-HDF5](http://photon-hdf5.org) format. </p>
<i>Please send feedback and report any problems to the
[Photon-HDF5 google group](https://groups.google.com/forum/#!forum/photon-hdf5).</i>
<br>
<div class="alert alert-warning">
<b>NOTE</b> Uploading data files is only necessary when running the notebook online.
</div>
will result in this output:
You can change alert-warning with alert-success, alert-info or alert-danger to get different colors for the box.
Update: This technique no longer works in IPython 4.0 / Jupyter since the way the notebook is rendered has changed.
I believe the best way to do such styling is to create a markdown entry at the top of your document and to collect your styles there. Since a markdown cell can contain any valid HTML code, it could contain (for instance)
<style>
.warning { color: red; }
</style>
See Matt Davis' PyCon 2013 talk, about 22 minutes in during the Q&A for an example of this in use.
These custom css styles are already added in ipython version 2 and higher.
<div class="alert">
As of IPython 2.0, the user interface has changed significantly
</div>
<div class="alert alert-success">
Enter edit mode by pressing `Enter`
</div>
<div class="alert alert-error">
Don't try to type into a cell in command mode
</div>
Just paste this in the cell and change it to markdown type.
Check this for the examples and ipython in depth for the cutting edge features of ipython.
Another mean consists to simply create a style chain and open it with iPython HTML object in a code cell:
from IPython.display import HTML
style = "<style>div.warn { background-color: #fcf2f2;border-color: #dFb5b4; border-left: 5px solid #dfb5b4; padding: 0.5em;}</style>"
HTML(style)
Then use it in a markdown cell:
<div class="warn">Warning!</div>

Resources