在 QML 中嵌入 Latex 的可能性 [英] Possibilities to embed Latex in QML

查看:10
本文介绍了在 QML 中嵌入 Latex 的可能性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 QML(带有 C++ 后端)做一个演示系统,类似于 这个.

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

我希望能够包含一些 Latex 代码以显示一些数学(仅需要最低的 Latex 功能,例如和、分数、超和子带以及数学字体).

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:

  • 使用 latex2e:
  1. 将 Latex 代码编译为 DVI 文档(使用 latex)
  2. 将 DVI 转换为 SVG(使用 dvisvgm)
  3. 在 QML(也支持 SVG)中使用 Image 显示此内容
  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)

  • 使用 MathJax:
  1. 将 Latex 代码封装在一个小的 HTML 文件中 + 包含 MathJax JS 库
  2. 使用 WebKit for QML 显示此内容
  1. Wrap the Latex code in a small HTML file + include the MathJax JS library
  2. Display this using WebKit for QML

  • 自定义解决方案 (C++):
  • Custom solution (C++):
  1. 编写或包含现有的最小 Latex 数学解析器
  2. 用自定义绘画编写一个QDeclarativeItem

还有其他我看不到的解决方案吗?我更喜欢第一个解决方案,因为第二个听起来太重,第三个太难了.

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

我发现数学公式的基线存在以下问题:我希望能够包含内联公式(在段落中).目前,文本段落是使用 QML Text 元素呈现的.是否有可能在具有指定基线的 Text 元素中包含图像(可能使用 HTML img 元素)?另外,如何确定渲染的 Latex 文档的基线?

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?

注意:预渲染 Latex 代码的时间没有问题.我将缓存已经渲染的公式,因此在演示文档中包含的每个公式上调用 latex + dvisvgm 应该没有问题.

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.

还请注意,我使用了预处理器(我不手动编写 QML 代码,而是生成它).所以我不需要 Latex 代码的 QML 元素,但我可以生成一个带有 Image 元素的 QML 代码片段(对于第一个解决方案).这应该可以简化嵌入渲染图像.

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.

在使用内联 Latex 时,我也不需要支持包装公式.(Latex 在编写内联公式时会这样做,但我只使用我不想被包装的小公式.)

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

推荐答案

我觉得这是三个不错的选择,我想不出其他的办法了.

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

听起来您需要将公式与一些文本段落对齐,因此我认为选项 2 是一个很好的方法.

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.

使用 WebKit 组件并不难.我不确定你所说的太重"是什么意思.

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

干杯!

这篇关于在 QML 中嵌入 Latex 的可能性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