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.

30 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.

  20. Rakesh Bisht says:

    Hi Alex,

    I am currently using WPF latex library.Till now it has been working great in my project.
    I have a requirement to show words “Current Value=” in a formula.
    I mean a space between the two words, could you please help me with writing the script that would work with the WPF mathtex libary.

    Thanks in advance,
    Rakesh

  21. Noldorin says:

    Hi Rakesh. Isn’t the \text{...} macro implemented in the library? I forget, but try it out and let me know. If not check some of the bug reports; I think someone may have submitted a patch for it there! Good luck.

  22. Rakesh Bisht says:

    Hi Alex,

    Thanks for your advice.
    I was able to workout the whitespace using two patches that were there in the bugs list of WPF-Math.
    Now one last help is required, can you please guide me what to do for a newline command implementation?

    Thanks
    Rakesh

  23. Noldorin says:

    Hi Rakesh. For a \newline command or such, I would suggest creating a vbox around multiple hboxes (which represent each line). You may want to add a conditional to check if the top-level object is already a vbox, otherwise add one at root. Let me know how that goes.

  24. Bisht says:

    Hello Noldorin,

    I am using Bazaar CVS to get the project but getting an error as below:

    Run command: bzr get http://noldorin.com/repos/wpf-math/
    bzr: ERROR: Connection error: while sending OPTIONS /repos/wpf-math/: [Errno 10013] An attempt was made to access a socket in a way forbidden by its access permissions.

    Please help.

    Thanks,
    B

  25. Rakesh Bisht says:

    Hi Alex,

    Instead of implementing newline command, I found it easier to create a collectionn of single line formulaes and then did WPF binding to a StackPanel.
    Thanks for your support,
    I request you if you could continue and go ahead with a release version.
    Because WPF Math library is really helpful for someone for rendering tex formulaes.
    And also there are not much alternatives available.
    Thanks a lot,
    Cheers,
    Rakesh Bisht

  26. apr says:

    Hello,

    Amazing effort so far. I was wondering if your efforts regarding WPF-math and or the whole Tex project are postponed indefinely or do you still have a plan to pick up again? Either way, thanks for sharing your work.

  27. Noldorin says:

    Hi apr,

    Glad you’re finding it of use. I do in fact have plans to pick up this project again, but not in the same form. I’m planning on taking the rendering logic from the excellent MathJax project and porting this to something usable within .NET. Follow the blog and I will hopefully have some news for you before long!

  28. Bas says:

    Hi,

    I’m getting:
    A first chance exception of type ‘System.Collections.Generic.KeyNotFoundException’ occurred in mscorlib.dll
    A first chance exception of type ‘WpfMath.FormulaNotFoundException’ occurred in WpfMath.dll

    ..Seems like the culture-problem from above (I’m from Europe decimal-comma).
    I branched from Launchpad, but it seems to be an older version (june 2010)?
    Using http://noldorin.com/repos/wpf-math/ I get this error:
    Invalid http response for http://noldorin.com/repos/wpf-math/info/refs?service=git-upload-pack: Unable to handle http code 500: Internal Server Error

  29. Noldorin says:

    Apologies; this was a problem with the server web configuration… it is being very strange, but you can use the alternate URL now!

  30. Victor says:

    Hello.

    I was also trying to get latest version but I’m getting this error:

    Run command: bzr branch http://noldorin.com/repos/wpf-math
    bzr: ERROR: Invalid http response for http://noldorin.com/repos/wpf-math/info/refs?service=git-upload-pack: Unable to handle http code 500: Internal Server Error

    Is there any other place that I could get the code?

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

Leave a Reply


%d bloggers like this: