diff --git a/development/FORMAT b/development/FORMAT index b96b0faa4e..bdcf98b94b 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,6 +1,10 @@ LyX file-format changes ----------------------- +2009-11-11 Uwe Stöhr + * Format incremented to 371: add option to suppress the LaTeX + package mhchem. + 2009-07-20 Uwe Stöhr * Format incremented to 370: introduce a document option to suppress the default date. diff --git a/lib/lyx2lyx/lyx_2_0.py b/lib/lyx2lyx/lyx_2_0.py index d088f7773d..d668bfa745 100644 --- a/lib/lyx2lyx/lyx_2_0.py +++ b/lib/lyx2lyx/lyx_2_0.py @@ -1038,6 +1038,37 @@ def revert_suppress_date(document): i = i + 1 +def revert_mhchem(document): + "Revert mhchem loading to preamble code" + i = 0 + j = 0 + k = 0 + i = find_token(document.header, "\\use_mhchem 1", 0) + if i != -1: + mhchem = "auto" + else: + i = find_token(document.header, "\\use_mhchem 2", 0) + if i != -1: + mhchem = "on" + if mhchem == "auto": + j = find_token(document.body, "\\cf{", 0) + if j != -1: + mhchem = "on" + else: + j = find_token(document.body, "\\ce{", 0) + if j != -1: + mhchem = "on" + if mhchem == "on": + add_to_preamble(document, ["% this command was inserted by lyx2lyx"]) + add_to_preamble(document, ["\\PassOptionsToPackage{version=3}{mhchem}"]) + add_to_preamble(document, ["\\usepackage{mhchem}"]) + k = find_token(document.header, "\\use_mhchem", 0) + if k == -1: + document.warning("Malformed LyX document: Could not find mhchem setting.") + return + del document.header[k] + + ## # Conversion hub # @@ -1068,9 +1099,11 @@ convert = [[346, []], [368, []], [369, [convert_author_id]], [370, []], + [371, []] ] -revert = [[369, [revert_suppress_date]], +revert = [[370, [revert_mhchem]], + [369, [revert_suppress_date]], [368, [revert_author_id]], [367, [revert_hspace_glue_lengths]], [366, [revert_percent_vspace_lengths, revert_percent_hspace_lengths]], diff --git a/src/Buffer.cpp b/src/Buffer.cpp index d1104370c0..8d8c537952 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -127,7 +127,7 @@ namespace { // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -int const LYX_FORMAT = 370; // uwestoehr: option to suppress default date +int const LYX_FORMAT = 371; // uwestoehr: option to turn off mhchem typedef map DepClean; typedef map > RefCache; diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index f369c8d6d9..656ba12ccf 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -336,6 +336,7 @@ BufferParams::BufferParams() use_geometry = false; use_amsmath = package_auto; use_esint = package_auto; + use_mhchem = package_auto; cite_engine_ = ENGINE_BASIC; use_bibtopic = false; use_indices = false; @@ -612,6 +613,10 @@ string BufferParams::readToken(Lexer & lex, string const & token, int useesint; lex >> useesint; use_esint = packagetranslator().find(useesint); + } else if (token == "\\use_mhchem") { + int usemhchem; + lex >> usemhchem; + use_mhchem = packagetranslator().find(usemhchem); } else if (token == "\\cite_engine") { string engine; lex >> engine; @@ -863,6 +868,7 @@ void BufferParams::writeFile(ostream & os) const << "\n\\use_geometry " << convert(use_geometry) << "\n\\use_amsmath " << use_amsmath << "\n\\use_esint " << use_esint + << "\n\\use_mhchem " << use_mhchem << "\n\\cite_engine " << citeenginetranslator().find(cite_engine_) << "\n\\use_bibtopic " << convert(use_bibtopic) << "\n\\use_indices " << convert(use_indices) @@ -1012,6 +1018,8 @@ void BufferParams::validate(LaTeXFeatures & features) const features.require("amsmath"); if (use_esint == package_on) features.require("esint"); + if (use_mhchem == package_on) + features.require("mhchem"); // Document-level line spacing if (spacing().getSpace() != Spacing::Single && !spacing().isDefault()) diff --git a/src/BufferParams.h b/src/BufferParams.h index 0be946c37f..fefa91b90f 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -294,6 +294,8 @@ public: Package use_amsmath; /// Whether and how to load esint Package use_esint; + /// Whether and how to load mhchem + Package use_mhchem; /// Split bibliography? bool use_bibtopic; /// Split the index? diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 81bebfdeda..1f88eb0f9a 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -745,7 +745,8 @@ string const LaTeXFeatures::getPackages() const packages << "\\PassOptionsToPackage{normalem}{ulem}\n" "\\usepackage{ulem}\n"; - if (mustProvide("mhchem")) + if (mustProvide("mhchem") && + params_.use_mhchem != BufferParams::package_off) packages << "\\PassOptionsToPackage{version=3}{mhchem}\n" "\\usepackage{mhchem}\n"; diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index b866cc3acf..ee3d4e8d6c 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -901,6 +901,8 @@ GuiDocument::GuiDocument(GuiView & lv) mathsModule->amsCB, SLOT(setDisabled(bool))); connect(mathsModule->esintautoCB, SIGNAL(toggled(bool)), mathsModule->esintCB, SLOT(setDisabled(bool))); + connect(mathsModule->mhchemautoCB, SIGNAL(toggled(bool)), + mathsModule->mhchemCB, SLOT(setDisabled(bool))); // maths connect(mathsModule->amsCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); @@ -910,6 +912,10 @@ GuiDocument::GuiDocument(GuiView & lv) this, SLOT(change_adaptor())); connect(mathsModule->esintautoCB, SIGNAL(clicked()), this, SLOT(change_adaptor())); + connect(mathsModule->mhchemCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); + connect(mathsModule->mhchemautoCB, SIGNAL(clicked()), + this, SLOT(change_adaptor())); latexModule = new UiWidget; // latex class @@ -1906,7 +1912,6 @@ void GuiDocument::applyView() else bp_.use_amsmath = BufferParams::package_off; } - if (mathsModule->esintautoCB->isChecked()) bp_.use_esint = BufferParams::package_auto; else { @@ -1915,6 +1920,14 @@ void GuiDocument::applyView() else bp_.use_esint = BufferParams::package_off; } + if (mathsModule->mhchemautoCB->isChecked()) + bp_.use_mhchem = BufferParams::package_auto; + else { + if (mathsModule->mhchemCB->isChecked()) + bp_.use_mhchem = BufferParams::package_on; + else + bp_.use_mhchem = BufferParams::package_off; + } // Page Layout if (pageLayoutModule->pagestyleCO->currentIndex() == 0) @@ -2270,6 +2283,11 @@ void GuiDocument::paramsToDialog() mathsModule->esintautoCB->setChecked( bp_.use_esint == BufferParams::package_auto); + mathsModule->mhchemCB->setChecked( + bp_.use_mhchem == BufferParams::package_on); + mathsModule->mhchemautoCB->setChecked( + bp_.use_mhchem == BufferParams::package_auto); + switch (bp_.spacing().getSpace()) { case Spacing::Other: nitem = 3; break; case Spacing::Double: nitem = 2; break; diff --git a/src/frontends/qt4/ui/MathsUi.ui b/src/frontends/qt4/ui/MathsUi.ui index 7aaebd3fa2..30b66bc3dd 100644 --- a/src/frontends/qt4/ui/MathsUi.ui +++ b/src/frontends/qt4/ui/MathsUi.ui @@ -1,7 +1,7 @@ MathsUi - - + + 0 0 @@ -9,59 +9,70 @@ 233 - + - - - 11 - - - 6 - - - - + + + + &Use AMS math package automatically - + false - - - + + + Use AMS &math package - - - + + + Use esint package &automatically - + false - - - + + + Use &esint package - + + + + Use mhchem &package automatically + + + false + + + + + + + Use mh&chem package + + + + - + Qt::Vertical - + QSizePolicy::Expanding - + 20 20 @@ -71,14 +82,13 @@ - - - qt_i18n.h - amsautoCB esintautoCB + + qt_i18n.h + diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp index 1d6d83baf8..b1af651497 100644 --- a/src/mathed/MathFactory.cpp +++ b/src/mathed/MathFactory.cpp @@ -62,6 +62,8 @@ #include "frontends/FontLoader.h" +#include "Buffer.h" +#include "BufferParams.h" #include "Encoding.h" #include "LyX.h" // use_gui #include "OutputParams.h" @@ -309,6 +311,10 @@ MathAtom createInsetMath(char const * const s, Buffer * buf) MathAtom createInsetMath(docstring const & s, Buffer * buf) { //lyxerr << "creating inset with name: '" << to_utf8(s) << '\'' << endl; + if ((s == "ce" || s == "cf") && buf + && buf->params().use_mhchem == BufferParams::package_off) + return MathAtom(new MathMacro(buf, s)); + latexkeys const * l = in_word_set(s); if (l) { docstring const & inset = l->inset; diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp index bc90a37091..c57221a362 100644 --- a/src/mathed/MathParser.cpp +++ b/src/mathed/MathParser.cpp @@ -65,6 +65,7 @@ following hack as starting point to write some macros: #include "MathSupport.h" #include "Buffer.h" +#include "BufferParams.h" #include "Encoding.h" #include "Lexer.h" @@ -1765,10 +1766,13 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags, } else if (t.cs().size()) { - bool const is_user_macro = - buf && (mode_ & Parse::TRACKMACRO + bool const no_mhchem = + (t.cs() == "ce" || t.cs() == "cf") && buf + && buf->params().use_mhchem == BufferParams::package_off; + bool const is_user_macro = no_mhchem || + (buf && (mode_ & Parse::TRACKMACRO ? buf->usermacros.count(t.cs()) != 0 - : buf->getMacro(t.cs(), false) != 0); + : buf->getMacro(t.cs(), false) != 0)); latexkeys const * l = in_word_set(t.cs()); if (l && !is_user_macro) { if (l->inset == "big") {