The branch, master, has been updated.

- Log -----------------------------------------------------------------

commit 2639734157ed24b07ed86cc3f74650e4acd561aa
Author: Kornel Benko <[email protected]>
Date:   Wed Feb 27 13:14:59 2013 +0100

    Missed in previous commit. Added handling of package cancel to the new 
lyx-format 464

diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index b6155da..dbf4d5c 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -525,6 +525,7 @@ Preamble::Preamble() : one_language(true), 
explicit_babel(false),
        h_use_refstyle            = false;
        h_use_packages["amsmath"]    = "1";
        h_use_packages["amssymb"]    = "0";
+       h_use_packages["cancel"]     = "0";
        h_use_packages["esint"]      = "1";
        h_use_packages["mhchem"]     = "0";
        h_use_packages["mathdots"]   = "0";
@@ -770,7 +771,7 @@ void Preamble::handle_package(Parser &p, string const & 
name,
                ||      is_known(name, known_typewriter_fonts) || 
is_known(name, known_math_fonts))
                ;
 
-       else if (name == "amsmath" || name == "amssymb" ||
+       else if (name == "amsmath" || name == "amssymb" || name == "cancel" ||
                 name == "esint" || name == "mhchem" || name == "mathdots" ||
                 name == "mathtools" || name == "stackrel" ||
                 name == "stmaryrd" || name == "undertilde")

commit 8f36aef17ab47aea0088648285c251415c133337
Author: Kornel Benko <[email protected]>
Date:   Wed Feb 27 13:12:03 2013 +0100

    Added "cancel" to the GUI handled list of LaTeX packages.
    Generalized convert_use_???() and revert_use_???() routines in lyx2lyx.

diff --git a/development/FORMAT b/development/FORMAT
index 5d34fd3..0558362 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -11,6 +11,10 @@ adjustments are made to tex2lyx and bugs are fixed in 
lyx2lyx.
 
 -----------------------
 
+2013-02-27 Kornel Benko <[email protected]>
+        * Format incremented to 464:
+         - Added "cancel" to the GUI handled list of LaTeX packages
+
 2013-02-18 Julien Rioux <[email protected]>
        * Format incremented to 463:
          - Use the LyX name of encodings instead of the LaTeX names.
diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py
index bc4d23b..5feefd8 100644
--- a/lib/lyx2lyx/lyx_2_1.py
+++ b/lib/lyx2lyx/lyx_2_1.py
@@ -370,36 +370,29 @@ def revert_use_packages(document):
         j = j + 1
 
 
-def convert_use_mathtools(document):
-    "insert use_package mathtools"
+def convert_use_package(document, pkg):
     i = find_token(document.header, "\\use_package", 0)
     if i == -1:
         document.warning("Malformed LyX document: Can't find \\use_package.")
         return;
-    j = find_token(document.preamble, "\\usepackage{mathtools}", 0)
+    j = find_token(document.preamble, "\\usepackage{" + pkg + "}", 0)
     if j == -1:
-        document.header.insert(i + 1, "\\use_package mathtools 0")
+        document.header.insert(i + 1, "\\use_package " + pkg + " 0")
     else:
-        document.header.insert(i + 1, "\\use_package mathtools 2")
+        document.header.insert(i + 1, "\\use_package " + pkg + " 2")
         del document.preamble[j]
 
 
-def revert_use_mathtools(document):
-    "remove use_package mathtools"
-    regexp = re.compile(r'(\\use_package\s+mathtools)')
+def revert_use_package(document, pkg, commands):
+    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{mathtools}"])
+        add_to_preamble(document, ["\\usepackage{" + pkg + "}"])
     elif value == "1": # auto
-        commands = ["mathclap", "mathllap", "mathrlap", \
-                    "lgathered", "rgathered", "vcentcolon", "dblcolon", \
-                    "coloneqq", "Coloneqq", "coloneq", "Coloneq", "eqqcolon", \
-                    "Eqqcolon", "eqcolon", "Eqcolon", "colonapprox", \
-                    "Colonapprox", "colonsim", "Colonsim"]
         i = 0
         while True:
             i = find_token(document.body, '\\begin_inset Formula', i)
@@ -413,37 +406,36 @@ def revert_use_mathtools(document):
             code = "\n".join(document.body[i:j])
             for c in commands:
                 if code.find("\\%s" % c) != -1:
-                    add_to_preamble(document, ["\\usepackage{mathtools}"])
+                    add_to_preamble(document, ["\\usepackage{" + pkg + "}"])
                     return
             i = j
 
 
+def convert_use_mathtools(document):
+    "insert use_package mathtools"
+    convert_use_package(document, "mathtools")
+
+
+def revert_use_mathtools(document):
+    "remove use_package mathtools"
+    commands = ["mathclap", "mathllap", "mathrlap", \
+                "lgathered", "rgathered", "vcentcolon", "dblcolon", \
+                "coloneqq", "Coloneqq", "coloneq", "Coloneq", "eqqcolon", \
+                "Eqqcolon", "eqcolon", "Eqcolon", "colonapprox", \
+                "Colonapprox", "colonsim", "Colonsim"]
+    revert_use_package(document, "mathtools", commands)
+
+
 def convert_use_stmaryrd(document):
     "insert use_package stmaryrd"
-    i = find_token(document.header, "\\use_package", 0)
-    if i == -1:
-        document.warning("Malformed LyX document: Can't find \\use_package.")
-        return;
-    j = find_token(document.preamble, "\\usepackage{stmaryrd}", 0)
-    if j == -1:
-        document.header.insert(i + 1, "\\use_package stmaryrd 0")
-    else:
-        document.header.insert(i + 1, "\\use_package stmaryrd 2")
-        del document.preamble[j]
+    convert_use_package(document, "stmaryrd")
 
 
 def revert_use_stmaryrd(document):
     "remove use_package stmaryrd"
-    regexp = re.compile(r'(\\use_package\s+stmaryrd)')
-    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{stmaryrd}"])
-    elif value == "1": # auto
-        commands = ["shortleftarrow", "shortrightarrow", "shortuparrow", \
+    # commands provided by stmaryrd.sty but LyX uses other packages:
+    # boxdot lightning, bigtriangledown, bigtriangleup
+    commands = ["shortleftarrow", "shortrightarrow", "shortuparrow", \
                     "shortdownarrow", "Yup", "Ydown", "Yleft", "Yright", \
                     "varcurlyvee", "varcurlywedge", "minuso", "baro", \
                     "sslash", "bbslash", "moo", "varotimes", "varoast", \
@@ -474,68 +466,19 @@ def revert_use_stmaryrd(document):
                     "varcopyright", "longarrownot", "Longarrownot", \
                     "Mapsto", "mapsfrom", "Mapsfrom" "Longmapsto", \
                     "longmapsfrom", "Longmapsfrom"]
-        # commands provided by stmaryrd.sty but LyX uses other packages:
-        # boxdot lightning, bigtriangledown, bigtriangleup
+    revert_use_package(document, "stmaryrd", commands)
 
-        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{stmaryrd}"])
-                    return
-            i = j
 
 
 def convert_use_stackrel(document):
     "insert use_package stackrel"
-    i = find_token(document.header, "\\use_package", 0)
-    if i == -1:
-        document.warning("Malformed LyX document: Can't find \\use_package.")
-        return;
-    j = find_token(document.preamble, "\\usepackage{stackrel}", 0)
-    if j == -1:
-        document.header.insert(i + 1, "\\use_package stackrel 0")
-    else:
-        document.header.insert(i + 1, "\\use_package stackrel 2")
-        del document.preamble[j]
+    convert_use_package(document, "stackrel")
 
 
 def revert_use_stackrel(document):
     "remove use_package stackrel"
-    regexp = re.compile(r'(\\use_package\s+stackrel)')
-    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{stackrel}"])
-    elif value == "1": # auto
-        regcmd = re.compile(r'.*\\stackrel\s*\[')
-        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])
-            if regcmd.match(code):
-                add_to_preamble(document, ["\\usepackage{stackrel}"])
-                return
-            i = j
+    commands = ["stackrel"]
+    revert_use_package(document, "stackrel", commands)
 
 
 def convert_cite_engine_type(document):
