FIX: JKQTMathText: rendering of matrices, when onle one row or column or a single value are present

This commit is contained in:
jkriege2 2024-02-14 13:55:12 +01:00
parent 924eb5fe91
commit 819ac7f9fc
4 changed files with 28 additions and 19 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 980 B

View File

@ -5,6 +5,9 @@ $\mat{M}_1=\begin{matrix}a&b&...\\ c&d&...\end{matrix}\ \ \ \ \ \ \mat{M}_2=\lef
jkqtmathtext_bmatrix.png jkqtmathtext_bmatrix.png
$\begin{bmatrix}a&b&...\\ c&d&...\end{bmatrix}$ $\begin{bmatrix}a&b&...\\ c&d&...\end{bmatrix}$
--- ---
jkqtmathtext_bmatrix_1col.png
$\begin{bmatrix}a\\b\\...\end{bmatrix}$
---
jkqtmathtext_bbmatrix.png jkqtmathtext_bbmatrix.png
$\begin{Bmatrix}a&b&...\\ c&d&...\end{Bmatrix}$ $\begin{Bmatrix}a&b&...\\ c&d&...\end{Bmatrix}$
--- ---
@ -45,3 +48,6 @@ $\mat{M}_\cdot=\begin{array}{l:ll}
\beta & b & \ldots \\ \beta & b & \ldots \\
\vdots & \vdots & \ddots \\ \vdots & \vdots & \ddots \\
\end{array}\right)$ \end{array}\right)$
---
jkqtmathtext_array_1col.png
$\vec{c}=\left(\begin{array}{l} \alpha \\ b \\ ... \end{array}\right)$

View File

@ -885,10 +885,17 @@ JKQTMathTextNode* JKQTMathTextLatexParser::parseLatexString(bool get, JKQTMathTe
bool firstLine=true; bool firstLine=true;
QVector<JKQTMathTextNode*> line; QVector<JKQTMathTextNode*> line;
qsizetype colCount=0; qsizetype colCount=0;
//std::cout<<"found \\begin{matrix}\n"; //qDebug()<<"start "<<envname;
while (first || currentToken==MTTampersand || currentToken==MTTinstructionNewline) { while (first || currentToken==MTTampersand || currentToken==MTTinstructionNewline) {
while (getToken()==MTTwhitespace) ; // eat whitespace //qDebug()<<" - START: "<<tokenType2String(currentToken)<<" first="<<first;
JKQTMathTextNode* it=simplifyAndTrimJKQTMathTextNode(parseLatexString(false, MTBTAny, envname)); while (getToken()==MTTwhitespace) ; // eat one token + whitespace
//qDebug()<<" - eatWS: "<<tokenType2String(currentToken)<<" first="<<first;
JKQTMathTextNode* it=nullptr;
if (currentToken==MTTampersand || currentToken==MTTinstructionNewline) {
it=new JKQTMathTextNoopNode(parentMathText);
} else {
it=simplifyAndTrimJKQTMathTextNode(parseLatexString(false, MTBTAny, envname));
}
if (firstLine) { if (firstLine) {
if (lastMatrixLineCommandCount.value("hline",0)==1) { if (lastMatrixLineCommandCount.value("hline",0)==1) {
matrixNode->setTopLine(JKQTMathTextMatrixNode::LTline); matrixNode->setTopLine(JKQTMathTextMatrixNode::LTline);
@ -914,26 +921,21 @@ JKQTMathTextNode* JKQTMathTextLatexParser::parseLatexString(bool get, JKQTMathTe
matrixNode->setRowBottomLine(items.size()-1, JKQTMathTextMatrixNode::LTdoubleDashed); matrixNode->setRowBottomLine(items.size()-1, JKQTMathTextMatrixNode::LTdoubleDashed);
} }
} }
//qDebug()<<" - before append CurrenTinstruction="<<tokenType2String(currentToken)<<", currentTokenName="<<currentTokenName;
if (currentToken==MTTampersand) { if (currentToken==MTTampersand) {
//std::cout<<" appending item\n"; //qDebug()<<" - appending item "<<it->getTypeName();
line.append(it); line.append(it);
} else { } else {
//std::cout<<" appending item and line with "<<line.size()<<" items.\n"; //qDebug()<<" - appending item "<<it->getTypeName()<<" to line with "<<line.size()<<" items.";
if (currentToken==MTTinstructionEnd) {
JKQTMathTextMultiChildNode* mnc=dynamic_cast<JKQTMathTextMultiChildNode*>(it);
if (mnc && mnc->childCount()>0) {
line.append(it); line.append(it);
} else {
line.append(it); if (currentToken==MTTinstructionNewline || (currentToken==MTTinstructionEnd && currentTokenName==envname) || line.size()>0) {
}
} else {
line.append(it);
}
if (currentToken==MTTinstructionNewline || line.size()>0) {
colCount=qMax(colCount, static_cast<qsizetype>(line.size())); colCount=qMax(colCount, static_cast<qsizetype>(line.size()));
if (line.size()==0 || (line.size()>1 && static_cast<qsizetype>(line.size())==colCount)) { //qDebug()<<" - colCount="<<colCount;
if (line.size()==0 || (line.size()>=1 && static_cast<qsizetype>(line.size())==colCount)) {
items.append(line); items.append(line);
} else if (line.size()>1 && static_cast<qsizetype>(line.size())!=colCount) { //qDebug()<<" - appending line with "<<line.size()<<" items. items.size now "<<items.size();
} else if (line.size()>=1 && static_cast<qsizetype>(line.size())!=colCount) {
addToErrorList(tr("error @ ch. %1: wrong number of entries widthin '\\begin{%2}...\\end{%2}'").arg(currentTokenID).arg(envname)); addToErrorList(tr("error @ ch. %1: wrong number of entries widthin '\\begin{%2}...\\end{%2}'").arg(currentTokenID).arg(envname));
} }
} }
@ -942,7 +944,8 @@ JKQTMathTextNode* JKQTMathTextLatexParser::parseLatexString(bool get, JKQTMathTe
} }
first=false; first=false;
} }
//std::cout<<" creating matrix-node with "<<items.size()<<" items.\n"; //qDebug()<<" - creating matrix-node with "<<items.size()<<" items.\n";
//for (int i=0; i<items.size(); i++) qDebug()<<" items["<<i<<"].size="<<items[i].size();
matrixNode->setChildren(items); matrixNode->setChildren(items);
if (envname=="pmatrix") nl->addChild(new JKQTMathTextBraceNode(parentMathText, MTBTParenthesis, MTBTParenthesis, matrixNode)); if (envname=="pmatrix") nl->addChild(new JKQTMathTextBraceNode(parentMathText, MTBTParenthesis, MTBTParenthesis, matrixNode));
else if (envname=="cases") nl->addChild(new JKQTMathTextBraceNode(parentMathText, MTBTCurlyBracket, MTBTNone, matrixNode)); else if (envname=="cases") nl->addChild(new JKQTMathTextBraceNode(parentMathText, MTBTCurlyBracket, MTBTNone, matrixNode));