]> git.lyx.org Git - features.git/commitdiff
support for the LaTeX commands \x***arrow
authorUwe Stöhr <uwestoehr@lyx.org>
Sun, 24 Aug 2014 22:44:09 +0000 (00:44 +0200)
committerUwe Stöhr <uwestoehr@lyx.org>
Sun, 24 Aug 2014 22:44:09 +0000 (00:44 +0200)
- this patch supports the \x***arrow commands provided by the mathtool package
- fileformat change

lib/lyx2lyx/LyX.py
lib/lyx2lyx/lyx_2_2.py
src/mathed/InsetMathNest.cpp
src/mathed/InsetMathXArrow.cpp
src/mathed/MathFactory.cpp
src/mathed/MathParser.cpp
src/mathed/MathSupport.cpp
src/version.h

index 63645245d57038cd1552cb1e1e3e1d19b4ef7f93..5f23eaf09b720a2c1de48f3fd7d41fb1b079e854 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,478), minor_versions("2.2", 0))
+                   ("2_2", range(475,479), minor_versions("2.2", 0))
                   ]
 
 ####################################################################
index f15b0c6e9e411a0db7ffcf4382f9de94fc63b402..59dbfbc07e303b8cd02b1d5c5a49da5b59707155 100644 (file)
@@ -30,7 +30,7 @@ import sys, os
 #  find_token_backwards, is_in_inset, get_value, get_quoted_value, \
 #  del_token, check_token, get_option_value
   
-#from lyx2lyx_tools import add_to_preamble, insert_to_preamble, \
+from lyx2lyx_tools import add_to_preamble#, insert_to_preamble, \
 #  put_cmd_in_ert, lyx2latex, latex_length, revert_flex_inset, \
 #  revert_font_attrs, hex2ratio, str2bool
 
@@ -292,11 +292,52 @@ def revert_swissgerman(document):
         j = j + 1
 
 
+def revert_use_package(document, pkg, commands, oldauto):
+    # oldauto defines how the version we are reverting to behaves:
+    # if it is true, the old version uses the package automatically.
+    # if it is false, the old version never uses the package.
+    regexp = re.compile(r'(\\use_package\s+%s)' % pkg)
+    i = find_re(document.header, regexp, 0)
+    value = "1" # default is auto
+    if i != -1:
+        value = get_value(document.header, "\\use_package" , i).split()[1]
+        del document.header[i]
+    if value == "2": # on
+        add_to_preamble(document, ["\\usepackage{" + pkg + "}"])
+    elif value == "1" and not oldauto: # auto
+        i = 0
+        while True:
+            i = find_token(document.body, '\\begin_inset Formula', i)
+            if i == -1:
+                return
+            j = find_end_of_inset(document.body, i)
+            if j == -1:
+                document.warning("Malformed LyX document: Can't find end of Formula inset at line " + str(i))
+                i += 1
+                continue
+            code = "\n".join(document.body[i:j])
+            for c in commands:
+                if code.find("\\%s" % c) != -1:
+                    add_to_preamble(document, ["\\usepackage{" + pkg + "}"])
+                    return
+            i = j
+
+
+mathtools_commands = ["xhookrightarrow", "xhookleftarrow", "xRightarrow", \
+                "xrightharpoondown", "xrightharpoonup", "xrightleftharpoons", \
+                "xLeftarrow", "xleftharpoondown", "xleftharpoonup", \
+                "xleftrightarrow", "xLeftrightarrow", "xleftrightharpoons", \
+                "xmapsto"]
+def revert_xarrow(document):
+    "remove use_package mathtools"
+    revert_use_package(document, "mathtools", mathtools_commands, False)
+
+  
 ##
 # Conversion hub
 #
 