@@ -569,25 +512,11 @@ def revert_cite_engine_type(document):
     document.header[i] = "\\cite_engine natbib_" + engine_type
 
 
+# this is the same, as revert_use_cancel()
 def revert_cancel(document):
     "add cancel to the preamble if necessary"
     commands = ["cancelto", "cancel", "bcancel", "xcancel"]
-    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{cancel}"])
-                return
-        i = j
+    revert_use_package(document, "cancel", commands)
 
 
 def revert_verbatim(document):
@@ -887,6 +816,17 @@ def revert_use_amssymb(document):
         add_to_preamble(document, ["\\usepackage{amssymb}"])
 
 
+def convert_use_cancel(document):
+    "insert use_package cancel"
+    convert_use_package(document, "cancel")
+
+
+def revert_use_cancel(document):
+    "remove use_package cancel"
+    commands = ["cancel", "bcancel", "xcancel", "cancelto"]
+    revert_use_package(document, "cancel", commands)
+
+
 def revert_ancientgreek(document):
     "Set the document language for ancientgreek to greek" 
 
@@ -3785,9 +3725,11 @@ convert = [
            [461, []],
            [462, []],
            [463, [convert_encodings]],
+           [464, [convert_use_cancel]],
           ]
 
 revert =  [
+           [463, [revert_use_cancel]],
            [462, [revert_encodings]],
            [461, [revert_new_libertines]],
            [460, [revert_kurier_fonts]],
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 60129ab..52ba206 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -450,6 +450,7 @@ vector<string> const & BufferParams::auto_packages()
                // adding a package here implies a file format change!
                packages.push_back("amsmath");
                packages.push_back("amssymb");
+               packages.push_back("cancel");
                packages.push_back("esint");
                packages.push_back("mathdots");
                packages.push_back("mathtools");
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index 562f9b1..10adb14 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -698,7 +698,7 @@ char const * simplefeatures[] = {
        "mathrsfs",
        "mathabx",
        "mathtools",
-       "cancel",
+       // "cancel",
        "ascii",
        "url",
        "covington",
@@ -833,6 +833,9 @@ string const LaTeXFeatures::getPackages() const
        if (mustProvide("fixltx2e"))
                packages << "\\usepackage{fixltx2e}\n";
 
+        if (mustProvide("cancel") &&
+            params_.use_package("cancel") != BufferParams::package_off)
+                packages << "\\usepackage{cancel}\n";
        // wasysym is a simple feature, but it must be after amsmath if both
        // are used
        // wasysym redefines some integrals (e.g. iint) from amsmath. That
diff --git a/src/frontends/qt4/GuiDocument.cpp 
b/src/frontends/qt4/GuiDocument.cpp
index ff63977..40b8dd8 100644
--- a/src/frontends/qt4/GuiDocument.cpp
+++ b/src/frontends/qt4/GuiDocument.cpp
@@ -140,6 +140,10 @@ char const * packages_gui[][4] =
         N_("&Use amssymb package automatically"),
         N_("Use amssymb package"),
         N_("The LaTeX package amssymb is only used if symbols from the AMS 
math toolbars are inserted into formulas")},
+       {"cancel",
+        N_("Use cancel package automatically"),
+        N_("Use cancel package"),
+        N_("The LaTeX package cancel is only used if \\cancel commands are 
used in formulas")},
        {"esint",
         N_("Use esint package &automatically"),
         N_("Use &esint package"),
diff --git a/src/version.h b/src/version.h
index ab0ee1b..94e5244 100644
--- a/src/version.h
+++ b/src/version.h
@@ -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 463 // jrioux: encodings renaming
-#define LYX_FORMAT_TEX2LYX 463 // jrioux: encodings renaming
+#define LYX_FORMAT_LYX 464 // kornel: use_package cancel
+#define LYX_FORMAT_TEX2LYX 464 // kornel: use_package cancel
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER

-----------------------------------------------------------------------

Summary of changes:
 development/FORMAT                |    4 +
 lib/lyx2lyx/lyx_2_1.py            |  150 +++++++++++-------------------------
 src/BufferParams.cpp              |    1 +
 src/LaTeXFeatures.cpp             |    5 +-
 src/frontends/qt4/GuiDocument.cpp |    4 +
 src/tex2lyx/Preamble.cpp          |    3 +-
 src/version.h                     |    4 +-
 7 files changed, 63 insertions(+), 108 deletions(-)


hooks/post-receive
-- 
The LyX Source Repository

Reply via email to