From efaae780dbbe3685e26e040ed4255e5abf268106 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sun, 24 Feb 2013 21:23:50 +0100 Subject: [PATCH] Fix regression of 5261ae6a2 Somehow I overlooked that \sideset also supports nonscript arguments for left and right. This is now fixed, although I do not like the toolbar names. If somebody knows something better, please improve. --- lib/Makefile.am | 3 + lib/images/math/sideset1.png | Bin 0 -> 138 bytes lib/images/math/sideset2.png | Bin 0 -> 142 bytes lib/images/math/sideset3.png | Bin 0 -> 134 bytes lib/ui/stdtoolbars.inc | 5 +- src/mathed/InsetMathSideset.cpp | 217 +++++++++++++++++++++++--------- src/mathed/InsetMathSideset.h | 37 +++--- src/mathed/MathFactory.cpp | 9 +- src/mathed/MathParser.cpp | 36 +++--- 9 files changed, 214 insertions(+), 93 deletions(-) create mode 100644 lib/images/math/sideset1.png create mode 100644 lib/images/math/sideset2.png create mode 100644 lib/images/math/sideset3.png diff --git a/lib/Makefile.am b/lib/Makefile.am index a428b3d1a7..b0a160efeb 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1110,6 +1110,9 @@ dist_imagesmath_DATA = \ images/math/shortrightarrow.png \ images/math/shortuparrow.png \ images/math/sideset.png \ + images/math/sideset1.png \ + images/math/sideset2.png \ + images/math/sideset3.png \ images/math/sigma.png \ images/math/sigma2.png \ images/math/sim.png \ diff --git a/lib/images/math/sideset1.png b/lib/images/math/sideset1.png new file mode 100644 index 0000000000000000000000000000000000000000..a919e8fa6446ff9759339860848171f4e8fcd50b GIT binary patch literal 138 zcmeAS@N?(olHy`uVBq!ia0vp^q98U08<2FHq?!Pv*pj^6T^Rm@;DWu&Cj&(|3p^r= z85p>QL70(Y)*K0-pq8hLV~EA+QL70(Y)*K0-pq{6TV~EA+wS?KfD#Pd<{@1gQu&X%Q~loCIC6gC<*`o literal 0 HcmV?d00001 diff --git a/lib/images/math/sideset3.png b/lib/images/math/sideset3.png new file mode 100644 index 0000000000000000000000000000000000000000..211c5f9144912974b3cf9bb7c5e98964b612ae13 GIT binary patch literal 134 zcmeAS@N?(olHy`uVBq!ia0vp^q98U08<2FHq?!Pv*pj^6T^Rm@;DWu&Cj&(|3p^r= z85p>QL70(Y)*K0-pqi(PV~EA+?nD0 nucleus + cur.idx() = 0; + return true; + } else if (!scriptr_ && cur.idx() == 0) { + // nucleus => right + cur.idx() = 2 + scriptl_; + return true; + } return false; } -bool InsetMathSideset::idxBackward(Cursor &) const +bool InsetMathSideset::idxBackward(Cursor & cur) const { + if (!scriptr_ && cur.idx() == (scriptl_ ? 3 : 2)) { + // right => nucleus + cur.idx() = 0; + return true; + } else if (!scriptl_ && cur.idx() == 0) { + // nucleus => left + cur.idx() = 1; + return true; + } return false; } @@ -245,11 +316,12 @@ bool InsetMathSideset::idxUpDown(Cursor & cur, bool up) const if (cur.idx() == 0) { // go up/down only if in the last position // or in the first position - if (cur.pos() == cur.lastpos() || cur.pos() == 0) { + if ((scriptr_ && cur.pos() == cur.lastpos()) || + (scriptl_ && cur.pos() == 0)) { if (cur.pos() == 0) cur.idx() = up ? 2 : 1; else - cur.idx() = up ? 4 : 3; + cur.idx() = (up ? 3 : 2) + scriptl_; cur.pos() = 0; return true; } @@ -257,7 +329,8 @@ bool InsetMathSideset::idxUpDown(Cursor & cur, bool up) const } // Are we 'up'? - if (cur.idx() == 2 || cur.idx() == 4) { + if ((scriptl_ && cur.idx() == 2) || + (scriptr_ && cur.idx() == (scriptl_ ? 4 : 3))) { // can't go further up if (up) return false; @@ -271,7 +344,8 @@ bool InsetMathSideset::idxUpDown(Cursor & cur, bool up) const } // Are we 'down'? - if (cur.idx() == 1 || cur.idx() == 3) { + if ((scriptl_ && cur.idx() == 1) || + (scriptr_ && cur.idx() == (scriptl_ ? 3 : 2))) { // can't go further down if (!up) return false; @@ -293,15 +367,24 @@ void InsetMathSideset::write(WriteStream & os) const MathEnsurer ensurer(os); os << "\\sideset"; - for (int i = 0; i < 2; ++i) { - os << '{'; - if (!cell(2*i+1).empty()) - os << "_{" << cell(2*i+1) << '}'; - if (!cell(2*i+2).empty()) - os << "^{" << cell(2*i+2) << '}'; - os << '}'; - } - os << '{' << nuc() << '}'; + os << '{'; + if (scriptl_) { + if (!bl().empty()) + os << "_{" << bl() << '}'; + if (!tl().empty()) + os << "^{" << tl() << '}'; + } else + os << bl(); + os << "}{"; + if (scriptr_) { + if (!br().empty()) + os << "_{" << br() << '}'; + if (!tr().empty()) + os << "^{" << tr() << '}'; + } else + os << br(); + os << '}'; + os << nuc(); if (lock_ && !os.latex()) os << "\\lyxlock "; @@ -314,7 +397,7 @@ void InsetMathSideset::normalize(NormalStream & os) const if (!bl().empty()) os << bl() << ' '; - if (!tl().empty()) + if (scriptl_ && !tl().empty()) os << tl() << ' '; if (!nuc().empty()) @@ -324,7 +407,7 @@ void InsetMathSideset::normalize(NormalStream & os) const if (!br().empty()) os << br() << ' '; - if (!tr().empty()) + if (scriptr_ && !tr().empty()) os << tr() << ' '; os << ']'; } @@ -332,41 +415,52 @@ void InsetMathSideset::normalize(NormalStream & os) const void InsetMathSideset::mathmlize(MathStream & os) const { - os << MTag("mmultiscripts"); + // FIXME This is only accurate if both scriptl_ and scriptr_ are true + if (!scriptl_) + os << MTag("mrow") << bl() << ETag("mrow"); + if (scriptl_ || scriptr_) { + os << MTag("mmultiscripts"); - if (nuc().empty()) - os << ""; - else - os << MTag("mrow") << nuc() << ETag("mrow"); + if (nuc().empty()) + os << ""; + else + os << MTag("mrow") << nuc() << ETag("mrow"); - if (br().empty()) - os << ""; - else - os << MTag("mrow") << br() << ETag("mrow"); - if (tr().empty()) - os << ""; - else - os << MTag("mrow") << tr() << ETag("mrow"); + if (br().empty() || !scriptr_) + os << ""; + else + os << MTag("mrow") << br() << ETag("mrow"); + if (tr().empty() || !scriptr_) + os << ""; + else + os << MTag("mrow") << tr() << ETag("mrow"); - if (bl().empty()) - os << ""; - else - os << MTag("mrow") << bl() << ETag("mrow"); - if (tl().empty()) - os << ""; - else - os << MTag("mrow") << tl() << ETag("mrow"); + if (bl().empty() || !scriptl_) + os << ""; + else + os << MTag("mrow") << bl() << ETag("mrow"); + if (tl().empty() || !scriptl_) + os << ""; + else + os << MTag("mrow") << tl() << ETag("mrow"); - os << ETag("mmultiscripts"); + os << ETag("mmultiscripts"); + } + if (!scriptr_) + os << MTag("mrow") << br() << ETag("mrow"); } void InsetMathSideset::htmlize(HtmlStream & os) const { - bool const havebl = !bl().empty(); - bool const havetl = !tl().empty(); - bool const havebr = !br().empty(); - bool const havetr = !tr().empty(); + // FIXME This is only accurate if both scriptl_ and scriptr_ are true + bool const havebl = scriptl_ && !bl().empty(); + bool const havetl = scriptl_ && !tl().empty(); + bool const havebr = scriptr_ && !br().empty(); + bool const havetr = scriptr_ && !tr().empty(); + + if (!scriptl_ && !bl().empty()) + os << bl(); if (havebl && havetl) os << MTag("span", "class='scripts'") @@ -390,6 +484,9 @@ void InsetMathSideset::htmlize(HtmlStream & os) const os << MTag("sub", "class='math'") << br() << ETag("sub"); else if (havetr) os << MTag("sup", "class='math'") << tr() << ETag("sup"); + + if (!scriptr_ && !br().empty()) + os << br(); } diff --git a/src/mathed/InsetMathSideset.h b/src/mathed/InsetMathSideset.h index 67f7eaa06f..41dc8eb1b4 100644 --- a/src/mathed/InsetMathSideset.h +++ b/src/mathed/InsetMathSideset.h @@ -25,9 +25,10 @@ namespace lyx { class InsetMathSideset : public InsetMathNest { public: /// - InsetMathSideset(Buffer * buf); + InsetMathSideset(Buffer * buf, bool scriptl, bool scriptr); /// create inset with given nucleus - InsetMathSideset(Buffer * buf, MathAtom const & at); + InsetMathSideset(Buffer * buf, bool scriptl, bool scriptr, + MathAtom const & at); /// mode_type currentMode() const { return MATH_MODE; } /// @@ -63,22 +64,22 @@ public: MathData const & nuc() const { return cell(0); }; /// returns nucleus MathData & nuc() { return cell(0); }; - /// bottom left index + /// bottom left index or single left cell MathData const & bl() const { return cell(1); } - /// bottom left index + /// bottom left index or single left cell MathData & bl() { return cell(1); } - /// top left index - MathData const & tl() const { return cell(2); } - /// top left index - MathData & tl() { return cell(2); } - /// bottom right index - MathData const & br() const { return cell(3); } - /// bottom right index - MathData & br() { return cell(3); } - /// top right index - MathData const & tr() const { return cell(4); } - /// top right index - MathData & tr() { return cell(4); } + /// top left index or single left cell + MathData const & tl() const { return cell(1 + scriptl_); } + /// top left index or single left cell + MathData & tl() { return cell(1 + scriptl_); } + /// bottom right index or single right cell + MathData const & br() const { return cell(2 + scriptl_); } + /// bottom right index or single right cell + MathData & br() { return cell(2 + scriptl_); } + /// top right index or single right cell + MathData const & tr() const { return cell(2 + scriptl_ + scriptr_); } + /// top right index or single right cell + MathData & tr() { return cell(2 + scriptl_ + scriptr_); } /// say that we have scripts void infoize(odocstream & os) const; /// @@ -105,6 +106,10 @@ private: int ndes(BufferView const &) const; /// returns subscript and superscript kerning of nucleus if any int nker(BufferView const * bv) const; + /// Whether there are two left scripts or one single cell + bool scriptl_; + /// Whether there are two right scripts or one single cell + bool scriptr_; }; diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp index d2bd2e8cb3..3bea8e9335 100644 --- a/src/mathed/MathFactory.cpp +++ b/src/mathed/MathFactory.cpp @@ -537,7 +537,14 @@ MathAtom createInsetMath(docstring const & s, Buffer * buf) if (s == "ensuremath") return MathAtom(new InsetMathEnsureMath(buf)); if (s == "sideset") - return MathAtom(new InsetMathSideset(buf)); + return MathAtom(new InsetMathSideset(buf, true, true)); + // The following 3 string values are only for math toolbar use, no LaTeX names + if (s == "sideset1") + return MathAtom(new InsetMathSideset(buf, false, true)); + if (s == "sideset2") + return MathAtom(new InsetMathSideset(buf, true, false)); + if (s == "sideset3") + return MathAtom(new InsetMathSideset(buf, false, false)); if (isSpecialChar(s)) return MathAtom(new InsetMathSpecialChar(s)); if (s == " ") diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index 61e000ccc2..05ceed80f2 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -1445,23 +1445,29 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, else if (t.cs() == "sideset") { // Here allowed formats are \sideset{_{bl}^{tl}}{_{br}^{tr}}{operator} - cell->push_back(MathAtom(new InsetMathSideset(buf))); + MathData ar[2]; + InsetMathScript * script[2] = {0, 0}; for (int i = 0; i < 2; ++i) { - MathData ar; - parse(ar, FLAG_ITEM, mode); - if (!ar.empty()) { - InsetMathScript * script = (ar.size() == 1) ? - ar[0].nucleus()->asScriptInset() : 0; - if (!script) { - error("found invalid sideset argument"); - break; - } - if (script->hasDown()) - cell->back().nucleus()->cell(2 * i + 1) = script->down(); - if (script->hasUp()) - cell->back().nucleus()->cell(2 * i + 2) = script->up(); - } + parse(ar[i], FLAG_ITEM, mode); + if (ar[i].size() == 1) + script[i] = ar[i][0].nucleus()->asScriptInset(); } + bool const hasscript[2] = {script[0] ? true : false, script[1] ? true : false}; + cell->push_back(MathAtom(new InsetMathSideset(buf, hasscript[0], hasscript[1]))); + if (hasscript[0]) { + if (script[0]->hasDown()) + cell->back().nucleus()->cell(1) = script[0]->down(); + if (script[0]->hasUp()) + cell->back().nucleus()->cell(2) = script[0]->up(); + } else + cell->back().nucleus()->cell(1) = ar[0]; + if (hasscript[1]) { + if (script[1]->hasDown()) + cell->back().nucleus()->cell(2 + hasscript[0]) = script[1]->down(); + if (script[1]->hasUp()) + cell->back().nucleus()->cell(3 + hasscript[0]) = script[1]->up(); + } else + cell->back().nucleus()->cell(2 + hasscript[0]) = ar[1]; parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode); } -- 2.39.5