mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-24 09:31:40 +08:00
JKQTMathText: added support for -- and --- for en- and em-dashes
This commit is contained in:
parent
f2e77c3213
commit
de80fa666b
@ -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>
|
||||
|
||||
|
BIN
doc/images/jkqtmathtext/jkqtmathtext_emdash.png
Normal file
BIN
doc/images/jkqtmathtext/jkqtmathtext_emdash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 573 B |
BIN
doc/images/jkqtmathtext/jkqtmathtext_endash.png
Normal file
BIN
doc/images/jkqtmathtext/jkqtmathtext_endash.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 556 B |
BIN
doc/images/jkqtmathtext/jkqtmathtext_hyphen.png
Normal file
BIN
doc/images/jkqtmathtext/jkqtmathtext_hyphen.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 552 B |
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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 */
|
||||
|
@ -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("•").addUprightWinSymbol(QChar(0xB7));
|
||||
{ auto s=UprightSymbolUnicode(QChar(0x2022)).addUprightHtml("•").addUprightWinSymbol(QChar(0xB7));
|
||||
symbols["bullet"]=s; symbols["textbullet"]=s; }
|
||||
symbols["cdots"]=UnicodeSymbol(QChar(0x22EF)).addHtml("···").addStd(QString(3, QChar(0xB7)));
|
||||
{ auto s=UnicodeSymbol(QChar(0x2103)).addUprightStd("°C").addUprightHtml("°C");
|
||||
symbols["celsius"]=s; symbols["degC"]=s; }
|
||||
@ -560,11 +561,21 @@ void JKQTMathTextSymbolNode::fillSymbolTables()
|
||||
symbols["sphericalangle"]=UprightSymbolUnicode(QChar(0x2222)).addHtml("∢");
|
||||
symbols["star"]=UprightSymbolUnicode(QChar(0x22C6));
|
||||
symbols["tcohm"]=UnicodeSymbol(QChar(0x2126));
|
||||
{ auto s=UnicodeSymbol(QChar(0x2014), "⹀");
|
||||
symbols["dblhyphen"]=s; symbols["textdblhyphen"]=s; symbols["textdblhyphenchar"]=s; }
|
||||
{ auto s=UnicodeSymbol(QChar(0x2014), "—");
|
||||
symbols["---"]=s; symbols["textemdash"]=s; symbols["emdash"]=s; }
|
||||
{ auto s=UnicodeSymbol(QChar(0x2013), "–");
|
||||
symbols["--"]=s; symbols["textendash"]=s; symbols["endash"]=s; }
|
||||
{ auto s=SimpleTextSymbol("-");
|
||||
symbols["texthyphen"]=s; symbols["hyphen"]=s; }
|
||||
symbols["textbar"]=SimpleTextSymbol("|", "|");
|
||||
{ auto s=SimpleTextSymbol(QChar(0xB0), "°");
|
||||
symbols["textdegree"]=s; symbols["degree"] = s; }
|
||||
symbols["textgreater"]=SimpleTextSymbol(">", ">");
|
||||
symbols["textless"]=SimpleTextSymbol("<", "<");
|
||||
symbols["textquestiondown"]=SimpleTextSymbol(QChar(0xBF), "¿");
|
||||
symbols["textexclamdown"]=SimpleTextSymbol(QChar(0xA1), "¡");
|
||||
{ auto s=UnicodeSymbol(QChar(0x231C));
|
||||
symbols["tlcorner"]=s; symbols["ulcorner"]=s; }
|
||||
symbols["trademark"]=UnicodeSymbol(QChar(0x2122)).addHtml("™").addWinSymbol(QChar(0xD4)).addStd("(TM)");
|
||||
|
@ -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<<"]";
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user