Search code examples
jupyter-notebooklatexmarkdown

math equations in ordered lists in jupyter notebook


I am trying to format math equations in a Jupyter notebook. Specifically, I want to add math equations embedded in text in an ordered list, similar to how \begin{enumerate} works in Latex. From what I understand, I should format using html, but write the math in MathJax.

Here is an example of what I want it to look like.

Here is an example of what I have tried.

<ol type="a">
<li> It should look something like this $b= \begin{pmatrix} 2\\ 2\\ -1 \end{pmatrix}$<\li>
<li> and be able to start an equation in between as well
$$
A= \begin{pmatrix}\epsilon & 1\\ 1 & 1\end{pmatrix}
$$
</ol>

Solution

  • You just need to use a markdown cell combining two things:

    • numbered list-specifying Markdown elements (as pointed out here, see the link in Tom Willis' answer to the markdown specification guide)
    • MathJax rendering using both in-line and paragraph typesetting style, see here and here.

    No need for the HTML you've been including.
    Your stated goal can be achieved with this text in markdown cell in a Jupyter .ipynb file:

    1. It should look something like this $b= \begin{pmatrix} 2\\ 2\\ -1 \end{pmatrix}$
    
    1. and be able to start an equation in between as well:
    $$
    A= \begin{pmatrix}\epsilon & 1\\ 1 & 1\end{pmatrix}
    $$
    

    The result of that: enter image description here

    Fortunately, the use of centered equation doesn't interrupt the numbering and so you can continue even adding to the list. I find with some other formatting it kicks things out and doesn't continue the numbering. Yet, right now this works:

    1. It should look something like this $b= \begin{pmatrix} 2\\ 2\\ -1 \end{pmatrix}$
    
    1. and be able to start an equation in between as well:
    $$
    A= \begin{pmatrix}\epsilon & 1\\ 1 & 1\end{pmatrix}
    $$
    
    1. It will even continue the numbering correctly after that $b= \begin{pmatrix} 201\\ 84\\ -19 \end{pmatrix}$
    

    The result: enter image description here



    By the way, if you wanted to generate such markdown rendering programmatically from a code cell within a Jupyter .ipynb file that is possible, too, see here and refereinces therein, especially this succinct StackOverflow answer.