diff --git a/doc/dox/whatsnew.dox b/doc/dox/whatsnew.dox
index 43e9ada588..f9dca116c4 100644
--- a/doc/dox/whatsnew.dox
+++ b/doc/dox/whatsnew.dox
@@ -70,6 +70,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
NEW: added \c \\unicode{HEX} and \c \\utfeight{HEX} instruction to draw unicide characters by code
NEW: JKQTMathTextVerticalListNode allows to typeset a vertical list of lines
NEW: added \c \\substack[lcr]{...\\\\...} , \c \\lsubstack{...\\\\...} , \c \\rsubstack{...\\\\...} instructions
+ NEW: added support for flushleft/flushright/center-environments with linebreaks
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_begincenter.png b/doc/images/jkqtmathtext/jkqtmathtext_begincenter.png
new file mode 100644
index 0000000000..834b683522
Binary files /dev/null and b/doc/images/jkqtmathtext/jkqtmathtext_begincenter.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_beginflushleft.png b/doc/images/jkqtmathtext/jkqtmathtext_beginflushleft.png
new file mode 100644
index 0000000000..9e91152626
Binary files /dev/null and b/doc/images/jkqtmathtext/jkqtmathtext_beginflushleft.png differ
diff --git a/doc/images/jkqtmathtext/jkqtmathtext_beginflushright.png b/doc/images/jkqtmathtext/jkqtmathtext_beginflushright.png
new file mode 100644
index 0000000000..a2c4848406
Binary files /dev/null and b/doc/images/jkqtmathtext/jkqtmathtext_beginflushright.png differ
diff --git a/examples/jkqtmathtext_test/testform.cpp b/examples/jkqtmathtext_test/testform.cpp
index f01cb783dc..d02389b5e5 100644
--- a/examples/jkqtmathtext_test/testform.cpp
+++ b/examples/jkqtmathtext_test/testform.cpp
@@ -72,6 +72,9 @@ TestForm::TestForm(QWidget *parent) :
const auto mathDecoExample=[](const QString& deco)->QString { return "\\"+deco+"{x}\\"+deco+"{i}\\"+deco+"{X}\\"+deco+"{\\psi}\\"+deco+"{abc}"; };
ui->cmbTestset->addItem("decoration: math", "$"+mathDecoExample("vec")+" -- "+mathDecoExample("grave")+" -- "+mathDecoExample("acute")+" -- "+mathDecoExample("dot")+" -- "+mathDecoExample("ddot")+" -- "+mathDecoExample("ocirc")+" -- "+mathDecoExample("overline")+" -- "+mathDecoExample("underline")+" -- "+mathDecoExample("hat")+" -- "+mathDecoExample("widehat")+" -- "+mathDecoExample("check")+" -- "+mathDecoExample("widecheck")+" -- "+mathDecoExample("breve")+" -- "+mathDecoExample("tilde")+" -- "+mathDecoExample("widetilde")+" -- "+mathDecoExample("uul")+" -- "+mathDecoExample("ool")+" -- "+mathDecoExample("bar")+" -- "+mathDecoExample("arrow")+" -- "+mathDecoExample("cancel")+" -- "+mathDecoExample("bcancel")+" -- "+mathDecoExample("xcancel")+" -- "+mathDecoExample("sout")+"$");
ui->cmbTestset->addItem("decoration: text", "Text \\ul{underlined Text Equator} -- \\ol{overlined Text Equator} -- \\sout{striked out Text Equator} -- \\cancel{canceled out Text Equator} -- \\bcancel{b-canceled out Text Equator} -- \\xcancel{x-canceled out Text Equator}");
+ ui->cmbTestset->addItem("text: flushleft", "\\begin{flushleft}text\\\\\\textbf{2^{nd} line of text}\\\\last \\textit{line!} $\\frac{1}{2}$\\end{flushleft}");
+ ui->cmbTestset->addItem("text: flushright", "\\begin{flushright}text\\\\\\textbf{2^{nd} line of text}\\\\last \\textit{line!} $\\frac{1}{2}$\\end{flushright}");
+ ui->cmbTestset->addItem("text: center", "\\begin{center}text\\\\\\textbf{2^{nd} line of text}\\\\last \\textit{line!} $\\frac{1}{2}$\\end{center}");
ui->cmbTestset->addItem("mathtest", "This is normal text: $this is math:\\langle r^2(\\tau)\\rangle=\\left\\langle (\\vec{r}(t)-\\vec{r}(t+\\tau) )^2\\right\\rangle\\ \\ \\ g(\\tau)=\\frac{1}{N}\\cdot\\left(1+\\frac{2}{3}\\frac{\\langle r^2(\\tau)\\rangle}{w_{xy}^2}\\right)^{-1} \\lfloor\\rfloor\\lceil\\rceil\\langle\\rangle\\left\\{\\vec{a}\\left|\\|\\vec{a}\\|_2\\geq2\\right.\\right\\} \\vec{r}\\vec{R}\\frac{\\sqrt{\\sqrt{\\sqrt{\\sum_{i=0}^\\infty \\hat{i}^2}+y^\\alpha}+1}}{\\dot{v}\\equiv\\ddot{r}}\\argmin_{\\vec{k}}\\sum_{\\sqrt{i}=0}^{N}\\int_{x_0}^{x_1}\\left(\\left(\\left(x\\right)\\right)\\right)\\underbrace{\\left[\\left\\{\\frac{\\partial f}{\\partial x}\\right\\}\\cdot\\frac{1}{2}\\right]}{\\text{underbraced text \\hbar}}\\cdots\\frac{\\sqrt{\\sum_{i=0}^2 \\hat{i}^2}+y^\\alpha}{\\dot{v}\\equiv\\ddot{r}}, \\hat{t}\\hat{T} \\overbrace{\\left|\\sqrt{x\\cdot Y}\\right|}{\\propto\\bbN\\circ\\bbZ} \\left<\\arrow{x(\\tau)}\\cdot\\vec{R}(t+\\bar{\\tau})\\right> \\alpha\\beta\\gamma\\delta\\epsilon\\Gamma\\Delta\\Theta\\Omega \\left\\_\\left~\\cbrt{\\hbar\\omega}\\right~\\right\\_$");
ui->cmbTestset->addItem("math: upper/lower parantheses test:", "$\\text{bblabla} \\frac{1}{2}\\cdot\\left(\\frac{1}{\\mathrm{e}^x+\\mathrm{e}^{-x}}\\right)\\cdot\\left(\\frac{1}{\\frac{1+2}{5+x}}\\right)\\cdot\\left(\\frac{1}{\\exp\\left[-\\frac{y^2}{\\sqrt{x}}\\right]\\cdot\\exp\\left[-\\frac{1}{\\frac{1}{2}}\\right]}\\right) $");
ui->cmbTestset->addItem("math: ACF test", "$g_{rg}^{ab}(\\tau)=\\frac{1}{N}\\cdot\\left(1+\\frac{2}{3}\\frac{\\langle r^2(\\tau)\\rangle}{w_{xy}^2}\\right)^{-1}\\cdot\\left(1+\\frac{2}{3}\\frac{\\langle r^2(\\tau)\\rangle}{w_{xy}^2}\\right)^{-\\frac{1}{2}}$");
diff --git a/lib/jkqtmathtext/jkqtmathtext.cpp b/lib/jkqtmathtext/jkqtmathtext.cpp
index a6b1113929..9bc550deca 100644
--- a/lib/jkqtmathtext/jkqtmathtext.cpp
+++ b/lib/jkqtmathtext/jkqtmathtext.cpp
@@ -1491,8 +1491,9 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
if (nl->hasChildren()) nl->getLastChild()->setSubSuperscriptAboveBelowNode(false);
} else if (currentInstructionName=="begin") {
if (getToken()==MTTopenbrace && getToken()==MTTtext) {
- QString envname=currentTokenName;
- while (currentToken!=MTTclosebrace) getToken(); // find closing brace '}' after '\\begin{name'
+ const QString envname=currentTokenName;
+ getToken();
+ if (currentToken!=MTTclosebrace) error_list.append(tr("error @ ch. %1: didn't find '}' after environment start '\\begin{%2'").arg(currentTokenID).arg(envname)); // find closing brace '}' after '\\begin{name'
if (envname=="matrix" || envname=="array" || envname=="aligned" || envname=="align" || envname=="cases" || envname=="pmatrix"|| envname=="bmatrix"|| envname=="Bmatrix"|| envname=="vmatrix"|| envname=="Vmatrix") {
QVector< QVector > items;
//int lines=0;
@@ -1522,6 +1523,17 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
else if (envname=="Vmatrix") nl->addChild(new JKQTMathTextBraceNode(this, MTBTDoubleLine, MTBTDoubleLine, new JKQTMathTextMatrixNode(this, items)));
else nl->addChild(new JKQTMathTextMatrixNode(this, items));
//std::cout<<" creating matrix-node ... done!\n";
+ } else if (envname=="center" || envname=="document" || envname=="flushleft" || envname=="flushright") {
+ JKQTMathTextHorizontalAlignment alignment=MTHALeft;
+ if (envname=="document") alignment=MTHALeft;
+ else alignment=String2JKQTMathTextHorizontalAlignment(envname);
+ JKQTMathTextVerticalListNode* vlist = new JKQTMathTextVerticalListNode(this, alignment, 1.0, JKQTMathTextVerticalListNode::SMDefault, MTVOFirstLine );
+ nl->addChild(vlist);
+ bool first=true;
+ while (first || currentToken==MTTinstructionNewline) {
+ vlist->addChild(parseLatexString(true, MTBTAny, envname));
+ first=false;
+ }
} else {
error_list.append(tr("error @ ch. %1: unknown environment '%2'").arg(currentTokenID).arg(envname));
}
diff --git a/lib/jkqtmathtext/jkqtmathtext.h b/lib/jkqtmathtext/jkqtmathtext.h
index 4b14506a76..d147d1b96f 100644
--- a/lib/jkqtmathtext/jkqtmathtext.h
+++ b/lib/jkqtmathtext/jkqtmathtext.h
@@ -202,6 +202,14 @@ class JKQTMathTextNode; // forward
- $\\rsubstack{...\\\\...}$
\image html jkqtmathtext/jkqtmathtext_rsubstack.png
.
+ \subsection JKQTMathTextSuppoertedLaTeXTextAlignment Environments with Multi-line text
+ Several environments are supported that allow to layout text with linebreaks and different alignemnts:
+ - $\\begin{document} ... \\\\ ... \\end{document}$
\image html jkqtmathtext/jkqtmathtext_beginflushleft.png
+ - $\\begin{flushleft} ... \\\\ ... \\end{flushleft}$
\image html jkqtmathtext/jkqtmathtext_beginflushleft.png
+ - $\\begin{flushright} ... \\\\ ... \\end{flushright}$
\image html jkqtmathtext/jkqtmathtext_beginflushright.png
+ - $\\begin{center} ... \\\\ ... \\end{center}$
\image html jkqtmathtext/jkqtmathtext_begincenter.png
+ .
+
\section JKQTMathTextSuppoertedFonts Font Handling
Several fonts are defined as properties to the class:
diff --git a/lib/jkqtmathtext/jkqtmathtexttools.cpp b/lib/jkqtmathtext/jkqtmathtexttools.cpp
index acf6d62ff1..5386b3317f 100644
--- a/lib/jkqtmathtext/jkqtmathtexttools.cpp
+++ b/lib/jkqtmathtext/jkqtmathtexttools.cpp
@@ -781,8 +781,8 @@ QString JKQTMathTextHorizontalAlignment2String(JKQTMathTextHorizontalAlignment t
JKQTMathTextHorizontalAlignment String2JKQTMathTextHorizontalAlignment(QString tokenName)
{
tokenName=tokenName.toLower().trimmed();
- if (tokenName=="l" || tokenName=="left") return MTHALeft;
- if (tokenName=="r" || tokenName=="right") return MTHARight;
+ if (tokenName=="l" || tokenName=="left" || tokenName=="flushleft") return MTHALeft;
+ if (tokenName=="r" || tokenName=="right" || tokenName=="flushright") return MTHARight;
if (tokenName=="c" || tokenName=="center" || tokenName=="centered") return MTHACentered;
return MTHACentered;
}