Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

R

Views: 4030
Kernel: R (R-Project)

© Copyright 2016 Dr Mike Croucher and Dr Marta Milo

Using the Jupyter Notebook as a Word Processor

In this notebook we will list a set of basic formatting commands that helps when using markdown cells as Word processor. It will be useful when adding text to your data analysis and also for sharing the notebook in collaborative projects.

Markdown

It is possible to use the notebook as a wordprocessor by making use of Markdown Cells.

Markdown is a very simple language that allows you to format your text in your notebook. It is used in many research projects around the world and it represents an ideal tool for data sharing. As well as the Jupyter notebook, another very important project that uses Markdown to format text is the github code-sharing site. SageMathCloud is also making use of github for the code-sharing and file management. Markdown, being a language, has its own syntax to implement the formatting of the text. In this brief document we list some commonly used syntax for basic text formatting.

Bold and italics

Unlike word processors such as Microsoft Word, you do not highlight text and click on something to change its format. Instead, you use the Markdown syntax to tell the computer how to format your text.

If you want some text to appear in bold, you surround it with two asterisks like this:

**This will be bold**

the result format will be:

This will be bold

If you want the text to be in italics, you surround it in just one asterisk

*This will be in italics*

the result format will be: This will be in italics

Lists

We often create lists in our text, as bullet points or as numbered items.

If we want to create bullet point lists, we can do so in markdown by putting an asterisk and a space in front of each item like this:

* item1 * item2 * item3

the resulting format will be:

  • item1

  • item2

  • item3

To create nested lists add 4 spaces to the beginning of each line to indent it by one level. Add 8 spaces to indent by two levels like in the example below:

* item1 * item1a * item1b * This has 8 spaces before the * * item2

the resulting format will be:

  • item1

    • item1a - This has 4 spaces before the *

    • item1b

      • This has 8 spaces before the *

  • item2

Finally to create a numbered list, you need to number the first entry and use asterisks for the other entries.

1. First * Second * Third
  1. First

  • Second

  • Third

Markdown does not support numbered nested lists. If you want to create nested indented lists, you can use the 4 spaces indentation and numbered list, like in the example below:

1. Dog * German Shepherd * Belgian Shepherd * Malinois * Groenendael * Tervuren * Cat * Siberian * Siamese

The result of the formatting is:

  1. Dog

    • German Shepherd

    • Belgian Shepherd

      • Malinois

      • Groenendael

      • Tervuren

  2. Cat

    • Siberian

    • Siamese

Mathematics

You can also use mathematical notation in markdown. Within a markdown cell, something surrounded in $ or $$, is considered as an equation. You write equations using a language called LaTeX\LaTeX (pronounced 'lay-tek' since the X is really a Greek letter chi).

Don't worry, you don't need to learn very much of this language - most people only need to learn a tiny number of commands. Here are some examples:

Superscript

Commonly used for powers. You use the ^ symbol

$x^2$

x2x^2

Subscript

One use for subscipts is in chemical forumlae:

$H_2O$

H2OH_2O

Fractions

Fractions are a little more complicated. We use the form \frac{numerator}{denominator}

$\frac{1}{x^2+1}$

1x2+1\frac{1}{x^2+1}

\frac is a LaTeX\LaTeX command and all such commands start with a \

Square root

We need another LaTeX\LaTeX command \sqrt. The argument to the square root function is put in curly brackets

$\sqrt{a+b}$

a+b\sqrt{a+b}

Sums

To sum a quantity N times we can use

$\sum_{n=1}^{N} 2^{-n} = 1$

the result will be:

n=1N2n=1\sum_{n=1}^{N} 2^{-n} = 1

Products

To multiply a quantity n times we can use

$\prod_{i=a}^{b} f(i)$

the results will be:

i=abf(i)\prod_{i=a}^{b} f(i)

Integrals

Integral notaton can be written using the following command:

$\int_{a}^{b} x^2 dx$

the result will be:

abx2dx\int_{a}^{b} x^2 dx

or we can use integral notation, without upper or lower limits, with the following command:

$\int x^2 dx$

the result will be:

x2dx\int x^2 dx

Web links such as http://www.walkingrandomly.com/ become clickable when the Markdown code is evaluated so just type them in.

If you want to turn a piece of text into a weblink, you surround it in square brackets and put the web adress after it in round brackets. Like this:

[Here is a link to Mike's blog](http://www.walkingrandomly.com/)

Here is a link to Mike's blog

Images

If the image is online, you use syntax that's very similar to a link but with a ! in front of it

![The equation that says Hi](http://www.walkingrandomly.com/images/matlab/hi1_matlab.png)

The equation that says Hi

Alternatively, you can put an image in the same folder as your notebook and link to it like this:

![An image from Chen et al (2014](images/Chen_et_al.png)

An image from Chen et al (2014

Tables

You can create tables in Markdown cells by doing something like this:

Column A | Column B ------------- | ------------- Row 1 | 1.0 Row 2 | 2.0

This produces the output

Column AColumn B
Row 11.0
Row 22.0

In practice, you'll rarely do this as you'll generate your tables using the R programming language.