Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color printing should be an option (or should be the default?) #840

Closed
aroberge opened this issue Dec 11, 2015 · 41 comments · Fixed by #3212
Closed

Color printing should be an option (or should be the default?) #840

aroberge opened this issue Dec 11, 2015 · 41 comments · Fixed by #3212

Comments

@aroberge
Copy link

Buried in the css files are various @media print configurations which prevent color printing. They can be edited by hand if one has access to the installation directories, but there should be a way to have color printing be done without this type of editing.

@willingc
Copy link
Member

@aroberge Thanks for the suggestion. Personally, I never noticed that printing defaults to B&W whether from the Print Preview menu option or the browser print menu (at least on Firefox).

@Carreau @ellisonbg Is there a setting that can be easily changed to enable color printing? If so, it would seem reasonable to document here and the user docs.

@ellisonbg
Copy link
Contributor

Hmm, I don't think we set anything that makes it BW. We will have to look
into this.

On Sat, Dec 12, 2015 at 3:54 AM, Carol Willing [email protected]
wrote:

@aroberge https://github.com/aroberge Thanks for the suggestion.
Personally, I never noticed that printing defaults to B&W whether from the
Print Preview menu option or the browser print menu (at least on Firefox).

@Carreau https://github.com/carreau @ellisonbg
https://github.com/ellisonbg Is there a setting that can be easily
changed to enable color printing? If so, it would seem reasonable to
document here and the user docs.


Reply to this email directly or view it on GitHub
#840 (comment).

Brian E. Granger
Associate Professor of Physics and Data Science
Cal Poly State University, San Luis Obispo
@ellisonbg on Twitter and GitHub
[email protected] and [email protected]

@aroberge
Copy link
Author

I've installed Jupyter + IPython using the Anaconda Python distribution. In my system, the relevant css file is (if I am not mistaken):
Anaconda3/pkgs/notebook-4.06-py34_0/Lib/site-packages/notebook/static/style/style.min.css

Edit: from memory, there were two places where I removed code from the css file to print everything in color. The first place was near the @media print declaration; the second was a setting for html tables if I recall correctly.

@Carreau
Copy link
Member

Carreau commented Dec 12, 2015

This is a bootstrap thing that include a print.less with !important.
It's not easy to get rid of, but we can try.

@Carreau Carreau added this to the wishlist milestone Dec 14, 2015
@mjbright
Copy link

mjbright commented Feb 4, 2016

Any progress on this?
Let me bump this one - it's really important to me.

I'm using Jupyter (+bash_kernel) to create some labs (Docker) where I use Jupyter to create the lab and then create a PDF to distribute to the students-*.

Those documents would be much more readable in colour.

Thanks for a great tool !

@Carreau
Copy link
Member

Carreau commented Feb 4, 2016

