Based on https://www.fast.ai/2020/01/20/nb2md/, using nbdev and the fastai repo template.

Notes:

  1. It’s very important that the title be in a single cell at the beginning. only the # My title part will be included in the processed markdown file.
  2. This post is generated by this notebook, by activating the virtualenv and running:
    ./make-post.py notebooks/2020-09-06-example-post.ipynb 
    

Here is an image that is copy/pasted into the cell: image.png

Here is some LaTeX: $\alpha(x^y) = z$

Here is some code:

for x in range(10):
    print(x)
0
1
2
3
4
5
6
7
8
9

Here is some more markdown.

And here is some code that generates an SVG:

import pygraphviz as pgv
from IPython.display import Image, SVG, display
import networkx as nx

def draw(graph):
    svg = nx.nx_agraph.to_agraph(graph).draw(prog='dot',format='svg')
    display(SVG(svg))

    
import networkx as nx
G = nx.DiGraph()
G.add_edge('a', 'b')
G.add_edge('a', 'c')
G.add_edge('b', 'd')
G.add_edge('c', 'd')
G.add_edge('e', 'f')
G.add_edge('h', 'f')
G.add_edge('confounder', 'h')
G.add_edge('confounder', 'f')

draw(G)

svg

Here is some code that generates latex from sympy:

import sympy
x, y = sympy.symbols('x y')
sympy.expand((x + y) ** 20)

$\displaystyle x^{20} + 20 x^{19} y + 190 x^{18} y^{2} + 1140 x^{17} y^{3} + 4845 x^{16} y^{4} + 15504 x^{15} y^{5} + 38760 x^{14} y^{6} + 77520 x^{13} y^{7} + 125970 x^{12} y^{8} + 167960 x^{11} y^{9} + 184756 x^{10} y^{10} + 167960 x^{9} y^{11} + 125970 x^{8} y^{12} + 77520 x^{7} y^{13} + 38760 x^{6} y^{14} + 15504 x^{5} y^{15} + 4845 x^{4} y^{16} + 1140 x^{3} y^{17} + 190 x^{2} y^{18} + 20 x y^{19} + y^{20}$

And the same thing, but hidden (should be blank):

And the same thing, but with the input hidden (should have Latex but not the code):

$\displaystyle x^{20} + 20 x^{19} y + 190 x^{18} y^{2} + 1140 x^{17} y^{3} + 4845 x^{16} y^{4} + 15504 x^{15} y^{5} + 38760 x^{14} y^{6} + 77520 x^{13} y^{7} + 125970 x^{12} y^{8} + 167960 x^{11} y^{9} + 184756 x^{10} y^{10} + 167960 x^{9} y^{11} + 125970 x^{8} y^{12} + 77520 x^{7} y^{13} + 38760 x^{6} y^{14} + 15504 x^{5} y^{15} + 4845 x^{4} y^{16} + 1140 x^{3} y^{17} + 190 x^{2} y^{18} + 20 x y^{19} + y^{20}$

And the same thing, but with the output hidden (should have the code but not the Latex):

# hide_output
import sympy
x, y = sympy.symbols('x y')
sympy.expand((x + y) ** 20)