-supported_versions = ["2.2.0","2.2"]
+supported_versions = ["2.2.0", "2.2"]
 convert = [
            [475, [convert_separator]],
            # nothing to do for 476: We consider it a bug that older versions
@@ -304,9 +345,11 @@ convert = [
            # want to hardcode amsmath off.
            [476, []],
            [477, []],
+           [478, []]
           ]
 
 revert =  [
+           [477, [revert_xarrow]],
            [476, [revert_swissgerman]],
            [475, [revert_smash]],
            [474, [revert_separator]]
index 12615e6865f926187f4b97f245bede53db1c2cf0..fc398e4e99f462a7a6015b91faa76b8c64abdb93 100644 (file)
@@ -2127,8 +2127,21 @@ MathCompletionList::MathCompletionList(Cursor const & cur)
        globals.push_back(from_ascii("\\framebox"));
        globals.push_back(from_ascii("\\makebox"));
        globals.push_back(from_ascii("\\kern"));
+       globals.push_back(from_ascii("\\xhookrightarrow"));
+       globals.push_back(from_ascii("\\xhookleftarrow"));
        globals.push_back(from_ascii("\\xrightarrow"));
+       globals.push_back(from_ascii("\\xRightarrow"));
+       globals.push_back(from_ascii("\\xrightharpoondown"));
+       globals.push_back(from_ascii("\\xrightharpoonup"));
+       globals.push_back(from_ascii("\\xrightleftharpoons"));
        globals.push_back(from_ascii("\\xleftarrow"));
+       globals.push_back(from_ascii("\\xLeftarrow"));
+       globals.push_back(from_ascii("\\xleftharpoondown"));
+       globals.push_back(from_ascii("\\xleftharpoonup"));
+       globals.push_back(from_ascii("\\xleftrightarrow"));
+       globals.push_back(from_ascii("\\xLeftrightarrow"));
+       globals.push_back(from_ascii("\\xleftrightharpoons"));
+       globals.push_back(from_ascii("\\xmapsto"));
        globals.push_back(from_ascii("\\split"));
        globals.push_back(from_ascii("\\gathered"));
        globals.push_back(from_ascii("\\aligned"));
index 7439970fb4c7a77d84d6cc5f10fa0eb6c236b1b0..b91c4ce21dbc43d7bec686e75b54afa323326ed1 100644 (file)
@@ -80,8 +80,38 @@ void InsetMathXArrow::normalize(NormalStream & os) const
 
 void InsetMathXArrow::mathmlize(MathStream & ms) const
 {
-       char const * const arrow = name_ == "xleftarrow" 
-                       ? "&larr;" : "&rarr;";
+       char const * arrow;
+       
+       if (name_ == "xleftarrow")
+               arrow = "&larr;";
+       else if (name_ == "xrightarrow")
+               arrow = "&rarr;";
+       else if (name_ == "xhookleftarrow")
+               arrow = "&larrhk;";
+       else if (name_ == "xhookrightarrow")
+               arrow = "&rarrhk;";
+       else if (name_ == "xLeftarrow")
+               arrow = "&lArr;";
+       else if (name_ == "xRightarrow")
+               arrow = "&rArr;";
+       else if (name_ == "xleftrightarrow")
+               arrow = "&leftrightarrow;";
+       else if (name_ == "xLeftrightarrow")
+               arrow = "&Leftrightarrow;";
+       else if (name_ == "xleftharpoondown")
+               arrow = "&leftharpoondown;";
+       else if (name_ == "xleftharpoonup")
+               arrow = "&leftharpoonup;";
+       else if (name_ == "xleftrightharpoons")
+               arrow = "&leftrightharpoons;";
+       else if (name_ == "xrightharpoondown")
+               arrow = "&rightharpoondown;";
+       else if (name_ == "xrightharpoonup")
+               arrow = "&rightharpoonup;";
+       else if (name_ == "xrightleftharpoons")
+               arrow = "&rightleftharpoons;";
+       else if (name_ == "xmapsto")
+               arrow = "&mapsto;";
        ms << "<munderover accent='false' accentunder='false'>"
           << arrow << cell(1) << cell(0)
           << "</munderover>";
@@ -90,8 +120,38 @@ void InsetMathXArrow::mathmlize(MathStream & ms) const
 
 void InsetMathXArrow::htmlize(HtmlStream & os) const
 {
-       char const * const arrow = name_ == "xleftarrow" 
-                       ? "&larr;" : "&rarr;";
+       char const * arrow;
+
+       if (name_ == "xleftarrow")
+               arrow = "&larr;";
+       else if (name_ == "xrightarrow")
+               arrow = "&rarr;";
+       else if (name_ == "xhookleftarrow")
+               arrow = "&larrhk;";
+       else if (name_ == "xhookrightarrow")
+               arrow = "&rarrhk;";
+       else if (name_ == "xLeftarrow")
+               arrow = "&lArr;";
+       else if (name_ == "xRightarrow")
+               arrow = "&rArr;";
+       else if (name_ == "xleftrightarrow")
+               arrow = "&leftrightarrow;";
+       else if (name_ == "xLeftrightarrow")
+               arrow = "&Leftrightarrow;";
+       else if (name_ == "xleftharpoondown")
+               arrow = "&leftharpoondown;";
+       else if (name_ == "xleftharpoonup")
+               arrow = "&leftharpoonup;";
+       else if (name_ == "xleftrightharpoons")
+               arrow = "&leftrightharpoons;";
+       else if (name_ == "xrightharpoondown")
+               arrow = "&rightharpoondown;";
+       else if (name_ == "xrightharpoonup")
+               arrow = "&rightharpoonup;";
+       else if (name_ == "xrightleftharpoons")
+               arrow = "&rightleftharpoons;";
+       else if (name_ == "xmapsto")
+               arrow = "&mapsto;";
        os << MTag("span", "class='xarrow'")
                 << MTag("span", "class='xatop'") << cell(0) << ETag("span")
                 << MTag("span", "class='xabottom'") << arrow << ETag("span")
@@ -101,7 +161,10 @@ void InsetMathXArrow::htmlize(HtmlStream & os) const
 
 void InsetMathXArrow::validate(LaTeXFeatures & features) const
 {
-       features.require("amsmath");
+       if (name_ == "xleftarrow" || name_ == "xrightarrow")
+               features.require("amsmath");
+       else
+               features.require("mathtools");
        if (features.runparams().math_flavor == OutputParams::MathAsHTML)
                // CSS adapted from eLyXer
                features.addCSSSnippet(
index 382f037e8920c93084c999743cd44ed71b6c6875..951d506a46b63915093b6c00ad2e60a7a72d9363 100644 (file)
@@ -466,7 +466,14 @@ MathAtom createInsetMath(docstring const & s, Buffer * buf)
 
        if (s == "Diagram")
                return MathAtom(new InsetMathDiagram(buf));
-       if (s == "xrightarrow" || s == "xleftarrow")
+       if (s == "xrightarrow" || s == "xleftarrow" ||
+               s == "xhookrightarrow" || s == "xhookleftarrow" ||
+               s == "xRightarrow" || s == "xLeftarrow" ||
+               s == "xleftrightarrow" || s == "xLeftrightarrow" ||
+               s == "xrightharpoondown" || s == "xrightharpoonup" ||
+               s == "xleftharpoondown" || s == "xleftharpoonup" ||
+               s == "xleftrightharpoons" || s == "xrightleftharpoons" ||
+               s == "xmapsto")
                return MathAtom(new InsetMathXArrow(buf, s));
        if (s == "split" || s == "alignedat")
                return MathAtom(new InsetMathSplit(buf, s));
index de2d4b691af996ee0b4295c836c1d181b632df62..2933c09d716b94f92ead5d2d7c9b253d2f2dabdd 100644 (file)
@@ -1492,6 +1492,18 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                        parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
                }
 
+               else if (t.cs() == "xhookrightarrow" || t.cs() == "xhookleftarrow" ||
+                            t.cs() == "xRightarrow" || t.cs() == "xLeftarrow" ||
+                                t.cs() == "xleftrightarrow" || t.cs() == "xLeftrightarrow" ||
+                                t.cs() == "xrightharpoondown" || t.cs() == "xrightharpoonup" ||
+                                t.cs() == "xleftharpoondown" || t.cs() == "xleftharpoonup" ||
+                                t.cs() == "xleftrightharpoons" || t.cs() == "xrightleftharpoons" ||
+                                t.cs() == "xmapsto") {
+                       cell->push_back(createInsetMath(t.cs(), buf));
+                       parse(cell->back().nucleus()->cell(1), FLAG_OPTION, mode);
+                       parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
+               }
+
                else if (t.cs() == "ref" || t.cs() == "eqref" || t.cs() == "prettyref"
                          || t.cs() == "pageref" || t.cs() == "vpageref" || t.cs() == "vref") {
                        cell->push_back(MathAtom(new InsetMathRef(buf, t.cs())));
index a715360112c8643dfd66c9364c6eca76acc32f43..7d15c42672f2357c0a053af1b642ec9b6b8a49a1 100644 (file)
@@ -113,6 +113,95 @@ double const brace[] = {
 };
 
 
+double const mapsto[] = {
+       2, 3,
+       0.75, 0.015, 0.95, 0.5, 0.75, 0.985,
+       1, 0.015, 0.475, 0.945, 0.475,
+       1, 0.015, 0.015, 0.015, 0.985,
+       0
+};
+
+
+double const lhook[] = {
+       2, 3,
+       0.25, 0.015, 0.05, 0.5, 0.25, 0.985,
+       1, 0.015, 0.475, 0.7, 0.475,
+       2, 5,
+       0.7, 0.015, 0.825, 0.15, 0.985, 0.25,
+       0.825, 0.35, 0.7, 0.475,
+       0
+};
+
+
+double const rhook[] = {
+       2, 3,
+       0.75, 0.015, 0.95, 0.5, 0.75, 0.985,
+       1, 0.3, 0.475, 0.985, 0.475,
+       2, 5,
+       0.3, 0.015, 0.175, 0.15, 0.05, 0.25,
+       0.175, 0.35, 0.3, 0.475,
+       0
+};
+
+
+double const LRArrow[] = {
+       2, 3,
+       0.25, 0.015, 0.05, 0.5, 0.25, 0.985,
+       2, 3,
+       0.75, 0.015, 0.95, 0.5, 0.75, 0.985,
+       1, 0.2, 0.8, 0.8, 0.8,
+       1, 0.2, 0.2, 0.8, 0.2,
+       0
+};
+
+
+double const LArrow[] = {
+       2, 3,
+       0.25, 0.015, 0.05, 0.5, 0.25, 0.985,
+       1, 0.2, 0.8, 0.985, 0.8,
+       1, 0.2, 0.2, 0.985, 0.2,
+       0
+};
+
+
+double const lharpoondown[] = {
+       2, 2,
+       0.015, 0.5, 0.25, 0.985,
+       1, 0.02, 0.475, 0.985, 0.475,
+       0
+};
+
+
+double const lharpoonup[] = {
+       2, 2,
+       0.25, 0.015, 0.015, 0.5,
+       1, 0.02, 0.525, 0.985, 0.525,
+       0
+};
+
+
+double const lrharpoons[] = {
+       2, 2,
+       0.25, 0.015, 0.015, 0.225,
+       1, 0.02, 0.23, 0.985, 0.23,
+       2, 2,
+       0.75, 0.985, 0.985, 0.775,
+       1, 0.02, 0.7, 0.980, 0.7,
+       0
+};
+
+
+double const rlharpoons[] = {
+       2, 2,
+       0.75, 0.015, 0.985, 0.225,
+       1, 0.02, 0.23, 0.985, 0.23,
+       2, 2,
+       0.25, 0.985, 0.015, 0.775,
+       1, 0.02, 0.7, 0.980, 0.7,
+       0
+};
+
+
 double const arrow[] = {
        4, 7,
        0.0150, 0.7500, 0.2000, 0.6000, 0.3500, 0.3500,
@@ -283,23 +372,36 @@ struct named_deco_struct {
 
 named_deco_struct deco_table[] = {
        // Decorations
-       {"widehat",             angle,    3 },
-       {"widetilde",           tilde,    0 },
-       {"underbar",            hline,    0 },
-       {"underline",           hline,    0 },
-       {"overline",            hline,    0 },
-       {"underbrace",          brace,    1 },
-       {"overbrace",           brace,    3 },
-       {"overleftarrow",       arrow,    1 },
-       {"overrightarrow",      arrow,    3 },
-       {"overleftrightarrow",  udarrow,  1 },
-       {"xleftarrow",          arrow,    1 },
-       {"xrightarrow",         arrow,    3 },
-       {"underleftarrow",      arrow,    1 },
-       {"underrightarrow",     arrow,    3 },
-       {"underleftrightarrow", udarrow,  1 },
-       {"undertilde",          tilde,    0 },
-       {"utilde",              tilde,    0 },
+       {"widehat",             angle,        3 },
+       {"widetilde",           tilde,        0 },
+       {"underbar",            hline,        0 },
+       {"underline",           hline,        0 },
+       {"overline",            hline,        0 },
+       {"underbrace",          brace,        1 },
+       {"overbrace",           brace,        3 },
+       {"overleftarrow",       arrow,        1 },
+       {"overrightarrow",      arrow,        3 },
+       {"overleftrightarrow",  udarrow,      1 },
+       {"xhookleftarrow",      lhook,        0 },
+       {"xhookrightarrow",     rhook,        0 },
+       {"xleftarrow",          arrow,        1 },
+       {"xLeftarrow",          LArrow,       0 },
+       {"xleftharpoondown",    lharpoondown, 0 },
+       {"xleftharpoonup",      lharpoonup,   0 },
+       {"xleftrightharpoons",  lrharpoons,   0 },
+       {"xleftrightarrow",     udarrow,      1 },
+       {"xLeftrightarrow",     LRArrow,      0 },
+       {"xmapsto",             mapsto,       0 },
+       {"xrightarrow",         arrow,        3 },
+       {"xRightarrow",         LArrow,       2 },
+       {"xrightharpoondown",   lharpoonup,   2 },
+       {"xrightharpoonup",     lharpoondown, 2 },
+       {"xrightleftharpoons",  rlharpoons,   0 },
+       {"underleftarrow",      arrow,        1 },
+       {"underrightarrow",     arrow,        3 },
+       {"underleftrightarrow", udarrow,      1 },
+       {"undertilde",          tilde,        0 },
+       {"utilde",              tilde,        0 },
 
        // Delimiters
        {"(",              parenth,    0 },
index f7eb1e1fd4c3b3005e4c5f64a9c9bff27e07e409..30bb4e279d90a03f12b1e913c4b57a81961e1bd0 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 477 // spitz: support for swissgerman
-#define LYX_FORMAT_TEX2LYX 477
+#define LYX_FORMAT_LYX 478 // uwestoehr: mathtools' x***arrow commands
+#define LYX_FORMAT_TEX2LYX 478
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER