Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List numbering Jupyter notebook markdown

I try to create a tutorial for students. I want to number the questions I ask them, but in between I'd like to add information to introduce the questions. How can I make an automatically numbered list that does not reset the numbering each time I put text. For instance:

This is some info.
1. This is question one.

This is more info.
2. This is question two.

Gives output:

This is some info.

  1. This is question one.

This is more info.

  1. This is question two.
like image 222
Chiel Avatar asked Mar 04 '16 13:03

Chiel


People also ask

How do you give numbers in Jupyter Notebook?

You can enable row numbers in one code cell by pressing L while the cell is not active. You can enable row numbers in all code cells by pressing Shift + L while no cell is active. If you cannot remember these hotkeys, open the command palette by pressing Control + Shift + P and search for 'line numbers'.


2 Answers

This is not directly possible with standard Markdown, although you can "fake it" (see below). In fact the rules state:

It’s important to note that the actual numbers you use to mark the list have no effect on the HTML output Markdown produces. ... The point is, if you want to, you can use ordinal numbers in your ordered Markdown lists, so that the numbers in your source match the numbers in your published HTML. But if you want to be lazy, you don’t have to.

If you do use lazy list numbering, however, you should still start the list with the number 1. At some point in the future, Markdown may support starting ordered lists at an arbitrary number.

That future never arrived, officially. However a few different Markdown implementations may offer such a feature as a non-default option. Unfortunately, it is rare (and I don't recall which implementations they are).

Regardless, you will have another problem. It is not clear to me how your desired output would be valid HTML. Essentially, you are asking for paragraphs outside of your list items which are nested inside your list. That would be invalid HTML:

<ol>
  <p>This is some info.</p>
  <li>This is question one.</li>
  <p>This is more info.</p>
  <li>This is question two.</li>
</ol>

That said, it will (almost) display as you desire (the non-list items are also indented).

    This is some info.

  1. This is question one.
  2. This is more info.

  3. This is question two.

I wouldn't recommend it but you could use that as raw HTML. Perhaps you could find some other method or format to represent your data.

I considered suggesting use an ordered list nested inside a definition list if your Markdown implementation supports it (while non-standard, this feature is very common and consistent across implementations, although it may not be on by default). It does give you the proper nesting but the same problem if nonconsecutive numbers persists. However, if you manually add the numbers and escape them so that they are not interpreted as list items, it works like this:

This is some info.
: 1\. This is question one.

This is more info.
: 2\. This is question two.

That renders as:

<dl>
<dt>This is some info.</dt>
<dd>1. This is question one.</dd>
<dt>This is more info.</dt>
<dd>2. This is question two.</dd>
</dl>

And displays as:

This is some info.
    1. This is question one.
This is more info.
    2. This is question two.

Interestingly, as SO removes the (commonly default) indentation on definition lists, in my attempts to fake it in the demo above, I realized there is a simpler solution which should work in all Markdown implementations. Just use paragraphs, manual numbers, and non-breaking spaces to force indentation:

This is some info.

&nbsp; &nbsp; 1. This is question one.

This is more info.

&nbsp; &nbsp; 2. This is question two.

Note that the non-breaking spaces cause Markdown to not see those lines as list items negating the need to escape them. The above renders as:

<p>This is some info.</p>
<p>&nbsp; &nbsp; 1. This is question one.</p>
<p>This is more info.</p>
<p>&nbsp; &nbsp; 2. This is question two.</p>

And displays as:

This is some info.

    1. This is question one.

This is more info.

    2. This is question two.

like image 165
Waylan Avatar answered Sep 20 '22 11:09

Waylan


There are multiple ways we can create lists in Jupyter notebook in markdown mode. The easiest way that I recommend myself is simple: just append * (make sure to include the space after the asterisk) before the item in the list. For example:

* one
* two
* three

Output:

  • one
  • two
  • three

Another way you just type any number and dot like 1. and then type item of the list.

1. one
2. two
3. three

so will see the output as:

  1. one
  2. two
  3. three

and if you want to change the list format like convert dot to number or number to dot just simple change one element in the appropriate format and the whole list will convert.

e.g.

 1. one
 * two
 * three

output will

  1. one
  2. two
  3. three

and

* one
2. two
3. three

output :

  • one
  • two
  • three
like image 43
ShujaR Avatar answered Sep 21 '22 11:09

ShujaR