Hide all code when exporting notebook in Jupyter Lab to PDF - jupyter-notebook

When I export a notebook to PDF in jupyter lab i cannot hide the code cells in the output.
(Like 'View > Collapse All Code')
Is there a built in functionality to hide code in the output PDF?
For example by using the cell Metadata?

This worked for me:
jupyter nbconvert path/to/your/ipynb --to=pdf --TemplateExporter.exclude_input=True

Related

Render all markdown cells in a Jupyter notebook at once

Is there a convenient way to render all markdown cells in a Jupyter notebook at once without running the code cells?
I find it quite annoying that while moving through my notebook and doing some little corrections the markdown cells "loose" their formatting. Is there an extension or a command with which I can "run" (i.e. render) all and only the markdown cells? If not, is there a way to at least update the table of content from the markdown cells. My table of content is realized via nbextensions.
You could use JupyterLab which provides a Render all Markdown cells action if you are not limited to plain Jupyter notebooks. Doing this programmatically within the notebook seems to be not trivial to do as we can derive from this GitHub issue. We might be able to implement this ourselves, but I am not aware of any resources that provide something similar.

How to delete all markdown cells in jupyter notebook?

I want to delete all markdown cells from a jupyter notebook. The only possible way to do this, as I see, to download it as .py file, then copy and paste in a new jupyter notebook. Is there a way to do this without breaking cell structure?
nbformat can be used to do that:
import nbformat as nbf
ntbk = nbf.read("old_notebook.ipynb", nbf.NO_CONVERT)
new_ntbk = ntbk
new_ntbk.cells = [cell for cell in ntbk.cells if cell.cell_type != "markdown"]
nbf.write(new_ntbk, "no_markdown_notebook.ipynb", version=nbf.NO_CONVERT)
For less 'broad-strokes' notebook cleaning, Chris Holdgraf's nbclean is my go-to tool for this type of thing.
(This answer was adapted from code to do the opposite process: Delete all code cells except markdown text).

Display Images from file in R Jupyter notebook

I have an image on disk and want to display it in a markdown cell in an R Jupyter Notebook. How can I go about this?
I know with Python this as simple as importing the Image class from display.
IRdisplay has functions to rich display "stuff", which includes images:
library("IRdisplay")
display_png(file="plot.png)
In a markdown cell as you usually would in a Jupyter Python notebook:
<img src="../relative/path/to/img.png">
or
![image](../relative/path/to/img.png)
Here is code for the Jupyter R Kernel Notebook User to select choose an image file (.PNG) from the file system, strip off the full pathname, and then insert the image into the cell below this code.
image_chosen = choose.files(
default = "",
caption = "Select The Image File (in PNG format) to Insert",
multi = TRUE, filters = Filters,
index = nrow(Filters)
)
chosen_image_name = basename(image_chosen)
#chosen_image_name # uncomment this line to show the location of the image.
IRdisplay::display_png(file = chosen_image_name) # This line inserts the image.
Then use the standard Jupyter Notebook extension "Hide Input" to hide this codecell, and the "Freeze" NBextension to freeze the codecell so the image stays frozen and the notebook does not try to select and insert a new image everytime the notebook code runs.

How to convert Jupyter/IPython notebooks to LaTex?

How can I export Jupyter notebooks to LaTeX? I can convert to PDF through LaTeX using the inbuilt menus but I'm unsure how to step in at the intermediate step and extract the actual LaTeX file.
You have to do this from the command line rather than the web interface with the following command:
jupyter nbconvert /path/to/mynotebook.ipynb --to latex
Anaconda Navigator provides JupyterLab. Use this to open jupyter notebook.
Under File menu you can find an item "Export Notebook As...".
This provides format such as Asciidoc, HTML, latex, pdf, Markdown, etc.
You can choose your desired format.

Inserting a Link to a Webpage in an IPython Notebook

How is this done? I'd like to have the link be in a markdown cell.
For visual learners:
[blue_text](url_here)
In case it is not a markdown cell, that is with what I went:
from IPython.core.display import display, HTML
display(HTML("""text"""))
Just another tip, using magic expression.
%%html
Showing Text
Improved. Thanks to the comment of calocedrus.
Here is the code I use in my python notebook when I want to insert a link to a webpage inside a markdown cell (in a python notebook).
[Clickable_visible_hyperlink](Hidden_landing_URL)
--note Here is the clickable hyperlink, you can change the value
This might help too, if you're looking to display a link programmatically.
from IPython.display import display, Markdown
display(Markdown("[google](https://www.google.com)"))
I also tried
display(HTML("""<a href="https://www.google.com>google</a>"""))
But somehow I was getting the object printed out, instead of the rendered version.
For programming in R, do the following when using Jupyter Notebook or Jupyter Lab - (using the R kernel). These steps will display a web link and an image in a Notebook markdown cell. The following shows a real-life example of some study notes using Jupyter Lab and R.
First open a markdown cell in Jupyter - can be a new markdown cell or an existing markdown cell. Then copy and paste the actual web address into a markdown cell. This will provide an active link to that website from the Notebook.
Step 2, from that website, copy the image that you want to view in the Notebook. This image should be in a standard image format (.png, .jpg, etc ). Paste this image into the same folder on the computer where the Jupyter notebook file is located. Note: if the image is later deemed too large or small, then resize using any graphics software available - and then save the changed image into this same folder. Note: it is important to know the name of this image file.
Next, paste the name of the image file between the quotation marks in the following code: . If this file in not within your existing jupyter notebook working directory, then a path to the image file will need to be placed inside the quotation marks.
Step 3, also included is an example of the line of code (also used in Notebook markdown cell) to create colored text in markdown cells. In this line of code, the double ## character results in the second largest font being used in Jupyter. Smaller text using more of these characters - with #### being the smallest. One # results in the largest font output.
Last, be sure to close and run the markdown cell to view the output. The code for the markdown cell follows, and further below shows the output from the Notebook.
Code in Markdown cell:
"https://www.tensorflow.org/images/colab_logo_32px.png" # link to website
<img src="tidyflow.png" /> # The image file (This path is the same folder as Notebook file)
## <font color = cyan> Some Colored Text in Notebook Markdown Cell </font> # colored text
Output:

Resources