Skip to content

Instantly share code, notes, and snippets.

@janpipek
Last active November 10, 2016 10:59
Show Gist options
  • Save janpipek/820e0546b416df452cbb556d5b302408 to your computer and use it in GitHub Desktop.
Save janpipek/820e0546b416df452cbb556d5b302408 to your computer and use it in GitHub Desktop.
SImplest Qt + Webkit + MathJax
from PyQt4 import QtCore, QtGui, QtWebKit
import sys
app = QtGui.QApplication(sys.argv)
# Define content
head = """
<script type="text/x-mathjax-config">MathJax.Hub.Config({tex2jax: {inlineMath: [['$','$']]}});</script>
<script type="text/javascript" async src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_CHTML"></script>"""
body = "$x + 4$"
html = """
<!DOCTYPE html>
<html>
<head>{0}</head>
<body>{1}<body>
</html>
""".format(head, body)
with open("output.html", "w") as output:
output.write(html)
wk = QtWebKit.QWebView()
wk.setHtml(html)
wk.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment