2019-01-20 17:49:29 +08:00
# Example (JKQTMathText): A simple usage example {#JKQTMathTextSimpleExample}
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.
2018-12-29 00:46:47 +08:00
This project (see `./examples/jkqtmathtext_simpletest/` ) simply creates a QLabel (as a new window) that displays a rendered LaTeX equation (here the time-dependent Schrödinger equation).
NEW/BREAKING: provide general targets JKQTPlotter5/6::JKQTPlotter5/6, JKQTPlotter5/6::JKQTMathText5/6, ... which are independent of the type of build (shared/static)
NEW/BREAKING: refactor CMake-Code, so static/dynamic switch is done via <code>BUILD_SHARED_LIBS</code>, which retires <code>JKQtPlotter_BUILD_STATIC_LIBS</code>, <code>JKQtPlotter_BUILD_SHARED_LIBS</code> and removes the capability to build static and shared libraries in one location (fixes issue #104)
NEW: prepareed library for CMake's <a href="https://cmake.org/cmake/help/latest/module/FetchContent.html">FetchContent</a>-API
NEW: the different sub-libraries JKQTPlotter, JKQTFastPlotter (DEPRECATED), JKQTMath, JKQTMathText can be activated/deactivated with CMake options JKQtPlotter_BUILD_LIB_JKQTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTFASTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTMATHTEXT, JKQtPlotter_BUILD_LIB_JKQTMATH
2024-01-16 20:05:52 +08:00
The source code of the main application is (see [`jkqtmathtext_simpletest.cpp` ](https://github.com/jkriege2/JKQtPlotter/tree/master/examples/jkqtmathtext_simpletest/jkqtmathtext_simpletest.cpp ):
2019-01-19 16:40:52 +08:00
```.cpp
2018-12-29 00:46:47 +08:00
#include <QApplication>
#include <QLabel>
#include <QPixmap>
2022-06-08 21:38:26 +08:00
#include "jkqtmathtext/jkqtmathtextlabel.h"
2018-12-29 00:46:47 +08:00
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;
2019-01-20 17:49:29 +08:00
// 2. now we create a JKQTMathText object.
// Also we configure the JKQTMathText to use the XITS fonts that
2018-12-29 00:46:47 +08:00
// were included in the *.pro-file
2019-01-20 17:49:29 +08:00
JKQTMathText mathText;
2018-12-29 00:46:47 +08:00
mathText.useXITS();
2019-01-26 03:16:04 +08:00
mathText.setFontSize(20);
2018-12-29 00:46:47 +08:00
// 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:
2019-02-03 22:54:41 +08:00
![jkqtmathtext_simpletest ](https://raw.githubusercontent.com/jkriege2/JKQtPlotter/master/screenshots/jkqtmathtext_simpletest.png )
2018-12-29 00:46:47 +08:00