Skip to main content

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 mcad2py installed to run. The output isn't standalone: it imports mcad2py.runtime for 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 .py or .ipynb to someone else, they need pip install mcad2py too — 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 Python defs
  • Solve blocks — numeric Given/Find (via scipy.optimize), including a block that defines a function; symbolic solve/simplify/factor/expand via 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

mcad2py-0.1.0.tar.gz (66.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcad2py-0.1.0-py3-none-any.whl (69.4 kB view details)

Uploaded Python 3

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

Hashes for mcad2py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3fa074c2fe5d1fafd9364191c8f9ccf9f924d0054abd323def9b19f26dcd23a7
MD5 2e9b0aded136b17deba44c9c79e0a2f3
BLAKE2b-256 59d4ae2d3be4cd0a65dd002ca9b0584a41e1634185e3c82a144d05f9f68a6817

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcad2py-0.1.0.tar.gz:

Publisher: publish.yml on ChristianCruger/mcad2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for mcad2py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c7ca804e5ce2819af5886fc7a602caeced3ef7efdc3e956a2fec4884ae80bab9
MD5 83b2b80acd2a605cd3fb1654ef8519ef
BLAKE2b-256 ce9de660a2ae2c665dcebc2d1a6c1a06b10fd8d405edd0713ba945ac854f5be1

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcad2py-0.1.0-py3-none-any.whl:

Publisher: publish.yml on ChristianCruger/mcad2py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page