Skip to content

Instantly share code, notes, and snippets.

@mitya57
Created August 28, 2012 12:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitya57/3497662 to your computer and use it in GitHub Desktop.
Save mitya57/3497662 to your computer and use it in GitHub Desktop.
QtWebKit + MathJax test
#!/usr/bin/env python
import sys
from PyQt4.QtCore import QFile, QFileInfo, QTextStream, QUrl
from PyQt4.QtGui import QApplication
from PyQt4.QtWebKit import QWebView
pageSource = """<html><head>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
</head><body>
<p><mathjax>$$
\imath
$$</mathjax></p>
</body></html>"""
app = QApplication(sys.argv)
tempFile = QFile('mathjax.html')
tempFile.open(QFile.WriteOnly)
stream = QTextStream(tempFile)
stream << pageSource
tempFile.close()
fileUrl = QUrl.fromLocalFile(QFileInfo(tempFile).canonicalFilePath())
webView = QWebView()
webView.load(fileUrl)
webView.show()
sys.exit(app.exec_())
@AlekseyCherepanov
Copy link

I just found this sample through Google. I had problems modifying it to get other LaTeX text work (particularly I got rac instead of fraction using frac command). The solution for my problem is to add r before string constant with html, otherwise backslashes are active (though it does not affect this example).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment