Search code examples
c#winformsequationmath.net

How to format an equation into a C# Form using Math.Net?


I am trying to find a way to format an equation in C#. The steps and result I am trying to achieve are something as follows:

  • First, declare a simple string equation in code like string equation = "a/(b^2)"
  • Second, have this string be displayed on my C# Windows Form (in a Label preferably) but Mathematically formatted. <-- which is the part that I need help with.

Here is an example of how a mathematically formatted equation looks like: Formatted equation example taken from Microsoft Word

Can Math.NET accomplish that? Is yes, please let me know how as this will save me in many ways. If no, are there any alternative methods?

Feel free to link me a Guild for Math.NET that I can read. I already looked for one and didn't find any useful resources.


Solution

  • Ok so after reading a lot, and I mean a lot of resources, I think until I find a better way, this is how I will be approaching this problem:

    I will make html scripts to take LaTeX or TeX text and have them converted by MathJax to formatted equations and rendered on a web page. The output will then be rendered in my windows form app in C# using a the WebBrowser control.

    For those reading this in the future for the same reason, if you can't find the WebBrowser control in the toolbox, just code an instance of it. Something like:

    WebBrowser web = new WebBrowser();
    web.Dock = DockStyle.Fill; // I like to put my browser in a panel Control
    this.Controls.Add(web);
    

    You can add text to its content as follows: web.DocumentText = "your html code"

    Or create another project but make sure it is a Windows Forms App (.NET Framework)

    If anyone have better ways please post them.

    Thanks to everyone who has helped so far.

    Edit: Thanks to Rand Random, there seems to be a better way using CSharpMath (Check the comments of this answer)