Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing iPython Notebook preview in color?

I'm using Windows Python 2.7.6 and iPython 2.0.0. When I do a print preview on a notebook, I get a gorgeous color output with syntax highlighting, etc.

As soon as I either do a print preview, or print it, it becomes gray scale and loses the syntax highlighting. How can I print keeping the color and highlighting?

like image 595
Charles Plager Avatar asked Apr 09 '14 17:04

Charles Plager


People also ask

How do I change the color of my output in Jupyter notebook?

In the Jupiter notebook, we can use a color marker to print the output in different colors There are three ways that we can use a color marker. let's see how to print a yellow color in a notebook. Some of the colors are : yellow = '\033[93m'

How do I print from IPython notebook?

In JupyterLab select Help -> Launch classic notebook, then from your browser menu (e.g. 3 dot menu) choose print and print to pdf.

How do you make a color in a Jupyter notebook?

We can change the colour of the text using the html <font> tag. We can use colour names or hexadecimal colour code: Example: <font color=green>green text</font>, <font color=blue>*blue italised text*</font> and <font color=#FF0000>**red bold text**</font>.


2 Answers

One workaround is, save the notebook as html. The rendered file will have the css embedded. Open the HTML in a text editor and do a search for

@media print

and delete the offending

!important;color:#000

save, open the file in a browser and print.

It's not ideal but you don't have to go digging around changing the CSS and recompiling in your site-packages.

Just in case someone is looking for an easier workaround.

like image 94
Caustic Avatar answered Oct 26 '22 22:10

Caustic


I know this is an old question, but for people who may be searching for this answer, here it is:

IPython on windows would be installed by default at C:\Python27\site-packages\IPython. If you installed Python somewhere else, the beginning of the path will change. For linux users, it would be installed under /usr/lib/python2.7/site-packages/IPython.

Once in the IPython folder, go to html\static\style. You should then see a file called style.min.css.

Making sure you have administrator priviledges, open style.min.css with your favorite text editor. If you don't know what I mean by text editor, just double click. In style.min.css find the line that starts with @media print. On that line, near the beginning, you will see color: #000 !important; Delete only that part of the line and save the file.

I have IPython 2.3.0, so it may be different in you version, but this is what the line I am talking about looks like before and after the change (only part of line is shown):

@media print{*{text-shadow:none !important;color:#000 !important;background:tran...

@media print{*{text-shadow:none !important;background:transparent !important;box...
like image 37
regdoug Avatar answered Oct 26 '22 22:10

regdoug