At first I was just writing them in plain text, like:
ax^2 + bx + c = 0
or gradient expressions written out linearly.
But as the equations became more complex it quickly became ugly and hard to read inside the code.
So I switched to writing them in LaTeX inside docstrings.
That solved the structure problem, but the equations were still not easy to visualize while reading the code.
So I built a small VS Code extension that renders the LaTeX directly.
PyMath Preview supports:
- inline math: $...$ - display math: $$...$$ - math inside Python docstrings - math inside comment blocks
Example:
def energy():
""" Einstein's mass–energy equivalence $$ E = mc^2 $$ """
Curious if others writing math-heavy Python code run into the same problem.
sankarebarri•1h ago
At first I was just writing them in plain text, like:
ax^2 + bx + c = 0
or gradient expressions written out linearly.
But as the equations became more complex it quickly became ugly and hard to read inside the code.
So I switched to writing them in LaTeX inside docstrings.
That solved the structure problem, but the equations were still not easy to visualize while reading the code.
So I built a small VS Code extension that renders the LaTeX directly.
PyMath Preview supports:
- inline math: $...$ - display math: $$...$$ - math inside Python docstrings - math inside comment blocks
Example:
def energy():
It uses KaTeX for fast rendering and it is lightweight.Curious if others writing math-heavy Python code run into the same problem.