JKQTPlotter trunk/v5.0.0
an extensive Qt5+Qt6 Plotter framework (including a feature-richt plotter widget, a speed-optimized, but limited variant and a LaTeX equation renderer!), written fully in C/C++ and without external dependencies
Loading...
Searching...
No Matches
Collaboration diagram for JKQTMathText Rendering Model:

Basics

JKQTMathText parses an input string of mathematical markup (i.e. LaTeX) and in a first step generates a memory representation of the it (cf. Render-Tree Items for JKQTMathText ). Then this memory representation is used to draw the represented math using the renndering API of QPainter.

As an example, we look at the following LaTeX markup, representing the solution to a quadratic equation:

$x_{1/2} = \frac{-b\pm\sqrt{b^2-4ac}}{2a}$

LaTeX itself would render this as follows:

JKQTMathText produces this output:

The memory representation of the expression above looks like this:

Note
The memory representation is independent of the actual math markup language (e.g. LaTeX) which was initially parsed. But of course it is modelled, so the features of the supported markup languages are supported by the memory model.
Also the parser performs optimizations on the tree, e.g. by removing a JKQTMathTextHorizontalListNode if it contains only one entry!

You can see that each node corresponds to a box, if these are overlayed over the rendering:

The box, representing each node, is characterized by its width and height, as well as the ascent (or "baseline-height"):

Linebreaks and Blocks

As described above, JKQTMathText represents the mathematicl markup as a tree of boxes. When calling JKQTMathText::parse() without any additional parameters, the base-node is a JKQTMathTextVerticalListNode that can represent several lines of text. A new line is started when a \\ or \newline command is found. Automatic line breaking is not performed, i.e. each line can possibly become very long, also longer than the available space for drawing! Also lineabreaks are only allowed directly in the current context. You cannot write

.tex
\textbf{line1\\text2}

but have to write

.tex
\textbf{line1}\\
\textbf{line2}

With environment-altering instructions like \bfserie or \it this can be overcome: If you write

.tex
\bf line1\\
line2

both lines are typeset in bold face!