close

How to wrap code/text in Jupyter notebooks

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to wrap code/text in Jupyter notebooks in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to wrap code/text in Jupyter notebooks?

  1. How to wrap code/text in Jupyter notebooks?

    Find your configuration directory via jupyter --config-dir (mine is ~/.jupyter). Then edit or create nbconfig/notebook.json to add the following:

  2. wrap code/text in Jupyter notebooks

    Find your configuration directory via jupyter --config-dir (mine is ~/.jupyter). Then edit or create nbconfig/notebook.json to add the following:

Method 1

Find your configuration directory via jupyter --config-dir (mine is ~/.jupyter). Then edit or create nbconfig/notebook.json to add the following:

{
  "MarkdownCell": {
    "cm_config": {
      "lineWrapping": true
    }
  },
  "CodeCell": {
    "cm_config": {
      "lineWrapping": true
    }
  }
}

(If you have something else in it, ensure you have valid JSON with no trailing commas after }s.)

Restart Jupyter and reload your notebook.

Method 2

In addition to Dan’s answer, you can apply line wrapping for all cells (code or markdown) by specifying the top object as Cell. Adding the code below to your ~/.jupyter/nbconfig/notebook.json

{
  "Cell": {
    "cm_config": {
      "lineWrapping": true
    }
  }
}

Ex: This is my cell config

{
  "Cell": {
    "cm_config": {
      "lineNumbers": false,
      "lineWrapping": true
    }
  }
}

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read