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?
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'
In JupyterLab select Help -> Launch classic notebook, then from your browser menu (e.g. 3 dot menu) choose print and print to pdf.
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>.
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.
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...
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