Render Python source files as Markdown with inline LaTeX math.
Project description
mathdocs
mathdocs renders ordinary Python source files as Markdown with inline LaTeX
math. The renderer reads annotations, decorators, and docstrings statically — it
never imports or executes the target module — so a .py file is the document.
Installation
pip install mathdocs
A small example
A complete, runnable Python file:
from typing import Annotated
import numpy as np
from mathdocs import Symbol, Tensor, render_as
"""
# Linear model
The prediction is a matrix-vector product plus a bias term, and the loss is
the residual norm scaled by the noise standard deviation.
"""
A: Annotated[np.ndarray, Tensor("A", ("i", "j"))]
x: Annotated[np.ndarray, Tensor("x", ("j",))]
b: Annotated[np.ndarray, Tensor("b", ("i",))]
y: Annotated[np.ndarray, Tensor("y", ("i",))]
sigma: Annotated[float, Symbol(r"\sigma")]
@render_as(latex=r"\left\|{0}\right\|")
def norm(v):
return np.linalg.norm(v)
loss = norm(y - (A @ x + b)) / sigma
Render it:
mathdocs render linear_model.py
Output:
# Linear model
The prediction is a matrix-vector product plus a bias term, and the loss is
the residual norm scaled by the noise standard deviation.
$$
\operatorname{loss} = \frac{\left\|y_{i} - \left(A_{ij}x_{j} + b_{i}\right)\right\|}{\sigma}
$$
The Python module still type-checks and runs unchanged. The annotations and
render_as decorator are metadata that the renderer reads from the source —
nothing executes when MathDocs builds the document.
What the helpers do
Symbol(latex)— annotate a scalar variable with how it should appear in math (e.g.sigma: Annotated[float, Symbol(r"\sigma")]renders as $\sigma$).Tensor(name, indices)— annotate an array with its tensor name and index labels; the renderer attaches the indices automatically when the variable appears in an expression.@render_as(latex="...")— give a function a LaTeX template.{0},{1}etc. are filled with rendered argument expressions.render_figure(path, caption=...)— drop a pre-generated image into the output at a specific point. Useful when a script produces a plot beside the source it documents.
CLI
mathdocs render path/to/file.py # print rendered Markdown
mathdocs symbols path/to/file.py # list discovered symbols
mathdocs check path/to/file.py # report diagnostics
python -m mathdocs <script.py> runs a Python script with the script
directory added to sys.path — useful when a script needs to generate
artifacts (plots, tables) before the renderer reads it.
The MathDocs project (including the VS Code extension) lives at https://github.com/bofrim/mathdocs.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mathdocs-0.1.3.tar.gz.
File metadata
- Download URL: mathdocs-0.1.3.tar.gz
- Upload date:
- Size: 37.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4993f79d89a6af047260842a1328f574ca00a4190ace03ebc5c9020aa0669448
|
|
| MD5 |
6a2d8dd69776b281711bce6b15f48d1d
|
|
| BLAKE2b-256 |
3647812b96d5f2655c5e7a50e6da71bbfde69d7f06f9594cac93e39df6685afd
|
Provenance
The following attestation bundles were made for mathdocs-0.1.3.tar.gz:
Publisher:
release.yml on bofrim/mathdocs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mathdocs-0.1.3.tar.gz -
Subject digest:
4993f79d89a6af047260842a1328f574ca00a4190ace03ebc5c9020aa0669448 - Sigstore transparency entry: 1415338326
- Sigstore integration time:
-
Permalink:
bofrim/mathdocs@58f2f34c753c3fbd767797349fb6ce21817950ed -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/bofrim
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@58f2f34c753c3fbd767797349fb6ce21817950ed -
Trigger Event:
push
-
Statement type:
File details
Details for the file mathdocs-0.1.3-py3-none-win_amd64.whl.
File metadata
- Download URL: mathdocs-0.1.3-py3-none-win_amd64.whl
- Upload date:
- Size: 1.8 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58dc42e3369dd4d3e4d0091840077e97a37ffe4873b49572947ffbd527517125
|
|
| MD5 |
a0c9e28fe886cbffca66926036fc2a3d
|
|
| BLAKE2b-256 |
ea02c00fa5855766cfd552ad65e07e94350009152c3796757781bb1063529d1c
|
Provenance
The following attestation bundles were made for mathdocs-0.1.3-py3-none-win_amd64.whl:
Publisher:
release.yml on bofrim/mathdocs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mathdocs-0.1.3-py3-none-win_amd64.whl -
Subject digest:
58dc42e3369dd4d3e4d0091840077e97a37ffe4873b49572947ffbd527517125 - Sigstore transparency entry: 1415338409
- Sigstore integration time:
-
Permalink:
bofrim/mathdocs@58f2f34c753c3fbd767797349fb6ce21817950ed -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/bofrim
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@58f2f34c753c3fbd767797349fb6ce21817950ed -
Trigger Event:
push
-
Statement type:
File details
Details for the file mathdocs-0.1.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: mathdocs-0.1.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 1.8 MB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d0c7821004cebafa2ef5c9d5d25c0d0584e6638e8d70d06e31131e91a5a8a07
|
|
| MD5 |
ed95e06570d5801661a8b5a48deaaaf6
|
|
| BLAKE2b-256 |
dd901941563dd46247f439da64cbc66081d1ca3952a04c6de884636b40103559
|
Provenance
The following attestation bundles were made for mathdocs-0.1.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release.yml on bofrim/mathdocs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mathdocs-0.1.3-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
1d0c7821004cebafa2ef5c9d5d25c0d0584e6638e8d70d06e31131e91a5a8a07 - Sigstore transparency entry: 1415338528
- Sigstore integration time:
-
Permalink:
bofrim/mathdocs@58f2f34c753c3fbd767797349fb6ce21817950ed -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/bofrim
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@58f2f34c753c3fbd767797349fb6ce21817950ed -
Trigger Event:
push
-
Statement type:
File details
Details for the file mathdocs-0.1.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.
File metadata
- Download URL: mathdocs-0.1.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
- Upload date:
- Size: 1.7 MB
- Tags: Python 3, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b20f4297d8a147d84c4d9cdc34d985a31f5bb5fada1e810864a2fd2ad6e4f7a
|
|
| MD5 |
d7b1553d0ed01affd87ed8e68da476bd
|
|
| BLAKE2b-256 |
229b22da9b93c4ad53cc049deffad5121a54a7c1f1873f85a25b9f66d05d0b1d
|
Provenance
The following attestation bundles were made for mathdocs-0.1.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:
Publisher:
release.yml on bofrim/mathdocs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mathdocs-0.1.3-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl -
Subject digest:
4b20f4297d8a147d84c4d9cdc34d985a31f5bb5fada1e810864a2fd2ad6e4f7a - Sigstore transparency entry: 1415338471
- Sigstore integration time:
-
Permalink:
bofrim/mathdocs@58f2f34c753c3fbd767797349fb6ce21817950ed -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/bofrim
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@58f2f34c753c3fbd767797349fb6ce21817950ed -
Trigger Event:
push
-
Statement type:
File details
Details for the file mathdocs-0.1.3-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: mathdocs-0.1.3-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 1.7 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c46f6e61bb227b94a2c48329b0d6e18359d6583d7d29ddaf8685e7c2b44be75f
|
|
| MD5 |
6d0af096052b3069d74e590af88ea522
|
|
| BLAKE2b-256 |
e4dc283c20b040bcad219f6aada2dc4244b018f1cabb9175fc749810124999d9
|
Provenance
The following attestation bundles were made for mathdocs-0.1.3-py3-none-macosx_11_0_arm64.whl:
Publisher:
release.yml on bofrim/mathdocs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mathdocs-0.1.3-py3-none-macosx_11_0_arm64.whl -
Subject digest:
c46f6e61bb227b94a2c48329b0d6e18359d6583d7d29ddaf8685e7c2b44be75f - Sigstore transparency entry: 1415338601
- Sigstore integration time:
-
Permalink:
bofrim/mathdocs@58f2f34c753c3fbd767797349fb6ce21817950ed -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/bofrim
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@58f2f34c753c3fbd767797349fb6ce21817950ed -
Trigger Event:
push
-
Statement type: