Faster math typesetting with Python (Part 2)

Mathcube
5 min readDec 3, 2021

This is part 2 of my programming series about the Python package swiftex for writing math in Jupyter as fast as with pencil and paper. Follow me along the development and feel free to influence its course by commenting this article or any other of the series.

Today, let’s continue with the foundations, and of course we still stay with the test-driven development style (TDD). After this article, the package shall enable us to do things like this:

>>> Int(-oo, oo) * f(x) * dx

When entered at the console, it shall return the corresponding LaTeX string

Out: \int_{-\infty}^{\infty} f(x) dx

but when entered in a Jupyter cell, it shall output the rendered version:

You may ask yourself why I’m not using something like sympy for this? Well, the problem is that sympy forces me to use a fixed syntax. For example, in sympy, I cannot say

But turning around the order of integrand and differentials is exactly how many physicists like to write integrals! sympy is simply not flexible enough in writing math notation and it forces one to press one’s thinking into what’s possible with sympy. That’s a killer for any creative process. So the goal for my package is to have something to write arbitrary math syntax fast and easily.

Let’s start with today’s features. First, take care of the integral sign itself. Write the test:

def…

--

--