]> git.lyx.org Git - features.git/commitdiff
Native support for \smash[t] and \smash[b]
authorGeorg Baum <baum@lyx.org>
Tue, 27 May 2014 20:10:02 +0000 (22:10 +0200)
committerGeorg Baum <baum@lyx.org>
Tue, 27 May 2014 20:13:58 +0000 (22:13 +0200)
This is a follow-up of bug #8967. The implementation is self-explaining, the
only part which needs a comment is lyx2lyx: Since a 100% correct solution is
not possible, it has been decided not to switch amsmath off in the forward
conversion if no other ams command than \smash[t] and \smash[b] is used, but
to consider it a bug that older versions do not load amsmath automatically for
these commands. In the backward direction it is easy to keep the document
compilable, so just do that.

25 files changed:
development/FORMAT
lib/Makefile.am
lib/images/math/smashb.png [new file with mode: 0644]
lib/images/math/smasht.png [new file with mode: 0644]
lib/lyx2lyx/LyX.py
lib/lyx2lyx/lyx_2_2.py
lib/ui/stdtoolbars.inc
src/mathed/InsetMathPhantom.cpp
src/mathed/InsetMathPhantom.h
src/mathed/MathFactory.cpp
src/mathed/MathParser.cpp
src/tex2lyx/test/CJK.lyx.lyx
src/tex2lyx/test/CJKutf8.lyx.lyx
src/tex2lyx/test/DummyDocument.lyx.lyx
src/tex2lyx/test/Dummy~Document.lyx.lyx
src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
src/tex2lyx/test/algo2e.lyx.lyx
src/tex2lyx/test/box-color-size-space-align.lyx.lyx
src/tex2lyx/test/test-insets.lyx.lyx
src/tex2lyx/test/test-modules.lyx.lyx
src/tex2lyx/test/test-refstyle-theorems.lyx.lyx
src/tex2lyx/test/test-structure.lyx.lyx
src/tex2lyx/test/test.lyx.lyx
src/tex2lyx/test/verbatim.lyx.lyx
src/version.h

index 74cd8ce6979700ed295541c2ca2892d279e212e9..51bc639c9506561db5b981855ae37d2306e25702 100644 (file)
@@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
 
 -----------------------
 
+2013-05-27 Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+       * Format incremented to 476
+         Native support for \smash[t] and \smash[b] with automatic amsmath
+         loading
+
 2014-05-05 Enrico Forestieri <forenr@lyx.org>
        * Format incremented to 475
          New Separator insets. The parbreak separator introduces a LaTeX
index 6188f87e12ceba0a94cc52466085ad5e2c65d64c..1aaec8b9d19780b9d4a4a346ad156adc7acb4918 100644 (file)
@@ -1180,6 +1180,8 @@ dist_imagesmath_DATA = \
        images/math/smallsetminus.png \
        images/math/smallsmile.png \
        images/math/smash.png \
+       images/math/smashb.png \
+       images/math/smasht.png \
        images/math/smile.png \
        images/math/smiley.png \
        images/math/space.png \
diff --git a/lib/images/math/smashb.png b/lib/images/math/smashb.png
new file mode 100644 (file)
index 0000000..f64629e
Binary files /dev/null and b/lib/images/math/smashb.png differ
diff --git a/lib/images/math/smasht.png b/lib/images/math/smasht.png
new file mode 100644 (file)
index 0000000..b957c48
Binary files /dev/null and b/lib/images/math/smasht.png differ
index e7b2186706ae047c42b040562394f5770bad1a34..e37691f273d11969af9bcea2828ad031f5396f7f 100644 (file)
@@ -85,7 +85,7 @@ format_relation = [("0_06",    [200], minor_versions("0.6" , 4)),
                    ("1_6", range(277,346), minor_versions("1.6" , 10)),
                    ("2_0", range(346,414), minor_versions("2.0", 8)),
                    ("2_1", range(414,475), minor_versions("2.1", 0)),
-                   ("2_2", range(475,476), minor_versions("2.2", 0))
+                   ("2_2", range(475,477), minor_versions("2.2", 0))
                   ]
 
 ####################################################################
index 64ff1086b48511b24828905981b110313ad50751..517c8978d5776e48c5dc37dee0cb356b70db4648 100644 (file)
@@ -244,6 +244,37 @@ def revert_separator(document):
         i = i + 1
 
 
+def revert_smash(document):
+    " Set amsmath to on if smash commands are used "
+
+    commands = ["smash[t]", "smash[b]"]
+    i = find_token(document.header, "\\use_package amsmath", 0)
+    if i == -1:
+        document.warning("Malformed LyX document: Can't find \\use_package amsmath.")
+        return;
+    value = get_value(document.header, "\\use_package amsmath", i).split()[1]
+    if value != "1":
+        # nothing to do if package is not auto but on or off
+        return;
+    j = 0
+    while True:
+        j = find_token(document.body, '\\begin_inset Formula', j)
+        if j == -1:
+            return
+        k = find_end_of_inset(document.body, j)
+        if k == -1:
+            document.warning("Malformed LyX document: Can't find end of Formula inset at line " + str(j))
+            j += 1
+            continue
+        code = "\n".join(document.body[j:k])
+        for c in commands:
+            if code.find("\\%s" % c) != -1:
+                # set amsmath to on, since it is loaded by the newer format
+                document.header[i] = "\\use_package amsmath 2"
+                return
+        j = k
+
+
 ##
 # Conversion hub
 #
