{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "# Workshop \"Teaching Sciences and Engineering with Jupyter Notebooks\" 2022\n", "C. Hardebolle, [CC-BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)\n", "\n", "
\n", " How to use this notebook?
\n", " This notebook is made of text cells and code cells. The code cells have to be executed to see the result of the program.
To execute a cell, simply select it and click on the \"play\" button () in the tool bar just above the notebook, or type shift + enter.
It is important to execute the code cells in their order of appearance in the notebook.\n", "
\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Getting started: narrative and code\n", "\n", "A notebook is made of text cells (\"Markdown\") and code cells.\n", "\n", "## Text cells\n", "\n", "The text you are reading is contained in a text cell, which can be edited by *double clicking* on it.\n", "\n", "You can **format the text** in a notebook using the Markdown syntax. For instance, you can put a sentence in bold by adding double stars (\\*\\*) before and after, **like this.** \n", "The double stars are actually not visible, what you see is the result of the formatting once the text cell has been **rendered**. \n", "To render a text cell, simply select it and click on the \"play\" button () in the tool bar just above the notebook, or type shift + enter.\n", "\n", "Here is an [amazing cheat sheet about the Markdown syntax in Jupyter notebooks](https://medium.com/analytics-vidhya/the-ultimate-markdown-guide-for-jupyter-notebook-d5e5abf728fd) and you can also find the [full reference of the Mardown syntax on John Gruber's website](https://daringfireball.net/projects/markdown/syntax).\n", "\n", "To **add a text cell** to a notebook, click on the + icon in the toolbar at the top, then change the type of the cell to \"Markdown\" using the dropdown menu in the same toolbar.\n", "\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Code cells\n", "\n", "Code cells make it possible to **embed a program** or pieces of program into a notebook, to execute them and **see the results** of its execution right away directly in the notebook.\n", "\n", "The code cell below contains a line of Python code that displays the text \"Hello!\". \n", "To **execute this cell**, simply select it and click on the \"play\" button () in the tool bar just above the notebook, or type shift + enter.
\n", "You should then see the text \"Hello!\" appear just below the code cell." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"Hello!\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You might have noticed that a *number between square brackets* has appeared at the left of the code cell after its execution. \n", "This number indicates the **order in which the code cell has been executed**, with respect to the other code cells or to previous executions of the same code cell.\n", "\n", "The order in which different pieces of code are executed affects the execution results, which is why these numbers are important information to consider.\n", "\n", "
" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## Useful text formatting tools\n", "\n", "Below, we discuss some additional useful tools to format your narrative in notebooks.\n", "\n", "
\n", "\n", "### Spacing / structuring text\n", "\n", "You can space out your text in your notebooks using blank lines. \n", "Unfortunately Markdown has no syntax for blank lines therefore you have to use the HTML syntax `
` each time you want to introduce one.\n", "\n", "To separate paragraphs you can also use horizontal lines, which are easily generated in Markdown with the syntax `---` (triple minus). \n", "The HMTL equivalent is `
`.\n", "\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Hyperlinks\n", "\n", "To create any type of link in Markdown, the syntax is the following: `[text that will appear](URL)` \n", "If you wish to create a link to a local file in the current folder, for instance another notebook, simply replace the URL with the path of the file, relative to the notebook in which the link is: `[text that will appear](subfolder/file.extension)`\n", "\n", "
" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "### Highlighting important information\n", "\n", "Text cells also support more elaborate [HTML](https://html.com/) and [CSS](https://html.com/css/) formatting, for instance to highlight exercises and solution.\n", "\n", "Feel free to reuse the examples below (simply edit the text cell and copy-paste the content)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", " Activity
\n", "\n", "Add a line to the plot that draws a door to the house. \n", "Then create a slider that will let the user choose the width of the door. \n", " \n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "\n", "**Solution** - You check your answer with the solution by clicking on the \"...\" below.\n", " \n", "
" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "
\n", "\n", "### Math equations\n", "\n", "You can use LaTeX to write mathematical equations in your Markdown cells, both inline like this: $\\lvert\\vec{T}\\rvert$ or in blocks like this:\n", "\n", "$$\n", "\\begin{align}\n", "\\lvert\\vec{T}\\rvert = \\frac{\\frac{1}{2}.m.g}{sin(\\alpha)}\n", "\\end{align}\n", "$$\n", "\n", "Of course you need to be familiar with the LaTeX syntax and symbols. \n", "You can find a quick intro and overview in the [LaTeX chapter](https://personal.math.ubc.ca/~pwalls/math-python/jupyter/latex/) of the online [\"Mathematical Python\"](https://personal.math.ubc.ca/~pwalls/math-python/) textbook (made with notebooks!).\n", "\n", "Note that notebooks support only a subset of the LaTeX mathematical syntax, more specifically it relies on the MathJax subset of LaTeX, more information in the [official documentation of MathJax](https://docs.mathjax.org/en/latest/input/tex/)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "# References\n", "\n", "The full documentation of JupyterLab: \n", "https://jupyterlab.readthedocs.io/en/1.2.x/ \n", "\n", "A useful cheat sheet on the Mardown syntax: \n", "https://medium.com/analytics-vidhya/the-ultimate-markdown-guide-for-jupyter-notebook-d5e5abf728fd\n", "\n", "The full reference for the Markdown syntax in Jupyter notebooks: \n", "https://daringfireball.net/projects/markdown/syntax\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 4 }