Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possibilities to embed Latex in QML

I'm doing a presentation system in QML (with C++ backend) similar to this one.

I want to be able to include some Latex code to display some math (only minimum Latex capabilities needed, such as sums, fractions, super- and substript and math fonts).

I see the following possibilities to do so:

  • Using latex2e:
    1. Compile the Latex code to a DVI document (with latex)
    2. Convert the DVI to SVG (with dvisvgm)
    3. Display this using an Image in QML (which also supports SVG)
  • Using MathJax:
    1. Wrap the Latex code in a small HTML file + include the MathJax JS library
    2. Display this using WebKit for QML
  • Custom solution (C++):
    1. Write or include an existing minimal Latex math parser
    2. Write a QDeclarativeItem with custom painting

Is there another solution I don't see? I prefer the first solution as the second sounds too heavy and the third too hard.

I see the following problem with the baseline of the math formula: I want to be able to include inline formulas (within a paragraph). Currently, text paragraphs are renderd using a QML Text element. Is there a possibility to include an image in a Text element (using HTML img element maybe) with a specified baseline? Also, how can I determine the baseline of a rendered Latex document?

Note: The time to pre-render Latex code isn't problematic. I'm going to cache already rendered formulas, so it should be no problem to invoke latex + dvisvgm on every single formula contained in the presentation document.

Also note that I use a preprocessor (I don't write the QML code by hand but generate it). So I don't need a QML element for the Latex code but I can just generate a QML code snippet with an Image element (for the first solution). This should simplify embedding the rendered image.

I also don't need to support wrapping a formula when using inline Latex. (Latex does so when writing inline formulas, but I only use small formulas I don't want to be wrapped anyways.)

like image 655
leemes Avatar asked Nov 26 '12 15:11

leemes


1 Answers

I think those are three good options, and I can't think of any other way to do it.

It sounds like you have a requirement to have the formulas in-line with some textual paragraphs, so for that reason I think option 2 is a good way to do it.

It isn't difficult to use the WebKit component. I'm not sure what you mean by "too heavy".

Cheers!

like image 145
sidewinderguy Avatar answered Oct 06 '22 23:10

sidewinderguy