如何使用PyQt5在Qt中显示数学排版(MathJax,LaTeX等)? [英] How to display mathematical typesetting (MathJax, LaTeX, etc.) in Qt using PyQt5?

查看:1141
本文介绍了如何使用PyQt5在Qt中显示数学排版(MathJax,LaTeX等)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Qt和PyQt5相当陌生,想在GUI窗口中显示数学排版.具体来说,我希望它能够动态更新.我似乎找不到任何有关如何使用PyQt5进行操作的有用信息.

I am fairly new to Qt and PyQt5 and would like to display mathematical typesetting in a GUI window. Specifically, I would like it to be able to update dynamically. I can't seem to find any helpful information on how to do this with PyQt5.

我已经深入研究了如何做到这一点

I've thoroughly researched how to do this

此处找到了一个看似相关的答案,但是没有给出解决方案,并且它实际上没有解决在GUI中显示排版数学的问题.

One seemingly relevant answer is found here, but no solution is given and it doesn't actually address the issue of showing the typeset math in a GUI.

此处找到了另一个看似相关的答案,但使用了PySide(和python 2.7),并给出了荒唐,不必要的复杂和过时的答案.

Another seemingly relevant answer is found here, but uses PySide (and python 2.7) and gives an absurdly and unecessarily complicated and outdated answer.

推荐答案

我想出了如何以一种非常简单的方式做到这一点.下面给出的示例需要Internet连接才能访问MathJax JS模块.

I figured out how to do this in a manner that is quite easy and simple. The example given below requires internet connectivity to access the MathJax JS module.

  1. 首先,导入 QApplication QWebEngineView .

import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView

  • 然后,编写一个包含HTML代码的多行字符串.该代码应导入MathJax javascript模块.然后,写出数学方程式...

  • Then, write a multi-line string containing HTML code. The code should import the MathJax javascript module. Then, write your mathematical equation...

    pageSource = """
                 <html><head>
                 <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML">                     
                 </script></head>
                 <body>
                 <p><mathjax style="font-size:2.3em">$$u = \int_{-\infty}^{\infty}(awesome)\cdot du$$</mathjax></p>
                 </body></html>
                 """
    

  • 最后,实例化一个QApplication,实例化一个QWebEngineView,并将WebEngineView设置为显示新编写的HTML代码:

  • Finally, instantiate a QApplication, instantiate a QWebEngineView, and set the WebEngineView to show your newly written HTML code:

    app = QApplication(sys.argv)
    webView = QWebEngineView()
    webView.setHtml(pageSource)
    

  • 别忘了在WebEngineView上调用show.

  • Don't forget to call show on your WebEngineView.

    webView.show()
    sys.exit(app.exec_())
    

  • 如果要创建不需要互联网连接即可运行MathJax JS文件的应用,只需复制JS模块并将其另存为字符串即可.

    这篇关于如何使用PyQt5在Qt中显示数学排版(MathJax,LaTeX等)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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