From 187790135b73e3e99a43e53f8c6494d119e94e98 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sun, 8 Jan 2012 12:34:12 +0000 Subject: [PATCH] Fix bug #5029: Support \smash, \mathclap, \mathllap and \mathrlap. Also improve lyx2lyx roundtrip for automatically loaded packages. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40589 a592a061-630c-0410-9148-cb99ea01b6c8 --- lib/Makefile.am | 4 + lib/images/math/mathclap.png | Bin 0 -> 215 bytes lib/images/math/mathllap.png | Bin 0 -> 212 bytes lib/images/math/mathrlap.png | Bin 0 -> 213 bytes lib/images/math/smash.png | Bin 0 -> 254 bytes lib/lyx2lyx/lyx_2_0.py | 13 ++- lib/lyx2lyx/lyx_2_1.py | 25 ++++- lib/ui/stdtoolbars.inc | 4 + src/LaTeXFeatures.cpp | 5 +- src/TextClass.cpp | 4 +- src/mathed/InsetMathNest.cpp | 4 + src/mathed/InsetMathPhantom.cpp | 192 +++++++++++++++++++++++++++++++- src/mathed/InsetMathPhantom.h | 10 +- src/mathed/MathFactory.cpp | 8 ++ 14 files changed, 250 insertions(+), 19 deletions(-) create mode 100644 lib/images/math/mathclap.png create mode 100644 lib/images/math/mathllap.png create mode 100644 lib/images/math/mathrlap.png create mode 100644 lib/images/math/smash.png diff --git a/lib/Makefile.am b/lib/Makefile.am index d2211d59dc..1119f55e49 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -734,6 +734,9 @@ dist_imagesmath_DATA = \ images/math/mathcal_L.png \ images/math/mathcal_O.png \ images/math/mathcircumflex.png \ + images/math/mathclap.png \ + images/math/mathllap.png \ + images/math/mathrlap.png \ images/math/mathrm_T.png \ images/math/matrix.png \ images/math/measuredangle.png \ @@ -866,6 +869,7 @@ dist_imagesmath_DATA = \ images/math/smallfrown.png \ images/math/smallsetminus.png \ images/math/smallsmile.png \ + images/math/smash.png \ images/math/smile.png \ images/math/space.png \ images/math/spadesuit.png \ diff --git a/lib/images/math/mathclap.png b/lib/images/math/mathclap.png new file mode 100644 index 0000000000000000000000000000000000000000..706adab02e29fd95a839bdabaa1d6313240c0109 GIT binary patch literal 215 zcmeAS@N?(olHy`uVBq!ia0vp@KrGC`1|+@B+ouC5#^NA%Cx&(BWL^R}Y)RhkE)4%c zaKYZ?lYt_f1s;*b3=G`DAk4@xYmNj^kiEpy*OmPaBL@!$=gY@?l7T|uo-U3d8t1Q0 zvKDGE;9$L9_1}8E>!gptoV{Mmk_q?N9DJ{CGda8R+l|YIn7v{TWP43eaof2^xJWsu zS6RYt@sX+4Py1hn3aGmVul%9DOsM|GFVdQ&MBb@0AQ#? A0{{R3 literal 0 HcmV?d00001 diff --git a/lib/images/math/mathrlap.png b/lib/images/math/mathrlap.png new file mode 100644 index 0000000000000000000000000000000000000000..d78aa065dc3c4e185b6f90f90857d66909f3a854 GIT binary patch literal 213 zcmeAS@N?(olHy`uVBq!ia0vp@KrGC`1|+@B+ouC5#^NA%Cx&(BWL^R}Y)RhkE)4%c zaKYZ?lYt_f1s;*b3=G`DAk4@xYmNj^kiEpy*OmPaBL@$gqSIANaiCDBr;B5V#`&w0 z4EYWy@G#f@`F}o*fm7>ZS4v~rNuk#=>Nmo+bWM8dcl+IvH;js+1wAa&&L#!TddBwB z_d-$jA$HBAi*57l=Px;#RJGjk*TK2(et+uO%5^Wa^d@WPonW8^44$rjF6*2Ung9Cxj)y`=j}o;EI=@`<6lsn|yLVah&U zC9_>|T%qfh=$JpPz2v*@(5 // \ / - // y3---- \ / - // | | | | - // x1 x2 x3 x4 + // y3---- \ / + // | | | | + // x1 x2 x3 x4 int const x1 = x; int const x2 = x + arrow_size; @@ -113,6 +116,123 @@ void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const pi.pain.line(x1, y2, x4, y2, Color_added_space); } + else if (kind_ == mathclap) { + // y1---- \ / + // \ / + // y2--- -------->-<-------- + // / \. + // y3---- / \. + // | | | | | + // x1 x2 x3 x4 x5 + + int const x1 = x; + int const x5 = x + dim.wid; + int const x3 = x + dim.wid / 2; + int const x2 = std::max(x1, x3 - arrow_size); + int const x4 = std::min(x5, x3 + arrow_size); + + int const y2 = y + (dim.des - dim.asc) / 2; + int const y1 = y2 - arrow_size; + int const y3 = y2 + arrow_size; + + // left arrow + pi.pain.line(x2, y3, x3, y2, Color_added_space); + pi.pain.line(x2, y1, x3, y2, Color_added_space); + + // right arrow + pi.pain.line(x4, y3, x3, y2, Color_added_space); + pi.pain.line(x4, y1, x3, y2, Color_added_space); + + // joining line + pi.pain.line(x1, y2, x5, y2, Color_added_space); + } + + else if (kind_ == mathllap) { + // y1---- \. + // \. + // y2--- ------------------> + // / + // y3---- / + // | | | + // x1 x2 x3 + + int const x1 = x; + int const x3 = x + dim.wid; + int const x2 = std::max(x1, x3 - arrow_size); + + int const y2 = y + (dim.des - dim.asc) / 2; + int const y1 = y2 - arrow_size; + int const y3 = y2 + arrow_size; + + // right arrow + pi.pain.line(x3, y2, x2, y3, Color_added_space); + pi.pain.line(x3, y2, x2, y1, Color_added_space); + + // joining line + pi.pain.line(x1, y2, x3, y2, Color_added_space); + } + + else if (kind_ == mathrlap) { + // y1---- / + // / + // y2--- <------------------ + // \. + // y3---- \. + // | | | + // x1 x2 x3 + + int const x1 = x; + int const x3 = x + dim.wid; + int const x2 = std::min(x3, x + arrow_size); + + int const y2 = y + (dim.des - dim.asc) / 2; + int const y1 = y2 - arrow_size; + int const y3 = y2 + arrow_size; + + // left arrow + pi.pain.line(x1, y2, x2, y3, Color_added_space); + pi.pain.line(x1, y2, x2, y1, Color_added_space); + + // joining line + pi.pain.line(x1, y2, x3, y2, Color_added_space); + } + + else if (kind_ == smash) { + // y1--------- + // | + // y2----- \ | / + // \ / + // y3-------- | + // / \. + // y4----- / | \. + // | + // y5--------- + // | | | + // / | \. + // x1 x2 x3 + + int const x2 = x + dim.wid / 2; + int const x1 = x2 - arrow_size; + int const x3 = x2 + arrow_size; + + int const y1 = y - dim.asc; + int const y5 = y + dim.des; + int const y3 = y; + int const y2 = std::max(y1, y3 - arrow_size); + int const y4 = std::min(y5, y3 + arrow_size); + + // top arrow + pi.pain.line(x1, y2, x2, y3, Color_added_space); + pi.pain.line(x3, y2, x2, y3, Color_added_space); + + // bottom arrow + pi.pain.line(x1, y4, x2, y3, Color_added_space); + pi.pain.line(x3, y4, x2, y3, Color_added_space); + + // joining line + pi.pain.line(x2, y1, x2, y5, Color_added_space); + } + drawMarkers(pi, x, y); } @@ -130,6 +250,18 @@ void InsetMathPhantom::write(WriteStream & os) const case hphantom: os << "\\hphantom{"; break; + case smash: + os << "\\smash{"; + break; + case mathclap: + os << "\\mathclap{"; + break; + case mathllap: + os << "\\mathllap{"; + break; + case mathrlap: + os << "\\mathrlap{"; + break; } os << cell(0) << '}'; } @@ -147,6 +279,18 @@ void InsetMathPhantom::normalize(NormalStream & os) const case hphantom: os << "[hphantom "; break; + case smash: + os << "[smash "; + break; + case mathclap: + os << "[mathclap "; + break; + case mathllap: + os << "[mathllap "; + break; + case mathrlap: + os << "[mathrlap "; + break; } os << cell(0) << ']'; } @@ -164,8 +308,44 @@ void InsetMathPhantom::infoize(odocstream & os) const case hphantom: os << "Hphantom"; break; + case smash: + os << "Smash"; + break; + case mathllap: + os << "Mathllap"; + break; + case mathclap: + os << "Mathclap"; + break; + case mathrlap: + os << "Mathrlap"; + break; + } +} + + +void InsetMathPhantom::validate(LaTeXFeatures & features) const +{ + InsetMathNest::validate(features); + switch (kind_) { + case phantom: + case vphantom: + case hphantom: + case smash: + break; + case mathclap: + case mathllap: + case mathrlap: + features.require("mathtools"); + break; } } +bool InsetMathPhantom::visibleContents() const +{ + return kind_ == phantom || kind_ == vphantom || kind_ == vphantom; +} + + } // namespace lyx diff --git a/src/mathed/InsetMathPhantom.h b/src/mathed/InsetMathPhantom.h index 9cce40df23..8221171b1d 100644 --- a/src/mathed/InsetMathPhantom.h +++ b/src/mathed/InsetMathPhantom.h @@ -23,7 +23,11 @@ public: enum Kind { phantom, vphantom, - hphantom + hphantom, + smash, + mathclap, + mathllap, + mathrlap }; /// explicit InsetMathPhantom(Buffer * buf, Kind); @@ -43,6 +47,10 @@ public: void mathmlize(MathStream &) const {} /// Nothing for HTML void htmlize(HtmlStream &) const {} + /// request "external features" + void validate(LaTeXFeatures & features) const; + /// Does the contents appear in LaTeX output? + bool visibleContents() const; private: /// diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp index ee35102cf2..00e585062f 100644 --- a/src/mathed/MathFactory.cpp +++ b/src/mathed/MathFactory.cpp @@ -501,6 +501,14 @@ MathAtom createInsetMath(docstring const & s, Buffer * buf) return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::phantom)); if (s == "vphantom") return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::vphantom)); + if (s == "smash") + return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::smash)); + if (s == "mathclap") + return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::mathclap)); + if (s == "mathllap") + return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::mathllap)); + if (s == "mathrlap") + return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::mathrlap)); if (s == "ensuremath") return MathAtom(new InsetMathEnsureMath(buf)); if (isSpecialChar(s)) -- 2.39.2