mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-11-15 10:05:47 +08:00
FIX: JKQTMathText: rendering of matrices, when onle one row or column or a single value are present
This commit is contained in:
parent
924eb5fe91
commit
819ac7f9fc
BIN
doc/images/jkqtmathtext/jkqtmathtext_array_1col.png
Normal file
BIN
doc/images/jkqtmathtext/jkqtmathtext_array_1col.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
BIN
doc/images/jkqtmathtext/jkqtmathtext_bmatrix_1col.png
Normal file
BIN
doc/images/jkqtmathtext/jkqtmathtext_bmatrix_1col.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 980 B |
@ -5,6 +5,9 @@ $\mat{M}_1=\begin{matrix}a&b&...\\ c&d&...\end{matrix}\ \ \ \ \ \ \mat{M}_2=\lef
|
||||
jkqtmathtext_bmatrix.png
|
||||
$\begin{bmatrix}a&b&...\\ c&d&...\end{bmatrix}$
|
||||
---
|
||||
jkqtmathtext_bmatrix_1col.png
|
||||
$\begin{bmatrix}a\\b\\...\end{bmatrix}$
|
||||
---
|
||||
jkqtmathtext_bbmatrix.png
|
||||
$\begin{Bmatrix}a&b&...\\ c&d&...\end{Bmatrix}$
|
||||
---
|
||||
@ -45,3 +48,6 @@ $\mat{M}_\cdot=\begin{array}{l:ll}
|
||||
\beta & b & \ldots \\
|
||||
\vdots & \vdots & \ddots \\
|
||||
\end{array}\right)$
|
||||
---
|
||||
jkqtmathtext_array_1col.png
|
||||
$\vec{c}=\left(\begin{array}{l} \alpha \\ b \\ ... \end{array}\right)$
|
||||
|
@ -885,10 +885,17 @@ JKQTMathTextNode* JKQTMathTextLatexParser::parseLatexString(bool get, JKQTMathTe
|
||||
bool firstLine=true;
|
||||
QVector<JKQTMathTextNode*> line;
|
||||
qsizetype colCount=0;
|
||||
//std::cout<<"found \\begin{matrix}\n";
|
||||
//qDebug()<<"start "<<envname;
|
||||
while (first || currentToken==MTTampersand || currentToken==MTTinstructionNewline) {
|
||||
while (getToken()==MTTwhitespace) ; // eat whitespace
|
||||
JKQTMathTextNode* it=simplifyAndTrimJKQTMathTextNode(parseLatexString(false, MTBTAny, envname));
|
||||
//qDebug()<<" - START: "<<tokenType2String(currentToken)<<" first="<<first;
|
||||
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 (lastMatrixLineCommandCount.value("hline",0)==1) {
|
||||
matrixNode->setTopLine(JKQTMathTextMatrixNode::LTline);
|
||||
@ -914,26 +921,21 @@ JKQTMathTextNode* JKQTMathTextLatexParser::parseLatexString(bool get, JKQTMathTe
|
||||
matrixNode->setRowBottomLine(items.size()-1, JKQTMathTextMatrixNode::LTdoubleDashed);
|
||||
}
|
||||
}
|
||||
//qDebug()<<" - before append CurrenTinstruction="<<tokenType2String(currentToken)<<", currentTokenName="<<currentTokenName;
|
||||
if (currentToken==MTTampersand) {
|
||||
//std::cout<<" appending item\n";
|
||||
//qDebug()<<" - appending item "<<it->getTypeName();
|
||||
line.append(it);
|
||||
} else {
|
||||
//std::cout<<" appending item and line with "<<line.size()<<" items.\n";
|
||||
if (currentToken==MTTinstructionEnd) {
|
||||
JKQTMathTextMultiChildNode* mnc=dynamic_cast<JKQTMathTextMultiChildNode*>(it);
|
||||
if (mnc && mnc->childCount()>0) {
|
||||
line.append(it);
|
||||
} else {
|
||||
line.append(it);
|
||||
}
|
||||
} else {
|
||||
line.append(it);
|
||||
}
|
||||
if (currentToken==MTTinstructionNewline || line.size()>0) {
|
||||
//qDebug()<<" - appending item "<<it->getTypeName()<<" to line with "<<line.size()<<" items.";
|
||||
line.append(it);
|
||||
|
||||
if (currentToken==MTTinstructionNewline || (currentToken==MTTinstructionEnd && currentTokenName==envname) || line.size()>0) {
|
||||
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);
|
||||
} 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));
|
||||
}
|
||||
}
|
||||
@ -942,7 +944,8 @@ JKQTMathTextNode* JKQTMathTextLatexParser::parseLatexString(bool get, JKQTMathTe
|
||||
}
|
||||
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);
|
||||
if (envname=="pmatrix") nl->addChild(new JKQTMathTextBraceNode(parentMathText, MTBTParenthesis, MTBTParenthesis, matrixNode));
|
||||
else if (envname=="cases") nl->addChild(new JKQTMathTextBraceNode(parentMathText, MTBTCurlyBracket, MTBTNone, matrixNode));
|
||||
|
Loading…
Reference in New Issue
Block a user