Results 1 to 20 of 24

Thread: [MathML] problem displaying a math expression

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default [MathML] problem displaying a math expression

    Hello,

    Despite all my research on the web, I'm still failing to display correctly a math expression using the MathML engine of Qwt. So far, I created a minimalist "testing project", aiming to only display a MathML-formatted text fed in via a text file in the execution directory :
    Qt Code:
    1. // includes erased here for clarity
    2. int main(int argc, char** argv)
    3. {
    4. ifstream ifs("text");
    5. std::string fullText="";
    6. while(!ifs.eof())
    7. {
    8. std::string line;
    9. getline(ifs,line);
    10. fullText += line + "\n";
    11. }
    12.  
    13. QTextCodec::setCodecForCStrings(QTextCodec::codecForName("utf-8")); // Strings in files are UTF-8 encoded
    14. QwtText::setTextEngine(QwtText::MathMLText, new QwtMathMLTextEngine()); // Setting Qwt text engine to MathML
    15.  
    16. QApplication a(argc, argv);
    17.  
    18. QString locale = QLocale::system().name().section('_', 0, 0); // Installs a translator to the user's locale
    19. QTranslator translator;
    20. translator.load(QString("qt_") + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath));
    21. a.installTranslator(&translator);
    22.  
    23. QwtText text(QString(fullText.c_str()), QwtText::MathMLText);
    24. QwtTextLabel* lbl = new QwtTextLabel(text);
    25. lbl->setMinimumHeight(100);
    26. lbl->setMinimumWidth(200);
    27. lbl->show();
    28.  
    29.  
    30. return a.exec();
    31. }
    To copy to clipboard, switch view to plain text mode 

    My "text" file contains a MathML expression directly copy/pasted from Wikipedia, to display the solutions of a quadratic equation, which - I suppose - is syntaxically correct : http://pastebin.com/Nq6gYkvf.
    This code results displaying only letters, not formatted at all, as seen in this screenshot :
    tmp.png

    What am I doing wrong?

    Thanks for your help,
    Tobast.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [MathML] problem displaying a math expression

    The MathML renderer is taken from the former Qt solutions package. I'm not sure how complete and powerful it is myself - but AFAIR the package ( no idea where to find it today ) contained a more advanced formula.

    Uwe

  3. #3
    Join Date
    Apr 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [MathML] problem displaying a math expression

    Hello,

    So, you would say that my implementation is right, but the engine cannot display that formula?

    Thanks, Tobast

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [MathML] problem displaying a math expression

    Your code is o.k. - at least the way how you use Qwt - so I would expect to find the reason in the syntax of the string you are passing. To be honest I have forgotten about the details of this renderer and - as I said before - it would be best to find the example in the Qt solution package.

    But as I'm interested myself I will try to write an example using MathML labels, so that it won't get lost anymore.

    Uwe

  5. #5
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [MathML] problem displaying a math expression

    Tobast/Uwe,

    I was wondering whether any of you guys had managed to get the MathML renderer to work 'properly' using Qwt's MathML engine? FWIW, I was able to get things to work fine using QtMmlWidget (but I have decided to drop it in favour of Qwt).

    Cheers, Alan.

  6. #6
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [MathML] problem displaying a math expression

    FWIW, the MathML code given by Tobast is content MathML while it would seem that Qwt's MathML engine only accepts presentation MathML, which would explain the rendering Tobast got...

  7. #7
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Question Re: [MathML] problem displaying a math expression

    Quote Originally Posted by Uwe View Post
    But as I'm interested myself I will try to write an example using MathML labels, so that it won't get lost anymore.
    Uwe, I have had another look at the MathML renderer in Qwt and spotted several issues with it. I know it has never been fully tested, so it doesn't come as a big surprise to me.

    Still, since you are interested in this issue, I was wondering whether you had had a chance to do anything about it or are planning to do something about it? It's just that I really need the MathML renderer to work in Qwt. So, either I wait for you to fix things or I do it myself (and then send you the code, of course, for possible revision and inclusion in Qwt). Just let me know.

  8. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [MathML] problem displaying a math expression

    Quote Originally Posted by agarny View Post
    Uwe, I have had another look at the MathML renderer in Qwt and spotted several issues with it. I know it has never been fully tested, so it doesn't come as a big surprise to me.
    This code is a leftover from the former Qt solutions package - all I did is to make it available as an option for being used as a QwtText plugin. In fact I don't know much about MathML myself and the quality of this renderer.

    Unfortunately I havn't seen any better option for rendering formulas for Qt so far.

    So, either I wait for you to fix things or I do it myself (and then send you the code, of course, for possible revision and inclusion in Qwt). Just let me know.
    Please go ahead with whatever you believe that improves the implementation.

    Uwe

  9. #9
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [MathML] problem displaying a math expression

    Quote Originally Posted by Uwe View Post
    Please go ahead with whatever you believe that improves the implementation.
    Ok, I shall then. I just wanted to make sure that you were not already working on it.

  10. #10
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [MathML] problem displaying a math expression

    Ok, I had a bit of time yesterday to look into it and I now have Qwt's MathML renderer working with QwtTextLabel in a way which is similar to what could be done with the now discontinued QtMmlWidget.

    You can find 'my' version of Qwt's MathML renderer at https://github.com/opencor/opencor/t...engines/mathml. I 'cleaned' the code a bit, but nothing major.

    I have tried the renderer with some presentation MathML code and it's working fine. At least, as fine as QtMmlWidget. Indeed, I noticed some issues with the renderer itself (see https://github.com/opencor/opencor/issues/225). I will try to fix them when I have a bit more time.

  11. #11
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [MathML] problem displaying a math expression

    I had a quick look at your changes and IMHO it seems to me like you are working around issues that have to do with rounding errors because of an integer based implementation. Your patches somehow fix these problems by adding some margins here changing a factor there. This might be a solution when using a formula with QwtTextLabel, but when scaling comes into the game ( f.e. a formula on the canvas painted with QwtPlotRenderer to PDF ) your approach will not be enough.

    IMO a more promising approach would be to modify the renderer being completely floating point based ?

    Uwe

  12. #12
    Join Date
    Mar 2010
    Posts
    319
    Thanks
    1
    Thanked 14 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [MathML] problem displaying a math expression

    I must confess that, so far, I have been working on getting the original QtMmlWidget's MathML renderer to work within Qwt (which is now the case). From there, I have been working on fixing some issues I have found with the original MathML renderer (still working on it).

    This being said, I agree that a floating point based approach would be better. Maybe I should go through the code and, who knows, it might mean I don't have 'patch' certain things. Then again, there are some factors that were just plain wrong, so I had no choice but to 'fix' them. For example, say that you have x with i as a sub-script and j as a super-script. In this case, the MathML render uses g_script_size_multiplier to scale those scripts. However, the original value of g_script_size_multiplier is such that i and j would always overlap, hence I modified that value to 0.5 (from 0.7071) and as expected now everything is fine.

    Anyway, it's still very much work in progress, but I am hoping to be done with it within the next few days. (I can't afford to spend too much time on this.) From there, I leave it to you to incorporate 'my' version of the MathML render to Qwt or not. What is certain is that you are better placed than I am to test the renderer for use within Qwt (my use of Qwt is somewhat limited).

  13. #13
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: [MathML] problem displaying a math expression

    What about starting this way: I will set up a test application ( in qwt/playground/mathml ), where a MathML text is displayed in the center of a widget using the MathML renderer in its paint event. It will be using a transformation, that can be modified by the mouse ( scale factor + maybe a rotation ). Your contribution would be to set up a reasonable collection of MathML formulas, that can be loaded into the application.

    Then we can see easily where the renderer needs polishing.

    Uwe

Similar Threads

  1. Replies: 3
    Last Post: 22nd August 2013, 13:57
  2. Problem with regular expression not working
    By Suppaman in forum Qt Programming
    Replies: 6
    Last Post: 9th April 2013, 23:40
  3. Support of MathML in Qt
    By oficjalne100 in forum Newbie
    Replies: 0
    Last Post: 28th September 2011, 13:18
  4. Support of MathML in Qt
    By oficjalne100 in forum General Discussion
    Replies: 0
    Last Post: 25th September 2011, 18:24
  5. Regular Expression Problem
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 27th February 2009, 10:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.