Metadata-Version: 2.4
Name: math2tex
Version: 1.0.2
Summary: A high-performance compiler for translating plaintext mathematics into LaTeX.
Author: NicknamedTwice
License: MIT License
License-File: LICENSE
Requires-Python: >=3.8
Requires-Dist: hypothesis>=6.0.0
Requires-Dist: pytest>=7.0.0
Description-Content-Type: text/markdown

# math2tex

A high-performance compiler for translating plaintext mathematics and English prose into clean, structural, and beautifully formatted LaTeX. 

`math2tex` is powered by a Do What I Mean (DWIM) AST engine that treats English prose as first-class grammatical constructs. It doesn't just do naive string replacement; it fully tokenizes and parses the mathematical intent into an Abstract Syntax Tree, intelligently handling spacing, implicit grouping, function application, piecewise definitions, and matrix alignment.

## Features

- **DWIM AST Engine**: Intelligently infers intent and groups mathematical structures based on linguistic context (e.g., differentiating between absolute value and cardinality based on preceding sentences).
- **Prose Continuity**: Handles inline mathematics within English sentences flawlessly, correctly inserting `\text{}` wrappers.
- **Auto-Alignment**: Converts multi-line equations and definitions directly into `\begin{align*}` environments, automatically routing English prose into `\intertext{}`.
- **Robustness**: 100% test pass rate against exhaustive unit tests and deep Hypothesis-driven AST property testing.

## Installation

You can install `math2tex` directly using `pip`:

```bash
pip install .
```

For development and testing, install the test dependencies:
```bash
pip install pytest hypothesis
```

## Python API Usage

`math2tex` provides a clean public API for developers to use directly in their Python projects.

```python
import math2tex as m2t

# Single-line compilation
latex = m2t.compile("integral from 0 to infinity of e^(-x^2) dx")
print(latex)
# Output: \int_{0}^{\infty}e^{-x^{2}}\dd{x}

# Prose and inline math
latex = m2t.compile("Let x = 5. Assume x is greater than 2.")
print(latex)
# Output: \text{Let } x=5. \text{ Assume } x>2.

# Multi-line equations and auto-alignment
text_block = \"\"\"
a = b
since c > d
x < y
\"\"\"
multi_latex = m2t.compile_multiline(text_block)
print(multi_latex)
# Output: 
# \begin{align*}
# a & = b \\
# \intertext{$ \text{since } c>d $}
# x & < y
# \end{align*}
```

## CLI Usage

The package comes with a robust Command Line Interface out of the box.

### Interactive REPL
Quickly convert equations in an interactive loop:
```bash
python -m math2tex repl
```
*Note: Type `MULTI` in the REPL to enter a multi-line environment block.*

### Watch Mode
Automatically compile a text file into LaTeX whenever you save it:
```bash
python -m math2tex watch input.txt output.tex
```

### Omni-Tester
Run the comprehensive test suite (combining deterministic unit tests with property-based randomized fuzzing) to ensure the AST is mathematically sound:
```bash
python -m math2tex test
```