Rendering TeX Math in WPF

So in my small periods of free time recently, I’ve picked up an old project of mine. As part of my long-term plans for the Syracuse project, I am creating a mathematical TeX (ultimately LaTeX) renderer for .NET 4.0.

My recent investigations led me to the JMathTeX library, which is a pure Java renderer for the mathematical subset of the TeX system. Me being a C# fan rather a Java one (who starts projects in Java these days anyway?), I decided to port the whole thing to C#/.NET and use the Windows Presentation Foundation (WPF) as the front end. Plans are to eventually integrate (most of) the functionality from JLatexMath into the .NET library too, giving a very complete and stylish renderer for mathematical formulae/renderer. With a bit of luck, I may even be able to integrate the renderer directly with my TeX.NET library, thus eliminating (at least in theory) the need to use TeX syntax for rendering.

To my surprise, I’ve actually had a lot of success on this port. The code is still pretty horrendous in some ways, as it’s all written in Java rather than C# style, not to mention I’ve had to hack a few things to get it to work. Nonetheless, it seems to be rendering just as well as the original Java library, or so my small example demonstrates. The complete code is available from my personal Bazaar repository here, which I ought to be updating regularly. All you need to compile and test is an installation of the .NET 4.0 framework and Visual Studio 2010 RC.

Check back for further updates soon, as I hope to be posting some screenshots of the software in action. Given that I’ve largely put a lid on serious programming with all the other things going on in my life at the moment, it may be some while before any official release… still, feel free to check out the rough work so far.

19 Responses to “Rendering TeX Math in WPF”

  1. Tobias says:

    Hello,

    we are very interested in your project.
    But bzr is only showing an error, when we try to DL your project.
    Is something wrong with your repository?
    Can you eventually send the project via email.

    Thank you very much.

    Tobias

  2. Noldorin says:

    Hi Tobias. I recently upgraded the back-end of the website, so there may indeed be problems. I will check into it. For now, could you please tell me the full error? Cheers.

  3. Johanna says:

    Well, since I want to check this out too and got an error, here it is,

    First dialog after trying to open
    “Unable to open location
    http://noldorin.com/repos/wpf-math/ is not a branch, checkout or repository. Do you want to pen it as virtual repository, searching for nested locations? ”

    I selected yes and got
    “Error
    bzr: Error: Transport operation not possible: Transport has not implemented list_dir (but must claim to be listable to trigger this error). ”

    I hope that helps you to get it fixt, have been looking for weeks for a way to get WPF to show math formulas.

    // Jo

  4. Tobias says:

    I tried with the comandline bzr

    C:\NET_Projects\wpfmath>bzr get http://noldorin.com/repos/wpf-math/
    bzr: ERROR: Not a branch: “http://noldorin.com/repos/wpf-math/”.

    Thank you in advance.

  5. Noldorin says:

    I confirmed that I was getting the same error, and it seems the problem was down to me forgetting to update the configuration files after the upgrade to IIS7. Sorry about that.

    You should be able to pull the branch now successfully, but let me know if there any further difficulties.

  6. Tobias says:

    Hello Noldorin,

    thanks for your efforts.
    I was now able to pull the branch successfully.
    But now I am not able to see any rendered Math in the Example.
    Looked into it with WPF Inspector and saw nothing more than a white screen in VisualContainerElement.
    (i gave it to my colleague and he has the same problems)

    thanks

  7. Noldorin says:

    Hi Tobias. That’s quite odd. Does the sample app not run a window containing a textbox for inputing TeX math? If not, then perhaps I need to update it to the latest revision. Let me know; cheers.

  8. Tobias says:

    Hi Noldorin,

    we both had the Window running.
    A Textbox with a Scrollviewer. But independet from what was typed inside the Textbox, the Scrollviewer showed nothing.
    I was not able to Debug deeper into it, but what I can say is, that the “visual” object (the Child from Scrollviewer) ist NOT null.

    Thanks in advance.

    Tobi

  9. Tobias says:

    I am sorry, but whats the state of this problem?
    Can you look further into it, or do we need to look for another way?

    Thanks in advance.

  10. Noldorin says:

    Hello. I checked just briefly and it worked fine for me. Will have another go tonight/tomorrow hopefully.

  11. Noldorin says:

    Tobias/Johanna: I’ve gone and fetched the most recent version of the library and example project from my local copy and uploaded (overwritten) the wpf-math branch on the server. Things are certainly working for me here! Try doing a fresh pull/checkout and let me know if that works. Good luck.

  12. Tobi says:

    very good news!
    Thank you noldorin.
    I’ll try it on monday at work.
    (My Linux/Mono here is not running WPF…)

  13. Noldorin says:

    Hi Tobias – how did the test go at work? A.

  14. Tobias says:

    Hi Noldorin,
    I am sorry, but it didn’t work either.
    When I try to Render a simple “e” instead of something complex, even then the screen is empty.
    But when I look with WPFInspector (a very handy tool – free!) I can see, that the visual is here and not empty. But the rendered “e” is a bit “crookbaked”.
    I can’t get into the problem here, the only thing I see is, with more complex formulas, I get a KeyNotFoundException from “predefinedFormulas”. I think because it is Count=0. It is never filled, and I can’t figure out, where it has to be filled, or with which it has to be filled.
    I didn’t want to bother you, so I didn’t ask you again….

    Greets
    Tobias

  15. Noldorin says:

    Oh, how odd! The project works perfectly for me. I’ve also helped out another guy in the past who used it successfully in his project. Perhaps you can test on another machine? It works fine on both my Windows 7 laptops. Cheers. A.

  16. Tobias says:

    Really odd, but I am happy about your support on this. ;-)
    I tried it on my XP machine and on another Windows 7 machine (Home, currently not in Domain). => empty Scrollview
    Is it possible that I have wrong prerequisites? Do I need a special font? Or Something else.
    Another thing:
    Should I write on the launchpad site in future? Because this comment section is soon flooded…

    Thanks for all your previous help, I am really glad about your contact.

  17. Noldorin says:

    Just a quick update here: thanks to some investigation and debugging effort on Tobias’ side as well as my own, we have no resolved a significant bug that prevented anything from rendering proeprly on foreign-culture machines.

    Please pull the latest revision from the wpf-math repo on my server to get the fix.

  18. Phuc Nguyen says:

    Hello.
    This porject is great. It’s very useful for me.
    But I have a problem with it. I don’t know how to render a system of linear equations, and a matrix with WPF Math.
    Could you tell me how please?
    Thanks so much

  19. Noldorin says:

    Hi Phuc,

    I’m afraid there is no support for matrices or complex tabular formatting like that at present. JLatexMath added support for that, but I never got around to porting it. Feel free to check it out though, and even see whether a port is viable. I can at least give you some advice as to how to go about it.

    There’s no built in method to render systems of equations (aligned that is), but you should be able to write such functionality fairly easy on top of the renderer, since it provides measurements as outputs anyway.

    Hope that helps.

    A.

RSS feed for comments on this post. And trackBack URL.

Leave a Reply