@mjbright have you tried the conversion to PDF via latex ? (it likely fail because of some ansi escape sequence but that's a bug that should be opened)(opened as jupyter/nbconvert#228)

Are you afraid of a custom IPython build ? Basically set-up a dev environment,
modify <repo root>/notebook/static/components/bootstrap/less, to remove line 13 @import "print.less";, and recompile CSS (python setup.py css)

That should be enough (understand it works for me locally), unfortunately that something that make the build process extremely inconvenient for downstream (like Debian) as then we use a modified version of our dependencies.

@mjbright
Copy link

mjbright commented Feb 4, 2016

Hi Matthias,

I did try briefly PDF via latex (quite a week I don't even remember if it
was under RHEL7, Ubuntu-trusty or Win8 that I tried) but without early
installation success I abandoned - because of soe lab setup constraints.
I'll try again with my Ubuntu (a Vagrant box) ... when I have time (?).

Afraid of a custom IPython build? A little (time wise) but i'll consider
that also.
Mind you why are we talking about IPython?

Thanks for the suggestions,
Mike.

On 4 February 2016 at 07:21, Matthias Bussonnier [email protected]
wrote:

@mjbright https://github.com/mjbright have you tried the conversion to
PDF via latex ? (it likely fail because of some ansi escape sequence but
that's a bug that should be opened)

Are you afraid of a custom IPython build ? Basically set-up a dev
environment,
modify /notebook/static/components/bootstrap/less, to remove
line 13 @import "print.less";, and recompile CSS (python setup.py css)

That should be enough (understand it works for me locally),
unfortunately that something that make the build process extremely
inconvenient for downstream (like Debian) as then we use a modified
version of our dependencies.


Reply to this email directly or view it on GitHub
#840 (comment).

@mjbright
Copy link

mjbright commented Feb 4, 2016

Hi, following a suggestion somewhere on StackOverflow, I think, I modified
that equivalent path on my Ubuntu system.

The following context diff shows what I tried (out of informed ignorance).
Restarting Jupyter didn't improve the situation.

Just in case someone has a quick hack to suggest ...

---

/home/vagrant/anaconda3/pkgs/notebook-4.1.0-py35_0/lib/python3.5/site-packages/notebook/static/style/style.min.
css     2016-02-04 05:37:14.921859360 +0000

---

/home/vagrant/anaconda3/pkgs/notebook-4.1.0-py35_0/lib/python3.5/site-packages/notebook/static/style/style.min.
css.orig        2016-02-04 05:35:56.893856260 +0000

---

**\* 192,198 ****

*:before,

*:after {

background: transparent !important;


!     /\* To allow colour printing: color: #000 !important;*/

box-shadow: none !important;

text-shadow: none !important;

}


--- 192,198 ----

*:before,

*:after {

background: transparent !important;


!     color: #000 !important;

box-shadow: none !important;

text-shadow: none !important;

}


---

**\* 242,252 ****

.dropup > .btn > .caret {

border-top-color: #000 !important;

}

-   /\* To allow colour printing:
  
  .label {
  
    border: 1px solid #000;
  
  }
-   */
  
  .table {
  
    border-collapse: collapse !important;
  
  }

--- 242,250 ----

On 12 December 2015 at 19:45, André Roberge [email protected]
wrote:

I've installed Jupyter + IPython using the Anaconda Python distribution.
In my system, the relevant css file is (if I am not mistaken):

Anaconda3/pkgs/notebook-4.06-py34_0/Lib/site-packages/notebook/static/style/style.min.css


Reply to this email directly or view it on GitHub
#840 (comment).

@Carreau
Copy link
Member

Carreau commented Feb 4, 2016

Mind you why are we talking about IPython?

gah, old habits and it was late at night, I was of course trying to say Jupyter Notebook

Hi, following a suggestion somewhere on StackOverflow, I think, I modified
that equivalent path on my Ubuntu system.

Force reload the page (Ctrl-Shift-R, likely) the browsers can have agressive caching.

@mjbright
Copy link

mjbright commented Feb 4, 2016

La honte (duh!) for Ctrl-Shift-R !
Thanks Matthieu, I have colour printing now !!

On 4 February 2016 at 18:15, Matthias Bussonnier [email protected]
wrote:

Mind you why are we talking about IPython?

gah, old habits and it was late at night, I was of course trying to say Jupyter
Notebook

Hi, following a suggestion somewhere on StackOverflow, I think, I modified
that equivalent path on my Ubuntu system.

Force reload the page (Ctrl-Shift-R, likely) the browsers can have
agressive cahing.


Reply to this email directly or view it on GitHub
#840 (comment).

@willingc
Copy link
Member

willingc commented Feb 4, 2016

That's wonderful! 🌅

Thanks @Carreau 👍

@willingc willingc closed this as completed Feb 4, 2016
@aroberge
Copy link
Author

aroberge commented Feb 4, 2016

I am curious as to why has this just been closed? It still requires custom editing of one file in the distribution if I am not mistaken. If I understand correctly, the Ctrl-Shift-R was just done so that the browser would use the file edited by hand but the underlying problem is still there.

@Carreau Carreau reopened this Feb 4, 2016
@Carreau
Copy link
Member

Carreau commented Feb 4, 2016

I am curious as to why has this just been closed?

This was likely a mistake, it happen when you get notification by mail, and only see the last few messages.

@Carreau
Copy link
Member

Carreau commented Feb 4, 2016

(reopened)

@willingc
Copy link
Member

willingc commented Feb 4, 2016

My apologies for not reading to the top of the message list @aroberge. Thanks @Carreau for reopening.

@AGS-Knight
Copy link

Could someone explain this to me - I, too, am interested in printing in color. I am able to generate .html files of my notebook that look correct, but when I print them or save as .pdf when printing, only the inline figures show color. This is the case whether or not I comment the lines that @Carreau suggested, above.

@takluyver
Copy link
Member

@AGS-Knight if you're modifying the LESS files, you'll need to recompile them to CSS, reinstall the notebook, and convince your browser to clear the cache before you'll see any effect.

It should absolutely be possible to print in colour without going through this.

@minrk minrk modified the milestones: 5.0, wishlist Feb 9, 2016
@minrk
Copy link
Member

minrk commented Feb 9, 2016

Yeah, I'm pretty sure any BW print settings are not intended. A LESS PR fixing this would be welcome.

@Carreau
Copy link
Member

Carreau commented Feb 9, 2016

A LESS PR fixing this would be welcome.

It was like that before, but it requires a modified version of bootstrap. We were removing code.less and print.less, though it required too much maintenance at each update, and completely screw up packaging by thongs like debian.

@lia-simeone
Copy link

Is the intent still to fix this issue? Any estimate on when it might be fixed?

Printing notebooks to PDF is one of my favorite features, but black and white really reduces the usefulness.

@marrabld
Copy link

marrabld commented Aug 2, 2016

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.

@vascotenner
Copy link

@marrabld Is it possible to do this with javascript, then it could be embedded in the saved html document.

@marrabld
Copy link

marrabld commented Aug 3, 2016

@vascotenner I guess so, but my Javascript isn't good enough to figure out how to do it.

[edit]
You could try adding
@media print { *, *:before, *:after { background: transparent !important; box-shadow: none !important; text-shadow: none !important; }

to your ~/.jupyter/custom/custom.css file.
[\edit]

@Eothred
Copy link

Eothred commented Sep 27, 2016

+1 from me

@takluyver
Copy link
Member

@minrk @Carreau are we any closer to being able to fix this in our LESS files?

@Carreau
Copy link
Member

Carreau commented Jan 31, 2017

@minrk @Carreau are we any closer to being able to fix this in our LESS files?

AFAICT, no, not without updating to new bootstrap.

@takluyver takluyver modified the milestones: Backlog, 5.0 Jan 31, 2017
@takluyver
Copy link
Member

Bumped from 5.0 to backlog so we can try to get to a release.

@lucasdurand
Copy link

Any idea how this is coming? I wasted a few hours toiling on this ... hoping others won't need to

@raoulraf
Copy link

same story here... trying to fix it with workarounds but I'm wasting too much time on it - without success :(

@itacdonev
Copy link

  1. Saving as slides using
    jupyter nbconvert --to slides NOTEBOOK_NAME.ipynb
  2. opening in Text Editor (Mac)
  3. open print dialog and uncheck the option to "rewrap contents to fit the page". If you leave this option the font size is large.
  4. adjust any other printing options
  5. print

It prints in color and structure is as in the notebook itself (code chunks highlighted, etc.)

@itacdonev
Copy link

It should be --to html in the above comment

@MathRanger6
Copy link

Still working at this myself...

@LukeLR
Copy link

LukeLR commented Nov 6, 2017

Any progress so far? I'm using Jupyter Notebook on a regular basis, and my work requires me to print my notebooks. Printing without color looks ugly, since the code is harder to read and less understandable. Printing via LaTeX/PDF works in color, but lines longer than the page width are cut off. So both options don't work for me.

Jupyter Notebook is a great tool and I love everything about it - except the printing / PDF export 😄 Besides that, it works very flawlessly and I love the openness of the code and the file format, and the reliability of the software. Great work! But, please, add an option for colored printing.

For those who don't want to modify their sources because of installing via package manager or temporary fixes, but still want colored printing: Using Firefox dev console (Ctrl+Shift+C) when viewing the print preview (File > Print preview) or a rendered HTML of the desired file, switch to the "Style editor" tab and select the largest style sheet (for me it's Inline Style Sheet #1 with 2199 rules). Search for "print" by Ctrl+F and comment out the line color: #000 !important; (line 196 for me) by wrapping in /* */, like that:

/*color: #000 !important;*/

Then print with Ctrl+P, maybe reload the page if it isn't updated automatically. If it doesn't work, you might try commenting out the whole print { ... } section.

@nickfarrow
Copy link

I would love this to be fixed too. Doesn't seem like it would be difficult to change either.

@phablulo
Copy link

+1

@takluyver
Copy link
Member

I've had a go at it in #3212 , though it's a rather ugly solution.

@PeterXiaoGuo
Copy link

PeterXiaoGuo commented Feb 13, 2018

Hi, for anyone who get lost in the long communication log and want to find the solution for colored pdf output quickly:

Just comment one line code below in a css file called "style.min" in C:\Users***\Anaconda3\Lib\site-packages\notebook\static\style

comment the 195th line:
color: #000 !important;

it's in a stuff called @media print {.....}
control + Q for notepad

Good luck~

@takluyver
Copy link
Member

Or upgrade to notebook 5.4 - we've removed the line for you.

@MathRanger6
Copy link

I'm still having this problem with both 5.4 and 5.5. I go to file - print preview, and then print. It uses the same bootstrap and the same line of code is in there telling it color 0000. What am I doing wrong?
boot

@takluyver
Copy link
Member

We need to do a new release of nbconvert to pick it up - see jupyter/nbconvert#748

@farhadsalemi1
Copy link

Thank you Matthias Bussonnier.
The (Ctrl-Shift-R) worked for me and I can print Jupyter documents in color format.
#840 (comment)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.