2

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.

  • 1
    https://stackoverflow.com/questions/8899204/how-to-render-a-formula-in-wpf-or-winforms – Rand Random Aug 06 '23 at 20:31
  • Without a more focused question, the best we can do is point you to Rand's link. For a better chance at a more quality answer, try using the library yourself and post about your attempt and the precise problem you're having. – gunr2171 Aug 06 '23 at 20:52
  • In addition, the library you mention, [math.net](https://www.mathdotnet.com/), doesn't look to do any sort of rendering. Do you have any research that says it should have that functionality? – gunr2171 Aug 06 '23 at 20:55
  • I am currently looking into the link RandRandom has provided. It seems to be in the right direction. When I am done reading I will post an update of the results. Thank you guys and in the mean while if anyone has more suggestions feel free to post them. I have been looking into this problem for 5 hours straight now. In fact, this is the second related question I have on Stack Overflow [Here](https://stackoverflow.com/questions/76846639/what-methods-can-be-used-to-format-an-equation-into-a-c-sharp-form/76846768?noredirect=1#comment135475886_76846768) which answers your question @gunr2171 – Alex Schmidt Aug 06 '23 at 21:24
  • A helpful link for you. Please [check](https://stackoverflow.com/questions/23355327/display-equations-in-windows-form-desktop-application-in-c-sharp) – Ishtiaq Aug 07 '23 at 07:20

1 Answers1

1

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)

  • 1
    Have you considered using https://github.com/verybadcat/CSharpMath with a SkiaSharp control as is described here? https://github.com/verybadcat/CSharpMath/issues/169#issuecomment-705133389 (comments below will show a full sample) - the provided sample looks like this, in a winforms .net7 app https://i.stack.imgur.com/udJXB.png – Rand Random Aug 07 '23 at 10:55
  • @RandRandom That seems to be working great for me so far. Thank you so much for your comment I will probably be using CSharpMath now. – Alex Schmidt Aug 11 '23 at 21:11