A command-line tool that processes Python code embedded in LaTeX math blocks in Markdown files. Define expressions, bind parameters, evaluate math, and generate computed results.
pip install markdown-math-solver# My Math Document
$5 + 3 py(mySum = THIS)$
Result: $py(ReplaceThis(mySum()))$markdown-math-solver yourfile.mdYour results will be in yourfile.output.md:
# My Math Document
$5 + 3$
Result: $8$markdown-math-solver [-h] [-o OUTPUT] [-v] file
| Argument | Description |
|---|---|
file | Path to the Markdown file to process |
-o, --output | Output file path (default: <input>.output.md) |
-v, --version | Show version number |
-h, --help | Show help message |
# Basic usage (output to yourfile.output.md)
markdown-math-solver yourfile.md
# Custom output path
markdown-math-solver yourfile.md -o result.md
# Check version
markdown-math-solver --version| Syntax | Description |
|---|---|
expr py(name = THIS) | Store the expression before py() as name |
param(var) | Parameter placeholder in expressions |
py(ReplaceThis(value)) | Replace the py(...) with value |
py(ReplaceAll(value)) | Replace the entire $...$ block with value |
name.bind(var=value) | Bind parameters to expression |
name.unbind() | Reset to original with all param(var) restored |
name(var=value) | Bind and evaluate |
name() | Evaluate expression |
THIS | Reference to LaTeX before py() in same block |
You can also use it as a library:
frommarkdown_math_solverimportprocess_markdown, storestore.clear()
result=process_markdown("$1+2 py(x = THIS)$ equals $py(ReplaceThis(x()))$")
print(result) # $1+2$ equals $3$MIT
