mcad2py
Convert PTC Mathcad Prime worksheets (.mcdx) into runnable Python — either a
Jupyter notebook (one region per cell, results echoed inline like Mathcad's =) or a
plain .py script. Units are preserved with Pint.
A .mcdx file is a zip archive of XML; the math is stored as an expression tree, so the
conversion walks that tree into an intermediate representation and emits Python from it.
Install
pip install mcad2py
Or from a clone, for development:
git clone https://github.com/ChristianCruger/mcad2py
cd mcad2py
pip install -e ".[dev]"
Requires Python 3.10+. Dependencies: pint, nbformat, sympy, numpy, scipy,
matplotlib, Pillow.
Usage
# Jupyter notebook (default)
mcad2py convert worksheet.mcdx # -> worksheet.ipynb
mcad2py convert worksheet.mcdx -o out.ipynb
# Plain Python script
mcad2py convert worksheet.mcdx -f py # -> worksheet.py
mcad2py convert worksheet.mcdx -o - -f py # to stdout
Or from Python:
from mcad2py import convert_file
print(convert_file("worksheet.mcdx", fmt="py"))
Example
A Mathcad region f_cd := 30 MPa / 1.5 = (displayed in MPa) becomes, in a notebook cell:
f_cd = 30 * ureg.MPa / 1.5
f_cd.to(ureg.MPa) # the bare last line echoes "20 megapascal", like Mathcad's "="
Mathcad trig handles angle units automatically; generated code matches this via small
angle-aware helpers (from mcad2py.runtime import sin, cos, tan, cot), so
tan(phi) works whether phi is in deg or rad.
Converted code needs
mcad2pyinstalled to run. The output isn't standalone: it importsmcad2py.runtimefor the unit- and shape-aware helpers that give Mathcad's semantics rather than Python's (angle-aware trig,matmul,index_build,solve_block, …). If you send a converted.pyor.ipynbto someone else, they needpip install mcad2pytoo — along with the dependencies above, since the generated code uses Pint, NumPy, SciPy and matplotlib directly.
What's supported
:=definitions and inline=evaluations, with display-unit overrides- Arithmetic, unit scaling (
30 MPa), roots,%, comparisons and boolean connectives - Constants (
π,e,∞), Greek/subscripted identifiers (f_cd,β,ϕ→f_cd,beta,phi) - Vectors and matrices — literals, 0-based indexing (including the two-subscript form),
ranges, range-built vectors and matrices, and the full built-in family:
rows/cols/identity/augment/submatrix,det/lsolve/geninv/rank/rref, the norm and condition sets, the eigen and singular-value set,sort/reverse. Mathcad's one·is resolved into a scalar, matrix or dot product by inferring shapes across the whole sheet. - Functions — the complete trigonometric and hyperbolic families (angle-aware), logs,
powers and roots, rounding,
min/max,linterp - Programs — inline and block
if, plus multi-line imperative programs (loops, local←assignments,return,try) emitted as real Pythondefs - Solve blocks — numeric Given/Find (via
scipy.optimize), including a block that defines a function; symbolicsolve/simplify/factor/expandvia SymPy - Integrals and sums — definite and double integrals (
scipy.integrate), indexed Σ - Plots — x-y (function and parametric), contour and 3D, rendered with matplotlib
- Controls and tables — ComboBox row selectors, data tables, scriptable controls (via their cached value), text/comment regions → markdown cells
- Images embedded from picture regions
Anything not yet handled is emitted as a clearly marked # TODO unsupported stub rather than
dropped, so the output always loads. See
docs/mathcad-function-coverage.md for the full
category-by-category map and what's next.
Tests
The suite lives in the git repository (it is not part of the published package, since each test
converts and executes a real .mcdx fixture from references/):
git clone https://github.com/ChristianCruger/mcad2py
cd mcad2py
pip install -e ".[dev]"
pytest
Every test converts a reference worksheet, runs the generated code, and checks the computed
values against Mathcad's own cached results in that file's result.xml.
Scope
Targets Mathcad Prime (.mcdx, worksheet50/math50 schema). Legacy Mathcad 15
(.xmcd) is a future target — the parser is structured behind an intermediate representation
so a second front-end can be added without changing the code generators.
License
MIT — see LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 mcad2py-0.1.0.tar.gz.
File metadata
- Download URL: mcad2py-0.1.0.tar.gz
- Upload date:
- Size: 66.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3fa074c2fe5d1fafd9364191c8f9ccf9f924d0054abd323def9b19f26dcd23a7
|
|
| MD5 |
2e9b0aded136b17deba44c9c79e0a2f3
|
|
| BLAKE2b-256 |
59d4ae2d3be4cd0a65dd002ca9b0584a41e1634185e3c82a144d05f9f68a6817
|
Provenance
The following attestation bundles were made for mcad2py-0.1.0.tar.gz:
Publisher:
publish.yml on ChristianCruger/mcad2py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcad2py-0.1.0.tar.gz -
Subject digest:
3fa074c2fe5d1fafd9364191c8f9ccf9f924d0054abd323def9b19f26dcd23a7 - Sigstore transparency entry: 2300560107
- Sigstore integration time:
-
Permalink:
ChristianCruger/mcad2py@1fa72ac7da8867fa41790029f99dfe2ffa651fef -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ChristianCruger
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1fa72ac7da8867fa41790029f99dfe2ffa651fef -
Trigger Event:
push
-
Statement type:
File details
Details for the file mcad2py-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mcad2py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 69.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7ca804e5ce2819af5886fc7a602caeced3ef7efdc3e956a2fec4884ae80bab9
|
|
| MD5 |
83b2b80acd2a605cd3fb1654ef8519ef
|
|
| BLAKE2b-256 |
ce9de660a2ae2c665dcebc2d1a6c1a06b10fd8d405edd0713ba945ac854f5be1
|
Provenance
The following attestation bundles were made for mcad2py-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on ChristianCruger/mcad2py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcad2py-0.1.0-py3-none-any.whl -
Subject digest:
c7ca804e5ce2819af5886fc7a602caeced3ef7efdc3e956a2fec4884ae80bab9 - Sigstore transparency entry: 2300560129
- Sigstore integration time:
-
Permalink:
ChristianCruger/mcad2py@1fa72ac7da8867fa41790029f99dfe2ffa651fef -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ChristianCruger
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1fa72ac7da8867fa41790029f99dfe2ffa651fef -
Trigger Event:
push
-
Statement type: