]> git.lyx.org Git - features.git/commitdiff
Disentangle amsmath and amssymb loading.
authorGeorg Baum <baum@lyx.org>
Sun, 6 May 2012 18:48:04 +0000 (20:48 +0200)
committerGeorg Baum <baum@lyx.org>
Sun, 6 May 2012 18:49:49 +0000 (20:49 +0200)
This is needed if you load a font package incompatible to amssymb manually
(see bug #5058).

development/FORMAT
lib/lyx2lyx/lyx_2_1.py
src/BufferParams.cpp
src/LaTeXFeatures.cpp
src/frontends/qt4/GuiDocument.cpp
src/tex2lyx/Preamble.cpp
src/version.h

index 356bf4c90356fa2ab6559517370520253cafacb3..f4433e00e51476e651d24e26fc74218622dca8cc 100644 (file)
@@ -11,6 +11,10 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
 
 -----------------------
 
+2012-05-06 Georg Baum  <Georg.Baum@post.rwth-aachen.de>
+       * Format incremented to 431
+         Add \use_package amssymb
+
 2012-04-16 Georg Baum  <Georg.Baum@post.rwth-aachen.de>
        * Format incremented to 430 (2773345)
          Support \lstlistoflistings in InsetTOC
index c76cf1baac12f93e058fe24bb4cf9526e15dc9ec..bbd9b3cd9fbc44a3dc04dd4ed87179637f598aa7 100644 (file)
@@ -31,8 +31,7 @@ from parser_tools import del_token, find_token, find_end_of, find_end_of_inset,
 
 #from parser_tools import find_token, find_end_of, find_tokens, \
   #find_token_exact, find_end_of_inset, find_end_of_layout, \
-  #find_token_backwards, is_in_inset, get_value, get_quoted_value, \
-  #del_token, check_token
+  #find_token_backwards, is_in_inset, del_token, check_token
 
 from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert, get_ert
 
@@ -730,6 +729,45 @@ def revert_listoflistings(document):
         i = i + 1
 
 
+def convert_use_amssymb(document):
+    "insert use_package amssymb"
+    regexp = re.compile(r'(\\use_package\s+amsmath)')
+    i = find_re(document.header, regexp, 0)
+    if i == -1:
+        document.warning("Malformed LyX document: Can't find \\use_package amsmath.")
+        return;
+    value = get_value(document.header, "\\use_package" , i).split()[1]
+    useamsmath = 0
+    try:
+        useamsmath = int(value)
+    except:
+        document.warning("Invalid \\use_package amsmath: " + value + ". Assuming auto.")
+        useamsmath = 1
+    j = find_token(document.preamble, "\\usepackage{amssymb}", 0)
+    if j == -1:
+        document.header.insert(i + 1, "\\use_package amssymb %d" % useamsmath)
+    else:
+        document.header.insert(i + 1, "\\use_package amssymb 2")
+        del document.preamble[j]
+
+
+def revert_use_amssymb(document):
+    "remove use_package amssymb"
+    regexp1 = re.compile(r'(\\use_package\s+amsmath)')
+    regexp2 = re.compile(r'(\\use_package\s+amssymb)')
+    i = find_re(document.header, regexp1, 0)
+    j = find_re(document.header, regexp2, 0)
+    value1 = "1" # default is auto
+    value2 = "1" # default is auto
+    if i != -1:
+        value1 = get_value(document.header, "\\use_package" , i).split()[1]
+    if j != -1:
+        value2 = get_value(document.header, "\\use_package" , j).split()[1]
+        del document.header[j]
+    if value1 != value2 and value2 == "2": # on
+        add_to_preamble(document, ["\\usepackage{amssymb}"])
+
+
 ##
 # Conversion hub
 #
@@ -753,9 +791,11 @@ convert = [
            [428, [convert_cell_rotation]],
            [429, [convert_table_rotation]],
            [430, [convert_listoflistings]],
+           [431, [convert_use_amssymb]],
           ]
 
 revert =  [
+           [430, [revert_use_amssymb]],
            [429, [revert_listoflistings]],
            [428, [revert_table_rotation]],
            [427, [revert_cell_rotation]],
index 5f848a6256ff9f76132d5c7bc4fb666ed4d7727e..0a7e5947f653ecfa4f6a159d8b6a725b93b84892 100644 (file)
@@ -447,6 +447,7 @@ vector<string> const & BufferParams::auto_packages()
        if (packages.empty()) {
                // adding a package here implies a file format change!
                packages.push_back("amsmath");
+               packages.push_back("amssymb");
                packages.push_back("esint");
                packages.push_back("mathdots");
                packages.push_back("mathtools");
index d5a0b6f6b90043b7015f37d64dad51804ea5071b..2a3d099ff5c5a13f1f03c3d01790d9174b54a203 100644 (file)
@@ -1066,7 +1066,7 @@ string const LaTeXFeatures::loadAMSPackages() const
        }
 
        if (mustProvide("amssymb")
-           || params_.use_package("amsmath") == BufferParams::package_on)
+           && params_.use_package("amssymb") != BufferParams::package_off)
                tmp << "\\usepackage{amssymb}\n";
 
        return tmp.str();
index e370170a265b106776d3d07870303423b4251333..0708f01db234ed594c0a97e8cd318b1a50069d60 100644 (file)
@@ -175,9 +175,13 @@ char const * backref_opts_gui[] =
 char const * packages_gui[][4] =
 {
        {"amsmath",
-        N_("&Use AMS math package automatically"),
-        N_("Use AMS &math package"),
-        N_("The AMS LaTeX packages are only used if symbols from the AMS math toolbars are inserted into formulas")},
+        N_("&Use amsmath package automatically"),
+        N_("Use ams&math package"),
+        N_("The LaTeX package amsmath is only used if AMS formula types or symbols from the AMS math toolbars are inserted into formulas")},
+       {"amssymb",
+        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")},
        {"esint",
         N_("Use esint package &automatically"),
         N_("Use &esint package"),
index c02c1919c4a02fa44a9c79c552dc23613d1a7fcf..454f2165c50215719a5d4d3c28f250dde9815e99 100644 (file)
@@ -466,6 +466,7 @@ Preamble::Preamble() : one_language(true), title_layout_found(false)
        h_use_hyperref            = "0";
        h_use_refstyle            = "0";
        h_use_packages["amsmath"]    = "1";
+       h_use_packages["amssymb"]    = "0";
        h_use_packages["esint"]      = "1";
        h_use_packages["mhchem"]     = "0";
        h_use_packages["mathdots"]   = "0";
@@ -653,10 +654,8 @@ void Preamble::handle_package(Parser &p, string const & name,
                ||      is_known(name, known_typewriter_fonts))
                ;
 
-       else if (name == "amsmath" || name == "amssymb")
-               h_use_packages["amsmath"] = "2";
-
-       else if (name == "esint" || name == "mhchem" || name == "mathdots" ||
+       else if (name == "amsmath" || name == "amssymb" ||
+                name == "esint" || name == "mhchem" || name == "mathdots" ||
                 name == "mathtools" || name == "undertilde")
                h_use_packages[name] = "2";
 
@@ -849,7 +848,6 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc)
                // amsbsy and amstext are already provided by amsmath
                registerAutomaticallyLoadedPackage("amsbsy");
                registerAutomaticallyLoadedPackage("amstext");
-               registerAutomaticallyLoadedPackage("amssymb");
        }
 
        // output the LyX file settings
index 8329f8a2876c3731a5ae0109400418bb7ad9f93d..5cd0fb136d263f1a8b00b6ac0d5e9e3a5bdd94ff 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 430 // gb: listoflistings
-#define LYX_FORMAT_TEX2LYX 430 // gb: listoflistings
+#define LYX_FORMAT_LYX 431 // gb: load switch for amssymb
+#define LYX_FORMAT_TEX2LYX 431 // gb: load switch for amssymb
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER