Disentangle amsmath and amssymb loading.

This is needed if you load a font package incompatible to amssymb manually
(see bug #5058).
This commit is contained in:
Georg Baum 2012-05-06 20:48:04 +02:00
parent 2e42350523
commit b86c984bf4
7 changed files with 60 additions and 13 deletions

View 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> 2012-04-16 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* Format incremented to 430 (2773345) * Format incremented to 430 (2773345)
Support \lstlistoflistings in InsetTOC Support \lstlistoflistings in InsetTOC

View 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, \ #from parser_tools import find_token, find_end_of, find_tokens, \
#find_token_exact, find_end_of_inset, find_end_of_layout, \ #find_token_exact, find_end_of_inset, find_end_of_layout, \
#find_token_backwards, is_in_inset, get_value, get_quoted_value, \ #find_token_backwards, is_in_inset, del_token, check_token
#del_token, check_token
from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert, get_ert from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert, get_ert
@ -730,6 +729,45 @@ def revert_listoflistings(document):
i = i + 1 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 # Conversion hub
# #
@ -753,9 +791,11 @@ convert = [
[428, [convert_cell_rotation]], [428, [convert_cell_rotation]],
[429, [convert_table_rotation]], [429, [convert_table_rotation]],
[430, [convert_listoflistings]], [430, [convert_listoflistings]],
[431, [convert_use_amssymb]],
] ]
revert = [ revert = [
[430, [revert_use_amssymb]],
[429, [revert_listoflistings]], [429, [revert_listoflistings]],
[428, [revert_table_rotation]], [428, [revert_table_rotation]],
[427, [revert_cell_rotation]], [427, [revert_cell_rotation]],

View File

@ -447,6 +447,7 @@ vector<string> const & BufferParams::auto_packages()
if (packages.empty()) { if (packages.empty()) {
// adding a package here implies a file format change! // adding a package here implies a file format change!
packages.push_back("amsmath"); packages.push_back("amsmath");
packages.push_back("amssymb");
packages.push_back("esint"); packages.push_back("esint");
packages.push_back("mathdots"); packages.push_back("mathdots");
packages.push_back("mathtools"); packages.push_back("mathtools");

View File

@ -1066,7 +1066,7 @@ string const LaTeXFeatures::loadAMSPackages() const
} }
if (mustProvide("amssymb") if (mustProvide("amssymb")
|| params_.use_package("amsmath") == BufferParams::package_on) && params_.use_package("amssymb") != BufferParams::package_off)
tmp << "\\usepackage{amssymb}\n"; tmp << "\\usepackage{amssymb}\n";
return tmp.str(); return tmp.str();

View File

@ -175,9 +175,13 @@ char const * backref_opts_gui[] =
char const * packages_gui[][4] = char const * packages_gui[][4] =
{ {
{"amsmath", {"amsmath",
N_("&Use AMS math package automatically"), N_("&Use amsmath package automatically"),
N_("Use AMS &math package"), 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_("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", {"esint",
N_("Use esint package &automatically"), N_("Use esint package &automatically"),
N_("Use &esint package"), N_("Use &esint package"),

View File

@ -466,6 +466,7 @@ Preamble::Preamble() : one_language(true), title_layout_found(false)
h_use_hyperref = "0"; h_use_hyperref = "0";
h_use_refstyle = "0"; h_use_refstyle = "0";
h_use_packages["amsmath"] = "1"; h_use_packages["amsmath"] = "1";
h_use_packages["amssymb"] = "0";
h_use_packages["esint"] = "1"; h_use_packages["esint"] = "1";
h_use_packages["mhchem"] = "0"; h_use_packages["mhchem"] = "0";
h_use_packages["mathdots"] = "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)) || is_known(name, known_typewriter_fonts))
; ;
else if (name == "amsmath" || name == "amssymb") else if (name == "amsmath" || name == "amssymb" ||
h_use_packages["amsmath"] = "2"; name == "esint" || name == "mhchem" || name == "mathdots" ||
else if (name == "esint" || name == "mhchem" || name == "mathdots" ||
name == "mathtools" || name == "undertilde") name == "mathtools" || name == "undertilde")
h_use_packages[name] = "2"; h_use_packages[name] = "2";
@ -849,7 +848,6 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc)
// amsbsy and amstext are already provided by amsmath // amsbsy and amstext are already provided by amsmath
registerAutomaticallyLoadedPackage("amsbsy"); registerAutomaticallyLoadedPackage("amsbsy");
registerAutomaticallyLoadedPackage("amstext"); registerAutomaticallyLoadedPackage("amstext");
registerAutomaticallyLoadedPackage("amssymb");
} }
// output the LyX file settings // output the LyX file settings

View File

@ -30,8 +30,8 @@ extern char const * const lyx_version_info;
// Do not remove the comment below, so we get merge conflict in // Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own. // independent branches. Instead add your own.
#define LYX_FORMAT_LYX 430 // gb: listoflistings #define LYX_FORMAT_LYX 431 // gb: load switch for amssymb
#define LYX_FORMAT_TEX2LYX 430 // gb: listoflistings #define LYX_FORMAT_TEX2LYX 431 // gb: load switch for amssymb
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER #ifndef _MSC_VER