<jupyter_start><jupyter_text>Publication Ready Jupyter Notebooks> From notebooks to documents.- toc: true - badges: true- comments: true- categories: [jupyter]- image: images/jupyter.png Documenting your work is an integral part of your development but if you are someone like me and you have to share your work with different set of technical and non-technical audience, you probably go an extra mile to create separate versions of the same results, one with code for your peers, and one for the business stakeholders who may find the code scary or distracting to say the least. [The Jupyter Notebook](https://jupyter.org/) makes my life so much easier for the data analysis related work. Although jupyter notebook supports a variety of programming languages like [Julia](https://julialang.org/), [Python](python.org) and [R](https://www.r-project.org/) for live code and visualisations, alongwith [Markdown](https://en.wikipedia.org/wiki/Markdown), [HTML](https://en.wikipedia.org/wiki/HTML) and others for narrative text, in this post, we will see an example with python code.  Installing Required PackagesAssuming you already have jupyter and python installed on your systems, you need to install the following packages additionally: [nbconvert](https://github.com/jupyter/nbconvert)The nbconvert tools utilises [Jinja](http://jinja.pocoo.org/) templates to convert your jupyter notebooks to various document formats such as HTML, LaTeX, PDF, Reveal JS, Markdown, ReStructured Text (rst) and executable script.You can install nbconvert using either of the commands depending on your python package manager:<jupyter_code>! pip install nbconvert
! conda install -c anaconda nbconvert<jupyter_output><empty_output><jupyter_text>To convert the notebook to the desired output format use the following command structure:<jupyter_code>$ jupyter nbconvert --to <output format> <input notebook><jupyter_output><empty_output><jupyter_text>[Hide_Code](https://github.com/kirbs-/hide_code)Hide_Code is an extension for your jupyter notebook, which allows you to selectively hide code, prompts and outputs in the jupyter notebook. It also enables these notebooks to be exported to HTML, LaTeX and PDF. Once hide_code is installed on your system, you can enable it by clicking View -> Cell Toolbar -> Hide Code on your jupyter notebook menu.![hide code demo](my_icons/hide_code.gif)You can install hide_code using following commands:<jupyter_code>!pip install hide_code
!jupyter nbextension install --py hide_code
!jupyter nbextension enable --py hide_code
!jupyter serverextension enable --py hide_code<jupyter_output><empty_output><jupyter_text>You can export your notebooks to desired format using the following commands:To HTML<jupyter_code>!jupyter nbconvert --to hide_code_html notebook_to_convert.ipynb<jupyter_output><empty_output><jupyter_text>To PDF<jupyter_code>!jupyter nbconvert --to hide_code_pdf notebook_to_convert.ipynb<jupyter_output><empty_output><jupyter_text>To LaTeX<jupyter_code>!jupyter nbconvert --to hide_code_latexpdf notebook_to_convert.ipynb<jupyter_output><empty_output><jupyter_text>[Tabulate](https://bitbucket.org/astanin/python-tabulate/src/master/)Tabulate is a python package used for pretty printing tabular data in python.You can install tabulate using either of the following commands:<jupyter_code>!pip install tabulate
!conda install -c conda-forge tabulate<jupyter_output><empty_output><jupyter_text>Creating the notebookI have created a [demo notebook](https://github.com/alephthoughts/JupyterPublishDemo) on github which you can fork or download or work with your own example.  Writing Narrative TextIn order to write the narrative text in Markdown or HTML, click on "Cell -> Cell Type -> Markdown" on jupyter menu or press "Esc + m" on your keyboard. This [tutorial](https://www.markdowntutorial.com/) gives a good introduction on markdown. Enable Hide_CodeEnable Hide_Code which gives you options to "Hide Prompt", "Hide Code" and "Hide Cell" on the top right corner of each cell in the notebook. Using the following command convert your notebook to LaTeX format.<jupyter_code>!jupyter nbconvert --to hide_code_latex notebook_to_convert.ipynb<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07390684410646388, 'fraction_numerical': 0.0, 'mean_word_length': 6.146010186757215, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 40, 'https://': 10, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '315964', 'license': 'Apache-2.0', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1204, 'n_words': 467, 'path': '_notebooks/2019-06-15-jupyterNotebook.ipynb', 'repo_name': 'alephthoughts/alephthoughts', 'size': '4208'}