mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 01:51:49 +08:00
added simple JKQTmathText example
This commit is contained in:
parent
ee56add165
commit
f6a6fb763b
67
README.md
67
README.md
@ -275,8 +275,75 @@ Scatter Plots can have symbols where the shape/color/size is parametrized by a d
|
||||
![LogLog Plot](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/screen_parmetrizedplots_datatable.png)
|
||||
|
||||
|
||||
|
||||
|
||||
#JKQTmathText
|
||||
JKQTmathText is a hand-written LaTeX-renderer for Qt (implemented in native C++, using Qt). It supports a large set of standard LaTeX markup and can render it to a QPainter.
|
||||
##A simple usage example
|
||||
This project (see `./test/jkqtmathtext_simpletest/`) simply creates a QLabel (as a new window) that displays a rendered LaTeX equation (here the time-dependent Schrödinger equation).
|
||||
The QMake project looks like this (see `./test/jkqtmathtext_simpletest/jkqtmathtext_simpletest.pro`):
|
||||
```qmake
|
||||
# include JKQTmathText source-code, including the open-source XITS fonts
|
||||
include(../../jkqtmathtext_with_xits.pri)
|
||||
SOURCES += jkqtmathtext_simpletest.cpp
|
||||
|
||||
# if you don't want to use the XITS fonts, use this line (and uncomment the
|
||||
# last two line!):
|
||||
#include(../../jkqtmathtext.pri)
|
||||
|
||||
CONFIG += qt
|
||||
QT += core gui
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
|
||||
|
||||
TARGET = jkqtmathtext_simpletest
|
||||
```
|
||||
And the soruce code of the main application is (see `./test/jkqtmathtext_simpletest/jkqtmathtext_simpletest.cpp`):
|
||||
```c++
|
||||
#include <QApplication>
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#include "jkqtmathtext.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
// we use a simple label to display the math text
|
||||
QLabel lab;
|
||||
|
||||
// 1. we will paint into a QPixmap
|
||||
QPixmap pix(600,400);
|
||||
pix.fill(QColor("white"));
|
||||
QPainter painter;
|
||||
|
||||
// 2. now we create a JKQTmathText object.
|
||||
// Also we configure the JKQTmathText to use the XITS fonts that
|
||||
// were included in the *.pro-file
|
||||
JKQTmathText mathText;
|
||||
mathText.useXITS();
|
||||
mathText.set_fontSize(20);
|
||||
|
||||
// 3. now we parse some LaTeX code (the Schroedinger's equation), so
|
||||
// we can draw it onto the QPixmap in the next step
|
||||
mathText.parse("$\\left[-\\frac{\\hbar^2}{2m}\\frac{\\partial^2}{\\partial x^2}+V(x)\\right]\\Psi(x)=\\mathrm{i}\\hbar\\frac{\\partial}{\\partial t}\\Psi(x)$");
|
||||
|
||||
// 3. here we do the painting
|
||||
painter.begin(&pix);
|
||||
mathText.draw(painter, Qt::AlignCenter, QRectF(0,0,pix.width(), pix.height()), false);
|
||||
painter.end();
|
||||
|
||||
// now we display and resize the label as a window
|
||||
lab.setPixmap(pix);
|
||||
lab.show();
|
||||
lab.resize(600,400);
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
```
|
||||
The result looks like this:
|
||||
![jkqtmathtext_simpletest](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtmathtext_simpletest.png)
|
||||
|
||||
##Screenshots
|
||||
![LatexRender](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/mscreen_schroedinger.png)
|
||||
![LatexRender](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/mscreen_rottaion.png)
|
||||
![LatexRender](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/mscreen_maxwell.png)
|
||||
|
BIN
screenshots/jkqtmathtext_simpletest.png
Normal file
BIN
screenshots/jkqtmathtext_simpletest.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
40
test/jkqtmathtext_simpletest/jkqtmathtext_simpletest.cpp
Normal file
40
test/jkqtmathtext_simpletest/jkqtmathtext_simpletest.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include <QApplication>
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#include "jkqtmathtext.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
// we use a simple label to display the math text
|
||||
QLabel lab;
|
||||
|
||||
// 1. we will paint into a QPixmap
|
||||
QPixmap pix(600,400);
|
||||
pix.fill(QColor("white"));
|
||||
QPainter painter;
|
||||
|
||||
// 2. now we create a JKQTmathText object.
|
||||
// Also we configure the JKQTmathText to use the XITS fonts that
|
||||
// were included in the *.pro-file
|
||||
JKQTmathText mathText;
|
||||
mathText.useXITS();
|
||||
mathText.set_fontSize(20);
|
||||
|
||||
// 3. now we parse some LaTeX code (the Schroedinger's equation), so
|
||||
// we can draw it onto the QPixmap in the next step
|
||||
mathText.parse("$\\left[-\\frac{\\hbar^2}{2m}\\frac{\\partial^2}{\\partial x^2}+V(x)\\right]\\Psi(x)=\\mathrm{i}\\hbar\\frac{\\partial}{\\partial t}\\Psi(x)$");
|
||||
|
||||
// 3. here we do the painting
|
||||
painter.begin(&pix);
|
||||
mathText.draw(painter, Qt::AlignCenter, QRectF(0,0,pix.width(), pix.height()), false);
|
||||
painter.end();
|
||||
|
||||
// now we display and resize the label as a window
|
||||
lab.setPixmap(pix);
|
||||
lab.show();
|
||||
lab.resize(600,400);
|
||||
|
||||
return app.exec();
|
||||
}
|
10
test/jkqtmathtext_simpletest/jkqtmathtext_simpletest.pro
Normal file
10
test/jkqtmathtext_simpletest/jkqtmathtext_simpletest.pro
Normal file
@ -0,0 +1,10 @@
|
||||
include(../../jkqtmathtext_with_xits.pri)
|
||||
SOURCES += jkqtmathtext_simpletest.cpp
|
||||
|
||||
CONFIG += qt
|
||||
QT += core gui
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
|
||||
|
||||
TARGET = jkqtmathtext_simpletest
|
||||
|
||||
|
@ -107,7 +107,7 @@ TestForm::TestForm(QWidget *parent) :
|
||||
ui->cmbTestset->addItem("lim, sum ...", "$\\lim_{x\\to\\infty} f(x) = \\binom{k}{r} + \\frac{a}{b} \\sum_{n=1}^\\infty a_n + \\displaystyle{ \\left\\{ \\frac{1}{13} \\sum_{n=1}^\\infty b_n \\right\\} }.$");
|
||||
ui->cmbTestset->addItem("array test", "$f(x) := \\left\\{\\begin{array} x^2 \\sin \\frac{1}{x} & \\textrm{if } x \\ne 0, \\\\ 0 & \\textrm{if } x = 0 . \\end{array}\\right.$");
|
||||
ui->cmbTestset->addItem("Schwinger-Dyson", "$\\left\\langle\\psi\\left|\\mathcal{T}\\{F \\phi^j\\}\\right|\\psi\\right\\rangle=\\left\\langle\\psi\\left|\\mathcal{T}\\{iF_{,i}D^{ij}-FS_{int,i}D^{ij}\\}\\right|\\psi\\right\\rangle.$");
|
||||
ui->cmbTestset->addItem(QLatin1String("Schrödinger's equation"), "$\\left[-\\frac{\\hbar^2}{-2m}\\frac{\\partial^2}{\\partial x^2}+V\\right]\\Psi(x)=i\\hbar\\frac{\\partial}{\\partial t}\\Psi(x)$");
|
||||
ui->cmbTestset->addItem(QLatin1String("Schrödinger's equation"), "$\\left[-\\frac{\\hbar^2}{2m}\\frac{\\partial^2}{\\partial x^2}+V\\right]\\Psi(x)=\\mathrm{i}\\hbar\\frac{\\partial}{\\partial t}\\Psi(x)$");
|
||||
ui->cmbTestset->addItem("Cauchy-Schwarz inequality", "$\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)$");
|
||||
ui->cmbTestset->addItem("Maxwell's equations", "$\\begin{aligned}\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac{1}{c}\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\ \\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac{1}{c}\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\\nabla \\cdot \\vec{\\mathbf{B}} & = 0 \\end{aligned}$");
|
||||
//ui->cmbTestset->addItem("", "$$");
|
||||
|
Loading…
Reference in New Issue
Block a user