PyMath Preview

PyMath Preview is a lightweight VS Code extension for rendering LaTeX math written inside Python docstrings and comment blocks.
What It Does
- Renders inline math:
$...$
- Renders display math:
$$...$$
- Designed for Python files:
- triple-quoted docstrings (
"""...""" or '''...''')
- contiguous
# comment blocks
- Works from explicit selection, or inferred Python blocks when selection is empty
How To Use
def energy():
"""
Einstein's mass–energy equivalence:
$$
E = mc^2
$$
"""
- Open a Python file.
- Select math text, or place the cursor inside a docstring/comment block.
- Run
PyMath Preview: Show Preview from Command Palette.
Default keybinding: Ctrl+Alt+M (Cmd+Alt+M on macOS).
Additional commands:
PyMath Preview: Copy LaTeX
Syntax Support
Inline math: $E = mc^2$
Display math:
$$
\frac{a+b}{c}
$$
Break Marker (Display Math Only)
If enabled, <|> inside display blocks is converted to \\allowbreak before rendering.
- Applies only inside
$$...$$
- Remains literal in inline math and plain text
Settings
pymathPreview.breakMarker (default: <|>)
Display-only soft-break marker text.
pymathPreview.autoSoftBreaks (default: false)
Adds conservative \\allowbreak points in display math.
pymathPreview.autoFitDisplayMath (default: false)
Scales overflowing display equations to fit preview panel (within safe limits).
pymathPreview.mathFontScale (default: 1.0)
Global math scale fallback.
Troubleshooting
- If a formula fails, check balanced
$$ delimiters.
- For multi-line derivations, prefer
aligned blocks with explicit \\ line breaks.
License
MIT
| |