Possibilities to embed Latex in QML

£可爱£侵袭症+ 提交于 2019-12-04 22:56:04

问题


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


回答1:


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!




回答2:


Another option is to use a rich text QML component which also supports images (e.g. TextEdit) rather than Image - then you can place them inline with normal text.



来源:https://stackoverflow.com/questions/13568233/possibilities-to-embed-latex-in-qml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!