| Hosted by CoCalc | Download
class Jinja2(object): def __init__(self): import jinja2 self.j2env = jinja2.Environment() self.j2env.filters["latex"] = lambda x: latex(x) def __call__(self, *args, **kwds): if len(kwds) > 0 and len(args) == 0: return Jinja2(**kwds) if len(args) > 0: self._render(args[0], **kwds) def _render(self, cell): tmpl = self.j2env.from_string(cell) out = tmpl.render(**globals()) salvus.md(out) jinja2 = Jinja2()
x = var('x') f(x) = sin(x^2)/x y = 31 ks = [ "a", "ccc", "d"]
# Note: the `variable|filter` notation only works, because the Jinja2 constructor defines the filter "latex"
%jinja2 # header: ${{ f|latex }}$ bold: **y: {{ y }}** {% for entry in ks %} entry at position {{loop.index0}} is {{entry}} {% endfor %}

header: x  sin(x2)xx \ {\mapsto}\ \frac{\sin\left(x^{2}\right)}{x}

bold: y: 31

entry at position 0 is a

entry at position 1 is ccc

entry at position 2 is d