From de80fa666b0b2a4acfd7e59bb47555b723d46877 Mon Sep 17 00:00:00 2001 From: jkriege2 Date: Mon, 1 Aug 2022 11:44:38 +0200 Subject: [PATCH] JKQTMathText: added support for -- and --- for en- and em-dashes --- doc/dox/whatsnew.dox | 1 + .../jkqtmathtext/jkqtmathtext_emdash.png | Bin 0 -> 573 bytes .../jkqtmathtext/jkqtmathtext_endash.png | Bin 0 -> 556 bytes .../jkqtmathtext/jkqtmathtext_hyphen.png | Bin 0 -> 552 bytes examples/jkqtmathtext_test/testform.cpp | 3 ++- lib/jkqtmathtext/jkqtmathtext.cpp | 24 +++++++++++++++++- lib/jkqtmathtext/jkqtmathtext.h | 6 +++++ .../nodes/jkqtmathtextsymbolnode.cpp | 13 +++++++++- .../nodes/jkqtmathtexttextnode.cpp | 2 +- 9 files changed, 45 insertions(+), 4 deletions(-) create mode 100644 doc/images/jkqtmathtext/jkqtmathtext_emdash.png create mode 100644 doc/images/jkqtmathtext/jkqtmathtext_endash.png create mode 100644 doc/images/jkqtmathtext/jkqtmathtext_hyphen.png diff --git a/doc/dox/whatsnew.dox b/doc/dox/whatsnew.dox index 10274d6cc8..a28ebda9a4 100644 --- a/doc/dox/whatsnew.dox +++ b/doc/dox/whatsnew.dox @@ -72,6 +72,7 @@ Changes, compared to \ref page_whatsnew_V4_0_0 "v4.0.0" include:
  • NEW: added \c \\substack[lcr]{...\\\\...} , \c \\lsubstack{...\\\\...} , \c \\rsubstack{...\\\\...} instructions
  • NEW: added support for flushleft/flushright/center-environments with linebreaks
  • NEW: added support for framed/shaded/snugshade-environments with linebreaks and framed
  • +
  • NEW: added support for -- and --- for en- and em-dashes
  • diff --git a/doc/images/jkqtmathtext/jkqtmathtext_emdash.png b/doc/images/jkqtmathtext/jkqtmathtext_emdash.png new file mode 100644 index 0000000000000000000000000000000000000000..d5074420cd7696d071aa462cdebbd016700f15d8 GIT binary patch literal 573 zcmV-D0>b@?P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D01|XXSaefwW^{L9 za%BKVa%E+1b7*gLUR4MM0005BNklpuFVYFuQ|3~b8Nrnc*3tU#So6H(Jc80A;ffQ_{XgFi?=0i`Nd8X zALAFnp56X_v1cFU*Ux^B+pjtPw_mJI=_|@9#VxNJ^m=Ou^ohq&o_#aL7|~vKM7_Y} zROUxBa%g9-#Q0V8HZ7u^g!EVTQS*EhQ>w93&FLEHbq(A0gtn1@GWCvsX3t?%y`v$- zs{y~tXq;=5$kNS_A;v9?TLd0(VM}7BJj3`iB`xxf4DBDK`z5*tM41<9*Vb5e8u#(V z0@o2WBL_nrv}Rs+dkX6p$g+IjFMhK7xMHc`gTY(P4gTEot9>MQcs;^>zr11fXYp%( zaicb6@Jo;$TGd+%*zI}X{iUAzvkF}&2U{`*Vfnk|Dqmt00000 LNkvXXu0mjftg{3p literal 0 HcmV?d00001 diff --git a/doc/images/jkqtmathtext/jkqtmathtext_endash.png b/doc/images/jkqtmathtext/jkqtmathtext_endash.png new file mode 100644 index 0000000000000000000000000000000000000000..47176221a5a602a7bc53a2c19ce4d5d87a686e87 GIT binary patch literal 556 zcmeAS@N?(olHy`uVBq!ia0vp^5kM@(!2~4tr1P)anMprBBRYeY$Kep*R+Vo@rCdr@j?UU5c#Nn9ug zPz&Q?PZ!6K2=}+sUY8zL;A!1EO*~09|FDsq8fz?LxW%#MM_y(|-HqqiyWhfZTD$iX zg%CccrwSqVOiA~zrE&(YeXrG)8hI@@{IhSBHAkd!Hdl+nnO`*mkxa?IIt3)^nU7@0 z^Rh4erK|92`kdvNhv)8PR$+>AHc(ix$ak?!R#S=z=b;|cVDS&s}_a<k zwQJI%pK7WnZ>_kfHuI{4i q(n@(B%|GF|LZ;;u644>ouYcy=pGL3c7ukT3$>8bg=d#Wzp$Py&g6LKN literal 0 HcmV?d00001 diff --git a/doc/images/jkqtmathtext/jkqtmathtext_hyphen.png b/doc/images/jkqtmathtext/jkqtmathtext_hyphen.png new file mode 100644 index 0000000000000000000000000000000000000000..775c712e4b3e50e00cd26210a5698e62a84119c9 GIT binary patch literal 552 zcmeAS@N?(olHy`uVBq!ia0vp^0YEIr!2~2t6#1S3DaPU;cPEB*=VV?2IV|apzK#qG z8~eHcB(eheoCO|{#S9F5he4R}c>anMprBBRYeY$Kep*R+Vo@rCdr@j?UU5c#Nn9ug zPz&RHPZ!6K2=}*B-&P)0;Az=AO*~09|8c5OkG2Y9yN`_X-z%EW>Ox;U{xWHT-|fRD z4b|5f-o^H_#oaaW{ru_D2d%x+WIL+a|+jX#CR{i7S<|;`%4(# zG`?-_wfX5ePdtP!*92NEE=e(& zyK+|b+~O*Q#2HVrofT^9+HRaYlQcVQ$&WQ<2MV%xwi-TZ7P#eSdtuAX-r|K~Z54@{ z|L3Nq<-WD5IxMri^plCJ`{@syd3+Ie*OC~wOj4P$G3U-Qu7p^BE)DjX@r;X^Pchy4 z;gK_wMJ)6HXER&UBVL1mM9ZAK;5DTWA&RXM?oOCu{l2l#+MCrf@64u>MV8zdkIfVf z^x2eib+qQbx|f*Cc{*`JoKwYEA|}Tls0@ludSb&i;1_`RH^;COf(N z(8cFw>pFzbaoax(R(ij;m*M*E`wOBHcHLl#C_nIFs#en0y8U?%_y85}Sb4q9e0KetxLI3~& literal 0 HcmV?d00001 diff --git a/examples/jkqtmathtext_test/testform.cpp b/examples/jkqtmathtext_test/testform.cpp index a927e45b97..0fcb5f4089 100644 --- a/examples/jkqtmathtext_test/testform.cpp +++ b/examples/jkqtmathtext_test/testform.cpp @@ -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$, $ab$"); const auto wsExample=[](const QStringList& spaces, const QString before, const QString& after)->QString { diff --git a/lib/jkqtmathtext/jkqtmathtext.cpp b/lib/jkqtmathtext/jkqtmathtext.cpp index adcc7b8ec9..dfa9541e12 100644 --- a/lib/jkqtmathtext/jkqtmathtext.cpp +++ b/lib/jkqtmathtext/jkqtmathtext.cpp @@ -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 diff --git a/lib/jkqtmathtext/jkqtmathtext.h b/lib/jkqtmathtext/jkqtmathtext.h index c1b4e5be67..50c670ccaa 100644 --- a/lib/jkqtmathtext/jkqtmathtext.h +++ b/lib/jkqtmathtext/jkqtmathtext.h @@ -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!
    \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 - \\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} ...: Decorations over/under symbols \image html jkqtmathtext/jkqtmathtext_mathdeco.png - \\verb{don't parse this _aaa\\LaTeX} : 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 */ diff --git a/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp index 5756bf641f..4f69718447 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp +++ b/lib/jkqtmathtext/nodes/jkqtmathtextsymbolnode.cpp @@ -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)"); diff --git a/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp b/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp index fed3de5691..9c278a78b6 100644 --- a/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp +++ b/lib/jkqtmathtext/nodes/jkqtmathtexttextnode.cpp @@ -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="< this->text="<text<<"]"; }