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 0000000000..d5074420cd Binary files /dev/null and b/doc/images/jkqtmathtext/jkqtmathtext_emdash.png differ diff --git a/doc/images/jkqtmathtext/jkqtmathtext_endash.png b/doc/images/jkqtmathtext/jkqtmathtext_endash.png new file mode 100644 index 0000000000..47176221a5 Binary files /dev/null and b/doc/images/jkqtmathtext/jkqtmathtext_endash.png differ diff --git a/doc/images/jkqtmathtext/jkqtmathtext_hyphen.png b/doc/images/jkqtmathtext/jkqtmathtext_hyphen.png new file mode 100644 index 0000000000..775c712e4b Binary files /dev/null and b/doc/images/jkqtmathtext/jkqtmathtext_hyphen.png differ 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<<"]"; }