JKQTMathText: added support for -- and --- for en- and em-dashes

This commit is contained in:
jkriege2 2022-08-01 11:44:38 +02:00
parent f2e77c3213
commit de80fa666b
9 changed files with 45 additions and 4 deletions

View File

@ -72,6 +72,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
<li>NEW: added \c \\substack[lcr]{...\\\\...} , \c \\lsubstack{...\\\\...} , \c \\rsubstack{...\\\\...} instructions</li>
<li>NEW: added support for flushleft/flushright/center-environments with linebreaks</li>
<li>NEW: added support for framed/shaded/snugshade-environments with linebreaks and framed</li>
<li>NEW: added support for -- and --- for en- and em-dashes</li>
</ul></li>
</ul>

Binary file not shown.

After

Width:  |  Height:  |  Size: 573 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 556 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 552 B

View File

@ -28,9 +28,10 @@ TestForm::TestForm(QWidget *parent) :
ui->cmbTestset->addItem("text: fonts", "rm: \\textrm{"+testText+"}, sf: \\textsf{"+testText+"}, tt: \\texttt{"+testText+"}, cal: \\textcal{"+testText+"}, scr: \\textscr{"+testText+"}, bb: \\textbb{"+testText+"}, frak: \\textfrak{"+testText+"}, ");
ui->cmbTestset->addItem("text: umlaute", umla);
ui->cmbTestset->addItem("text: umlaute and fonts", "rm: \\textrm{"+testTextUmla+"}, sf: \\textsf{"+testTextUmla+"}, tt: \\texttt{"+testTextUmla+"}, cal: \\textcal{"+testTextUmla+"}, scr: \\textscr{"+testTextUmla+"}, bb: \\textbb{"+testTextUmla+"}, frak: \\textfrak{"+testTextUmla+"}, ");
ui->cmbTestset->addItem("text: dashes", "hyphen: - endash: -- emdash: --- \\ \\ \\ endash--within text\\ \\ \\ emdash---within text\\ \\ \\ enemdash-----within text\\ \\ \\ ememdash------within text");
ui->cmbTestset->addItem("math: fonts", "base: $"+testText+"$, rm: $\\mathrm{"+testText+"}$, sf: $\\mathsf{"+testText+"}$, tt: $\\mathtt{"+testText+"}$, cal: $\\mathcal{"+testText+"}$, scr: $\\mathscr{"+testText+"}$, bb: $\\mathbb{"+testText+"}$, frak: $\\mathfrak{"+testText+"}$, ");
ui->cmbTestset->addItem("math: umlaute", "$"+umla_math+"$");
ui->cmbTestset->addItem("math: umlaute and \\text{...}", "\\${\\backslash}text{...}\\$: $\\text{"+umla+"}\\ \\ \\ \\$...\\$: "+umla+"$");
ui->cmbTestset->addItem("math: umlaute and \\text{...}", "\\${\\backslash}text\\{...\\}\\$: $\\text{"+umla+"}\\ \\ \\ \\$...\\$: "+umla+"$");
ui->cmbTestset->addItem("math: umlaute and fonts", "base: $"+testTextUmla_math+"$, rm: $\\mathrm{"+testTextUmla_math+"}$, sf: $\\mathsf{"+testTextUmla_math+"}$, tt: $\\mathtt{"+testTextUmla_math+"}$, cal: $\\mathcal{"+testTextUmla_math+"}$, scr: $\\mathscr{"+testTextUmla_math+"}$, bb: $\\mathbb{"+testTextUmla_math+"}$, frak: $\\mathfrak{"+testTextUmla_math+"}$, ");
ui->cmbTestset->addItem("math: simple relations", "$a{\\leq}b$, $a{\\geq}b$, $a{\\equiv}b$, $a=b$, $a{\\neq}b$, $a<b$, $a>b$");
const auto wsExample=[](const QStringList& spaces, const QString before, const QString& after)->QString {

View File

@ -1002,7 +1002,7 @@ JKQTMathText::tokenType JKQTMathText::getToken() {
if (TokenCharacters.size()==0) {
mathEnvironmentSpecialChars<<'(' << '[' << '|' << ')' << ']' << '+' << '-' << '*' << '/' << '<' << '>' << '=';
mathEnvironmentSpecialEndChars<<'(' << '&' << '[' << '|' << ')' << ']' << '\\' << '$' << '{' << '}' << '_' << '^' << '+' << '-' << '/' << '*' << '=' << '<' << '>';
TokenCharacters<<'_'<<'^'<<'\\'<<'$'<<'&'<<'}'<<'{'<<'['<<']';
TokenCharacters<<'-'<<'_'<<'^'<<'\\'<<'$'<<'&'<<'}'<<'{'<<'['<<']';
SingleCharInstructions<<'|'<<';'<<':'<<'!'<<','<<'_'<<'\\'<<'$'<<'%'<<'&'<<'#'<<'}'<<'{'<<' '<<'['<<']';
auto fAddUml=[](const QString& cmd, const QChar& letter, const QChar& ch) {
@ -1280,6 +1280,22 @@ JKQTMathText::tokenType JKQTMathText::getToken() {
fAddUml("AA", QChar(), QChar(0xC5));
}
//----------------------------------------------------------
// check for emdash "---" or endash "--"
if (c=='-' && !parsingMathEnvironment) {
if (parseString.mid(currentTokenID, 3)=="---") {
currentTokenID+=2;
currentTokenName="---";
return currentToken=MTTemdash;
} else if (parseString.mid(currentTokenID, 2)=="--") {
currentTokenID+=1;
currentTokenName="--";
return currentToken=MTTendash;
} else {
currentTokenName="-";
return currentToken=MTThyphen;
}
}
//----------------------------------------------------------
// read an instruction name
if (c=='\\') {
@ -1482,6 +1498,12 @@ JKQTMathTextNode* JKQTMathText::parseLatexString(bool get, JKQTMathTextBraceType
break;
} else if (currentToken==MTTwhitespace) {
if (!parsingMathEnvironment) nl->addChild(new JKQTMathTextWhitespaceNode(this));
} else if (currentToken==MTTendash) {
nl->addChild(new JKQTMathTextSymbolNode(this, "endash"));
} else if (currentToken==MTTemdash) {
nl->addChild(new JKQTMathTextSymbolNode(this, "emdash"));
} else if (currentToken==MTThyphen) {
nl->addChild(new JKQTMathTextSymbolNode(this, "hyphen"));
} else if (currentToken==MTTinstruction) {
const QString currentInstructionName=currentTokenName;
if (currentInstructionName=="\\") break; // break on linebrak character

View File

@ -143,6 +143,9 @@ class JKQTMathTextNode; // forward
symbols may differ (there are not all symbols defined in the MS Windows Symbol
font!). Best coverage should be given by Unicode font encoding with a good
unicode font installed!<br>\image html jkqtmathtext/jkqtmathtext_symbols.png
- \c - : draw a hyphen \image html jkqtmathtext/jkqtmathtext_hyphen.png
- \c -- : draw an en-dash \image html jkqtmathtext/jkqtmathtext_endash.png
- \c --- : draw an em-dash \image html jkqtmathtext/jkqtmathtext_emdash.png
- <code>\\vec{x} \\dot{x} \\ddot{x} \\overline{x} \\underline{x} \\hat{x} \\tilde{x} \\uul{x} \\ool{x} \\bar{x} \\arrow{x} \\widehat{x} \\widetilde{x} ...</code>: Decorations over/under symbols \image html jkqtmathtext/jkqtmathtext_mathdeco.png
- <code>\\verb{don't parse this _aaa\\LaTeX} </code>: interpret enclosed text as verbose \image html jkqtmathtext/jkqtmathtext_verb.png
.
@ -832,6 +835,9 @@ class JKQTMATHTEXT_LIB_EXPORT JKQTMathText : public QObject {
MTTclosebracket, /*!< \brief the character \c "]" */
MTTwhitespace, /*!< \brief some whitespace */
MTTampersand, /*!< \brief the character \c "&" */
MTThyphen, /*!< \brief the single hyphen character \c "-" in text-mode \note MTTendash and MTTemdash take precedence over MTThypen */
MTTendash, /*!< \brief the en-dash character sequence \c "--" in text-mode */
MTTemdash, /*!< \brief the em-dash character sequence \c "---" in text-mode */
};
/** \brief tokenizer for the LaTeX parser */

View File

@ -489,7 +489,8 @@ void JKQTMathTextSymbolNode::fillSymbolTables()
symbols["blcorner"]=s; symbols["llcorner"]=s; }
{ auto s=UprightSymbolUnicode(QChar(0x231F));
symbols["brcorner"]=s; symbols["lrcorner"]=s; }
symbols["bullet"]=UprightSymbolUnicode(QChar(0x2022)).addUprightHtml("&bull;").addUprightWinSymbol(QChar(0xB7));
{ auto s=UprightSymbolUnicode(QChar(0x2022)).addUprightHtml("&bull;").addUprightWinSymbol(QChar(0xB7));
symbols["bullet"]=s; symbols["textbullet"]=s; }
symbols["cdots"]=UnicodeSymbol(QChar(0x22EF)).addHtml("&middot;&middot;&middot;").addStd(QString(3, QChar(0xB7)));
{ auto s=UnicodeSymbol(QChar(0x2103)).addUprightStd("°C").addUprightHtml("&deg;C");
symbols["celsius"]=s; symbols["degC"]=s; }
@ -560,11 +561,21 @@ void JKQTMathTextSymbolNode::fillSymbolTables()
symbols["sphericalangle"]=UprightSymbolUnicode(QChar(0x2222)).addHtml("&angsph;");
symbols["star"]=UprightSymbolUnicode(QChar(0x22C6));
symbols["tcohm"]=UnicodeSymbol(QChar(0x2126));
{ auto s=UnicodeSymbol(QChar(0x2014), "&#11840;");
symbols["dblhyphen"]=s; symbols["textdblhyphen"]=s; symbols["textdblhyphenchar"]=s; }
{ auto s=UnicodeSymbol(QChar(0x2014), "&mdash;");
symbols["---"]=s; symbols["textemdash"]=s; symbols["emdash"]=s; }
{ auto s=UnicodeSymbol(QChar(0x2013), "&ndash;");
symbols["--"]=s; symbols["textendash"]=s; symbols["endash"]=s; }
{ auto s=SimpleTextSymbol("-");
symbols["texthyphen"]=s; symbols["hyphen"]=s; }
symbols["textbar"]=SimpleTextSymbol("|", "&VerticalLine;");
{ auto s=SimpleTextSymbol(QChar(0xB0), "&deg;");
symbols["textdegree"]=s; symbols["degree"] = s; }
symbols["textgreater"]=SimpleTextSymbol(">", "&gt;");
symbols["textless"]=SimpleTextSymbol("<", "&lt;");
symbols["textquestiondown"]=SimpleTextSymbol(QChar(0xBF), "&iquest;");
symbols["textexclamdown"]=SimpleTextSymbol(QChar(0xA1), "&iexcl;");
{ auto s=UnicodeSymbol(QChar(0x231C));
symbols["tlcorner"]=s; symbols["ulcorner"]=s; }
symbols["trademark"]=UnicodeSymbol(QChar(0x2122)).addHtml("&trade;").addWinSymbol(QChar(0xD4)).addStd("(TM)");

View File

@ -51,7 +51,7 @@ JKQTMathTextTextNode::JKQTMathTextTextNode(JKQTMathText* _parent, const QString&
while (this->text.size()>1 && this->text[0].isSpace()) {
this->text=this->text.right(this->text.size()-1);
}
if (addWhitespace /*&& (this->text.size()>0)*/ && (!this->text[this->text.size()-1].isSpace())) this->text=this->text+" ";
if (addWhitespace && (this->text.size()>0) && (!this->text[this->text.size()-1].isSpace())) this->text=this->text+" ";
//qDebug()<<"JKQTMathTextTextNode( text="<<text<<" addWhitespace="<<addWhitespace<<") [=> this->text="<<this->text<<"]";
}