From: Georg Baum Date: Sun, 6 May 2012 18:48:04 +0000 (+0200) Subject: Disentangle amsmath and amssymb loading. X-Git-Tag: 2.1.0beta1~1895 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=b86c984bf408b47fbd6fc92c4009f9129d0d1ef8;p=features.git Disentangle amsmath and amssymb loading. This is needed if you load a font package incompatible to amssymb manually (see bug #5058). --- diff --git a/development/FORMAT b/development/FORMAT index 356bf4c903..f4433e00e5 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -11,6 +11,10 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx. ----------------------- +2012-05-06 Georg Baum + * Format incremented to 431 + Add \use_package amssymb + 2012-04-16 Georg Baum * Format incremented to 430 (2773345) Support \lstlistoflistings in InsetTOC diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py index c76cf1baac..bbd9b3cd9f 100644 --- a/lib/lyx2lyx/lyx_2_1.py +++ b/lib/lyx2lyx/lyx_2_1.py @@ -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]], diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 5f848a6256..0a7e5947f6 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -447,6 +447,7 @@ vector 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"); diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index d5a0b6f6b9..2a3d099ff5 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -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(); diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index e370170a26..0708f01db2 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -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"), diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index c02c1919c4..454f2165c5 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -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 diff --git a/src/version.h b/src/version.h index 8329f8a287..5cd0fb136d 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 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