@@ -251,9 +282,14 @@ def revert_separator(document):
 supported_versions = ["2.2.0","2.2"]
 convert = [
            [475, [convert_separator]],
+           # nothing to do for 476: We consider it a bug that older versions
+           # did not load amsmath automatically for these commands, and do not
+           # want to hardcode amsmath off.
+           [476, []],
           ]
 
 revert =  [
+           [475, [revert_smash]],
            [474, [revert_separator]]
           ]
 
index e8ce0b9b39cd931321e52bb583922f4d18a423e7..163beab99b683afdc6d101872b9d32e8741b57fb 100644 (file)
@@ -353,6 +353,8 @@ ToolbarSet
                Item "Horizontal phantom        \\hphantom" "math-insert \hphantom"
                Item "Vertical phantom  \\vphantom" "math-insert \vphantom"
                Item "Smash \\smash" "math-insert \smash"
+               Item "Top smash \\smasht" "math-insert \smasht"
+               Item "Bottom smash \\smashb" "math-insert \smashb"
                Item "Left overlap \\mathllap" "math-insert \mathllap"
                Item "Center overlap \\mathclap" "math-insert \mathclap"
                Item "Right overlap \\mathrlap" "math-insert \mathrlap"
index b8c965b21cfde45139b45abc08e6d6e2d654d7e3..9d6295bb060ccff99a56e3730571021b72b146b5 100644 (file)
@@ -197,7 +197,7 @@ void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
                pi.pain.line(x1, y2, x3, y2, Color_added_space);
        }
 
-       else if (kind_ == smash) {
+       else if (kind_ == smash || kind_ == smasht || kind_ == smashb) {
                // y1---------
                //            |
                // y2-----  \ | /
@@ -222,15 +222,24 @@ void InsetMathPhantom::draw(PainterInfo & pi, int x, int y) const
                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);
+               if (kind_ != smashb) {
+                       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);
+               if (kind_ != smasht) {
+                       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);
+               if (kind_ == smasht)
+                       pi.pain.line(x2, y1, x2, y3, Color_added_space);
+               else if (kind_ == smashb)
+                       pi.pain.line(x2, y3, x2, y5, Color_added_space);
+               else
+                       pi.pain.line(x2, y1, x2, y5, Color_added_space);
        }
 
        drawMarkers(pi, x, y);
@@ -255,6 +264,12 @@ void InsetMathPhantom::write(WriteStream & os) const
        case smash:
                os << "\\smash{";
                break;
+       case smasht:
+               os << "\\smash[t]{";
+               break;
+       case smashb:
+               os << "\\smash[b]{";
+               break;
        case mathclap:
                os << "\\mathclap{";
                break;
@@ -284,6 +299,12 @@ void InsetMathPhantom::normalize(NormalStream & os) const
        case smash:
                os << "[smash ";
                break;
+       case smasht:
+               os << "[smasht ";
+               break;
+       case smashb:
+               os << "[smashb ";
+               break;
        case mathclap:
                os << "[mathclap ";
                break;
@@ -313,6 +334,12 @@ void InsetMathPhantom::infoize(odocstream & os) const
        case smash:
                os << "Smash";
                break;
+       case smasht:
+               os << "Smashtop";
+               break;
+       case smashb:
+               os << "Smashbottom";
+               break;
        case mathllap:
                os << "Mathllap";
                break;
@@ -335,6 +362,10 @@ void InsetMathPhantom::validate(LaTeXFeatures & features) const
        case hphantom:
        case smash:
                break;
+       case smasht:
+       case smashb:
+               features.require("amsmath");
+               break;
        case mathclap:
        case mathllap:
        case mathrlap:
index 8221171b1d4330987812efe3dd856a94c0d5ea8d..63b8ea28de772844ef04f35b64132e74d3dcb258 100644 (file)
@@ -25,6 +25,8 @@ public:
                vphantom,
                hphantom,
                smash,
+               smasht,
+               smashb,
                mathclap,
                mathllap,
                mathrlap
index d19899866fb25c7c8509107024a48ed168ef1704..85fdf478565f6fa6ad11d4562161f6ec55839932 100644 (file)
@@ -561,6 +561,11 @@ MathAtom createInsetMath(docstring const & s, Buffer * buf)
                return MathAtom(new InsetMathCancelto(buf));
        if (s == "smash")
                return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::smash));
+       // The following 2 string values are only for math toolbar use, no LaTeX names
+       if (s == "smashb")
+               return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::smashb));
+       if (s == "smasht")
+               return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::smasht));
        if (s == "mathclap")
                return MathAtom(new InsetMathPhantom(buf, InsetMathPhantom::mathclap));
        if (s == "mathllap")
