From 816a97f88fdd6844e3a1d26cef6c3f4ef1451dd8 Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Sun, 31 Jul 2022 07:56:13 +0200 Subject: [PATCH] JKQTMathText: added support for flushleft/flushright/center-environments with linebreaks --- doc/dox/whatsnew.dox | 1 + .../jkqtmathtext/jkqtmathtext_begincenter.png | Bin 0 -> 1656 bytes .../jkqtmathtext_beginflushleft.png | Bin 0 -> 1653 bytes .../jkqtmathtext_beginflushright.png | Bin 0 -> 1660 bytes examples/jkqtmathtext_test/testform.cpp | 3 +++ lib/jkqtmathtext/jkqtmathtext.cpp | 16 ++++++++++++++-- lib/jkqtmathtext/jkqtmathtext.h | 8 ++++++++ lib/jkqtmathtext/jkqtmathtexttools.cpp | 4 ++-- 8 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 doc/images/jkqtmathtext/jkqtmathtext_begincenter.png create mode 100644 doc/images/jkqtmathtext/jkqtmathtext_beginflushleft.png create mode 100644 doc/images/jkqtmathtext/jkqtmathtext_beginflushright.png 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 0000000000000000000000000000000000000000..834b683522b2cafc0a67bbdf8d5cfbc2cdc6d0b0 GIT binary patch literal 1656 zcmV-;28a2HP)Px#1ZP1_K>z@;j|==^1poj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(Pi?4VYm7+IVz!WsE&LQ=%`5Y za`2FHRH(Mc3*IS56%|g@p$}A&qZ;8rC7m8sxR$U7YMu{y!p@DVcFlL#zaO6$75oBU z>abs0{#`YU9Mv##RKv(o4I@W2j2zV<`u+VM<&Brc=r}R600000NkvXXu0mjfjnf5D literal 0 HcmV?d00001 diff --git a/doc/images/jkqtmathtext/jkqtmathtext_beginflushright.png b/doc/images/jkqtmathtext/jkqtmathtext_beginflushright.png new file mode 100644 index 0000000000000000000000000000000000000000..a2c4848406926c493fd59455a26f13e16193d458 GIT binary patch literal 1660 zcmV-?27~#DP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D01|XXSaefwW^{L9 za%BKVa%E+1b7*gLUR4MM000H^NklE%u;Fw|%%MgaY&?Jxv;`*GPdXu(a-uj2Gx6A=QaiR=+b3u#IUrEv}B;~LDzHJHyx z4eXnvvyZ{&Aj#kwbm1Dzr$YmJtGO==-fr<-8<`%9YtT>EIp9{)cjKwqa0d*RcrWZ4 zba6lf=&-m%-g=vVAnYi;n;|C9Q{hfe&)Yosv6K& z9GSFF(P7!_ECQBRt%`z@k=t;&2)L7wcV)k?28SglrW z{)&DJTS!runXvXsLDfBxAGu+i+?yh?p<=I1|BFuFpO|4){bTy z*I)qrrsNt-BHbH+4z9seT!Z+Z=HnX7=XYuVkBIH3!$Cmp$L|Y=@%uF3&b(cN zNX+&Y2|5D*J`ExR&cVLFoDvg>>eE*=BgBVDf4Bzw{&I?uU>sd-{av4nbJhvaYKWB5-ho!kSh(uWyB2QgbMsduKzrUGeyB@Q$3GP z>l*BmKu+YmDPdY`y@1u~dp_Y872FKjw%n#_b4Y@0#09~SR*6^wf%sJQString { 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; }