DEV Community

Kidus Adugna
Kidus Adugna

Posted on

I made a Mathcad alternative using Python

I assume most people here are a little inclined to web development and so the name Mathcad might be new. PTC Mathcad is a desktop app built primarily for engineers to do math on a really readable document. It's like a limited word processor focused rather on doing calculations (MATLAB competitor) and how to display them.

Mathcad screenshot (Google images)

Now It's a really awesome tool. So why did I create an alternative? Well, it has some pain points, at least for me.

  • It does not support exporting to LaTeX or Word. It can export to a Rich Text Format (.rtf) file which can be read by Word, but...
  • When exporting to .rtf, the equations are converted to images and editing ability is lost. Also the text is in text boxes so you need to do some work in order to make your document obey some standards.
  • For simple calculations, it's fine but for big works, which might require some programming parts like loops and conditionals, you have to learn a new language, which is more graphically oriented. Let's just say it's not for everyone.
  • Again for big works, you may need a lot of word processing and related things (headings, TOC, citations, bibliography, index, etc.) which it does not have.
  • It's really big, like the installer is around 900MB. I suspect that's because of the symbolic engine but for someone who does not need most of the bells and whistles, that's a lot.
  • It is not cross-platform. This may not be a deal breaker for people who usually need something like that because (we)'re Windows users.

Introducing docal (what a name right?). It's written in Python. It's available as a kind of a compiler CLI and also a GUI built with Tkinter.

docal screenshot

It solves all of the issues above.

  • It supports both LaTeX and Word
  • Writes all equations in the native format of the respective document type (LaTeX or Word), means they can be editted, copied or anything as if you wrote them by hand. And all text is written normally.
  • Very small, available as a Python package with no dependencies and a pre built GUI (whose installer is below 9MB)
  • Cross-platform (although I have not tested it on systems other than windows, it should be, because Python is).

Additionally, the fun part, it can insert calculations into existing documents at places specified by hashtags. This is so that you make no compromises on anything. Word and LaTeX are the best for word processing. Therefore it will not try to compete with them on that. But they are not designed to do calculations. docal fills that gap, and nothing more. You do the other parts of the document in Word or LaTeX, and the calculation parts in docal and insert them into the main document.

I started working on something very primitive to this a year and a half ago when I was doing mechanical projects at university. It started out as just a text replacement program for LaTeX files, easier because they are just text files. Then a friend suggested Word support. Then little by little, I started using it more and adding features and fixing issued along the way. Then I did my final year project with it and it was great! I was comfortable with working in a text editor and using the CLI but not all people are. So a GUI was necessary. But there was no support for displaying math in Tkinter (as far as I know). So I first used PyWebview and used KaTeX for the math. But, being a webview, it got slow for longer works. So I decided to tackle it using Tkinter. To do that, I first had to find a way to render math. So I made tkinter-math, a package to render math on a tkinter canvas. Then everything else was easy and the current implementation happened.

P.S. This is my first post on DEV, so if you think there is something I need to improve, please tell me.

Discussion (2)

lihi64 profile image

Wow!! Amazing!
I have been looking for a long time for a comfortable way to display math with tkinter.
I wanted to create an equation solver and I thought it was impossible until I saw your post.
Is there any chance you can help me understand how to start?
Thank you in advance.

eng_rey profile image
Rey Mangubat, P.Eng. πŸ‡¨πŸ‡¦

Well this is what i'm planning to do as well. To create my own version of mathcad. Let me try this then and I will let you know.