Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jupyter notebook color different parentheses by different colors

I can see the matching parenthesis hightlights green when I hover around them, but is it possible to add additional color syntax to them so that the matching parenthesis have different colors.

  • Is there any nbextension for that?
  • Is there a way to add some code to custom.js that will make it happen.

Example code:

# create new features
df = (df
 .withColumn(("rooms_per_hh", F.round(col('total_rooms') / col('households'), 2)))
 .withColumn(("pop_per_hh", F.round(col('pop') / col('households'), 2)))
 .withColumn(("bedrooms_per_rooms", F.round(col('total_bedrooms') / col('total_rooms'), 2)))
     )

I like to see different colors for different parentheses here.

Related links:
- Changing jupyter's matching parenthesis color
- Replace / remove highlighting in Jupyter Notebook with custom theme

Required output: enter image description here

like image 683
BhishanPoudel Avatar asked Sep 29 '19 15:09

BhishanPoudel


People also ask

What does purple mean in Jupyter notebook?

Green = a string Grey = a comment Orange = a number or a parameter (or a predefined property name(for instance .length )) Purple = special keyword (like var , if , else , etc) Light-blue = operator ( + , - , * , / , = , < , == , && , etc) Dark-blue = a predefined function name or the function name in a function ...

Does Jupyter notebook have syntax highlighting?

Jupyter notebook displays do not use the syntax highlighting theme in Preferences to display code blocks.

How do you color text 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>.

Why is variable red in Jupyter?

This is because the indentation is screwed up. For consistency the codemirror parser will make a red line if it's not indented 4 spaces (or if it's indented with tabs, depending on codemirror version).


2 Answers

I think you can use jupyter-notebook-themes Google Chrome and add .cm-s-ipython .CodeMirror-matchingbracket { color: black !important;} or some thing else to change coloring of inner parenthesis.

Then you can add it to your Chrome as a custom extension.

like image 155
AliReza Avatar answered Oct 21 '22 19:10

AliReza


You can run the jupyter in VSCode, using the Bracket Pair Colorizer ( or Rainbow Brackets ) And will give you something like this : strong text

You import the .ipynb file, have the "Run Cell" command + can import the Color extensions.... It's not perfect ( not really using "Jupyter" ) but it works...

like image 23
spYder Avatar answered Oct 21 '22 18:10

spYder