Hello, @Cyrille! I have a quite complicated solution that should work on Windows or any OS. I cannot take credit for it; I just adapted a solution from this site (retrieved on May 2nd, 2020), which in turn comes from this other page (retrieved on May 2nd, 2020). Since I don't know Javascript, it was a really painful process to understand this code and how to use it. Unfortunately, I wasn't able to improve the code (I just adapted it), so maybe you need a more clever person than me.
However, here is what I've got. Write the following Python script in a file, which, for the sake of the discussion, I will call "invisible_cells.py":
from IPython.core.display import display, HTML
def toggle_cell():
tag = HTML("""
<script>
code_show=true;
function toggle_cell() {
if (code_show){
$('div.cell.code_cell.rendered.selected div.input').hide();
} else {
$('div.cell.code_cell.rendered.selected div.input').show();
}
code_show = !code_show;
}
$( document ).ready(toggle_cell);
</script>
<a href="javascript:toggle_cell()">Toggle this cell</a>""")
display(tag)
def hide_cell():
tag = HTML("""
<script>
function hide_cell() {
$('div.cell.code_cell.rendered.selected div.input').hide();
}
$(document).ready(hide_cell);
</script>
<a href="javascript:hide_cell()">Hide permanently</a>""")
display(tag)
This script defined two functions: toggle_cell()
will allow you to hide/unhide the contents of a cell, while hide_cell
will make it permanently invisible.
You can use these functions as follows. Write the following in a cell:
import invisible_cells as ic
ic.hide_cell()
When you execute that cell, it will show you a link "Hide permanently"; when pressed, it will hide the cell and the link. From that point on, you should use the ic.hide_cell()
command at the beginning of every cell you want to hide.
Since permanently hiding a cell is dangerous, I also included the ic.toggle_cell()
command. If you use it at the beginning of a cell, when executed, it will show you a link "Toggle this cell", which will hide the cell, but also will show it again, just in case you need to make modifications.
This is the downside of the code: You must press the links in order to hide the cells. If you share this notebook with somebody, or even if you close and then re-open the notebook, the cells will be visible until you press the links to hide them. This is because the Javascript code uses the selected div
command, which requires the cell to be activated, which in turn requires the link to be pressed. However, if you find somebody who can program Javascript, you can ask them to change the code so that the code recognizes the cell from which is executed, and automatically hides it.
I hope this helps! I am so sorry i didn't find a better solution.
off-topic: in general sage is not "windows friendly", if you can I will recommend to use some linux distribution. I have dual boot with win10 and kubuntu and almost all the time Im in kubuntu. Indeed I have a lot more of useful tools in kubuntu, at least for what I generally do in a computer.
I have not enough room and to jump from one system to the other is boring.
Installing
hide_code
is explained here https://ask.sagemath.org/question/502... why doesn't it work for windows?About "the procedure to follow": can you include a link?
About "comes without
view
"; can you explain what you mean?Sorry I am stupid . I finally have understud that to install an additionnal package it was necessary to use sage shell. From notebook I was unable to do it.