index 1c7f2ff0ad3abc79a452d187f29378c3eb4d7a15..234bfd8728c0367f6eaee30840588703ff981112 100644 (file)
@@ -1849,16 +1849,22 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                        skipSpaces();
                        if (nextToken().asInput() == "[") {
                                // Since the phantom inset cannot handle optional arguments
-                               // we must not create an InsetMathPhantom (bug 8967).
+                               // other than b and t, we must not create an InsetMathPhantom
+                               // if opt is different from b and t (bug 8967).
                                docstring const opt = parse_verbatim_option();
-                               docstring const arg = parse_verbatim_item();
-                               cell->push_back(MathAtom(new MathMacro(buf, t.cs())));
-                               MathData ar;
-                               mathed_parse_cell(ar, '[' + opt + ']', mode_);
-                               cell->append(ar);
-                               ar = MathData();
-                               mathed_parse_cell(ar, '{' + arg + '}', mode_);
-                               cell->append(ar);
+                               if (opt == "t" || opt == "b") {
+                                       cell->push_back(createInsetMath(t.cs() + opt, buf));
+                                       parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
+                               } else {
+                                       docstring const arg = parse_verbatim_item();
+                                       cell->push_back(MathAtom(new MathMacro(buf, t.cs())));
+                                       MathData ar;
+                                       mathed_parse_cell(ar, '[' + opt + ']', mode_);
+                                       cell->append(ar);
+                                       ar = MathData();
+                                       mathed_parse_cell(ar, '{' + arg + '}', mode_);
+                                       cell->append(ar);
+                               }
                        }
                        else {
                                cell->push_back(createInsetMath(t.cs(), buf));
index a113614ef5b78ed47c7eb90ac8b078552ccde5b4..f934830c6884deb2185e519740c0abd477335229 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 475
+\lyxformat 476
 \begin_document
 \begin_header
 \textclass article
index 6330530e56502912f982daad538198fedb3b370c..0834a8e3c0c4c21be449e2975fef2f0a466a94c8 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 475
+\lyxformat 476
 \begin_document
 \begin_header
 \textclass article
index 58a18f2b6a1c0a544153fe54af91e4a224436254..50b105eb1db47c378569dd36ca3cd0c722671be4 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 475
+\lyxformat 476
 \begin_document
 \begin_header
 \textclass article
index 7e97f2b2d916ebf7bb828ba48dbe731a091c2a69..f379c6ef690eff5df108cb50df7b7062dc08007f 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 475
+\lyxformat 476
 \begin_document
 \begin_header
 \textclass article
index 8864033a97d454aa171e564913aed5155b955ed3..2917ee21ed4200f60676a1278071b0a0446a8a95 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 475
+\lyxformat 476
 \begin_document
 \begin_header
 \textclass article
index 5b8db5b24564c2617e3c1414b9f006472f2a0819..e3ac0cb2b60ff8bc9f495cd10d0c0e292a0b3374 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 475
+\lyxformat 476
 \begin_document
 \begin_header
 \textclass article
index f4c97b1571da9f7e7b1b96cdb7dc7cefb9ee7458..4199340333efbebb4bbf1f139377529856fc9ca3 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 475
+\lyxformat 476
 \begin_document
 \begin_header
 \textclass article
index bc8e98fb33cccc6b5d90ad1d3b92da375a3e4c74..69a2da3cd20ab33b461a5ec441b183ab3b4a0682 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 475
+\lyxformat 476
 \begin_document
 \begin_header
 \textclass article
index 051052722974c685b59a9db036bb26069a6c746a..6ca4148b52838f6a8c2f58823745e9dcc819bd56 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 475
+\lyxformat 476
 \begin_document
 \begin_header
 \textclass amsart
index bb8ec5618113e00a837487a1f9db2a271a07a7f6..01ddac15d9873cc926bb97ffeaf631cb2fb6b034 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 475
+\lyxformat 476
 \begin_document
 \begin_header
 \textclass book
index 2752a2720300cd197a050a59dc6ca613ddc2431a..7bacf5335d7155cf9dd9089071991837629a0fe1 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 475
+\lyxformat 476
 \begin_document
 \begin_header
 \textclass article
index 344470a33ca4c5b6d19976155b0f6d7881ff793d..2d5371b2f931f9edf9c654a16ca6f7056a137432 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 475
+\lyxformat 476
 \begin_document
 \begin_header
 \textclass article
index 68fbf23256ddf8f276e8c4d4ec32a1123c22e249..4435064beca664f76f179ba52481ba49f85d0393 100644 (file)
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.2
-\lyxformat 475
+\lyxformat 476
 \begin_document
 \begin_header
 \textclass article
index e98f3a0d8bf2f8bdcd60e1ae147e37f25937ab8f..be963857e5326142f3eb7ca3455e726c9c0588ee 100644 (file)
@@ -30,8 +30,8 @@ extern char const * const lyx_version_info;
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 475 // ef: new separator inset
-#define LYX_FORMAT_TEX2LYX 475
+#define LYX_FORMAT_LYX 476 // gb: \smash[t] and \smash[b]
+#define LYX_FORMAT_TEX2LYX 476
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER