Created
August 28, 2012 12:31
-
-
Save mitya57/3497662 to your computer and use it in GitHub Desktop.
QtWebKit + MathJax test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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).