Skip to content

Repository files navigation

Markdown Math Solver

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.

Demo

Watch the demoWatch the demo

Installation

pip install markdown-math-solver

Quick Start

1. Create a Markdown file with embedded py() blocks

# My Math Document
$5 + 3 py(mySum = THIS)$
Result: $py(ReplaceThis(mySum()))$

2. Run the tool

markdown-math-solver yourfile.md

3. Check output

Your results will be in yourfile.output.md:

# My Math Document
$5 + 3$
Result: $8$

Usage

markdown-math-solver [-h] [-o OUTPUT] [-v] file
ArgumentDescription
filePath to the Markdown file to process
-o, --outputOutput file path (default: <input>.output.md)
-v, --versionShow version number
-h, --helpShow help message

Examples

# 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 Overview

SyntaxDescription
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
THISReference to LaTeX before py() in same block

Python API

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$

License

MIT

About

A command-line tool that processes Python code embedded in LaTeX math blocks in Markdown files. :s1:p0

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages