]> git.lyx.org Git - features.git/commitdiff
- introduce option to suppress the LaTeX package mhchem, fileformat change
authorUwe Stöhr <uwestoehr@web.de>
Wed, 11 Nov 2009 01:48:07 +0000 (01:48 +0000)
committerUwe Stöhr <uwestoehr@web.de>
Wed, 11 Nov 2009 01:48:07 +0000 (01:48 +0000)
The fileformat change is also needed because of our mistake that we load mhchem since LyX 1.6.4 automatically so that files created with LyX 1.6.4 won't compile under LyX 1.6.3. Now at least all files created or opened with LyX 1.7 can be reverted to the fileformat of LyX 1.6.x and can therefore be read by all LyX 1.6.x versions.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31941 a592a061-630c-0410-9148-cb99ea01b6c8

development/FORMAT
lib/lyx2lyx/lyx_2_0.py
src/Buffer.cpp
src/BufferParams.cpp
src/BufferParams.h
src/LaTeXFeatures.cpp
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/ui/MathsUi.ui
src/mathed/MathFactory.cpp
src/mathed/MathParser.cpp

index b96b0faa4e0f64ad4ce09f3d5c787ff906b81431..bdcf98b94b838a4f5e00856a1253ba3310d6626b 100644 (file)
@@ -1,6 +1,10 @@
 LyX file-format changes
 -----------------------
 
+2009-11-11 Uwe Stöhr <uwestoehr@web.de>
+       * Format incremented to 371: add option to suppress the LaTeX
+         package mhchem.
+
 2009-07-20 Uwe Stöhr <uwestoehr@web.de>
        * Format incremented to 370: introduce a document option to
          suppress the default date.
index d088f7773dfc158a86daac87a1e5557d323ef7e4..d668bfa745ac4dc8ecb95b6e534d539776f0f48a 100644 (file)
@@ -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]],
index d1104370c09452cb4f5316c570cb2d81f4012247..8d8c53795201c69f9e6de8ac5319a772d596e86f 100644 (file)
@@ -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<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
index f369c8d6d9cbdf03d67c3cf520ec2c45edc3a5ce..656ba12ccf9827a9781ea956c4c06a031894c0b6 100644 (file)
@@ -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<string>(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<string>(use_bibtopic)
           << "\n\\use_indices " << convert<string>(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())
index 0be946c37f42ee1a0c6d4eec607256b06e0e983d..fefa91b90f4ff3e0da390feb6b12fe8be9e43e50 100644 (file)
@@ -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?
index 81bebfdeda7416f63ae6ea4d66fc07a0ec5100de..1f88eb0f9a857cf5e3e19666684d7174d882f16b 100644 (file)
@@ -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";
 
index b866cc3acf586b2602737447659120d36f5a3303..ee3d4e8d6ca9262e664b4dc7cd9cb70d3c62ea4d 100644 (file)
@@ -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<Ui::LaTeXUi>;
        // 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;
index 7aaebd3fa2a1b673ef2691c27262d8fedf15d1f3..30b66bc3dd892b99889544aab0f5a6d722554011 100644 (file)
@@ -1,7 +1,7 @@
 <ui version="4.0" >
  <class>MathsUi</class>
- <widget class="QWidget" name="MathsUi" >
-  <property name="geometry" >
+ <widget class="QWidget" name="MathsUi">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
@@ -9,59 +9,70 @@
     <height>233</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string/>
   </property>
-  <layout class="QVBoxLayout" >
-   <property name="margin" >
-    <number>11</number>
-   </property>
-   <property name="spacing" >
-    <number>6</number>
-   </property>
-   <item>
-    <widget class="QCheckBox" name="amsautoCB" >
-     <property name="text" >
+  <layout class="QGridLayout" name="gridLayout">
+   <item row="0" column="0">
+    <widget class="QCheckBox" name="amsautoCB">
+     <property name="text">
       <string>&amp;Use AMS math package automatically</string>
      </property>
-     <property name="checked" >
+     <property name="checked">
       <bool>false</bool>
      </property>
     </widget>
    </item>
-   <item>
-    <widget class="QCheckBox" name="amsCB" >
-     <property name="text" >
+   <item row="1" column="0">
+    <widget class="QCheckBox" name="amsCB">
+     <property name="text">
       <string>Use AMS &amp;math package</string>
      </property>
     </widget>
    </item>
-   <item>
-    <widget class="QCheckBox" name="esintautoCB" >
-     <property name="text" >
+   <item row="2" column="0">
+    <widget class="QCheckBox" name="esintautoCB">
+     <property name="text">
       <string>Use esint package &amp;automatically</string>
      </property>
-     <property name="checked" >
+     <property name="checked">
       <bool>false</bool>
      </property>
     </widget>
    </item>
-   <item>
-    <widget class="QCheckBox" name="esintCB" >
-     <property name="text" >
+   <item row="3" column="0">
+    <widget class="QCheckBox" name="esintCB">
+     <property name="text">
       <string>Use &amp;esint package</string>
      </property>
     </widget>
    </item>
-   <item>
+   <item row="4" column="0">
+    <widget class="QCheckBox" name="mhchemautoCB">
+     <property name="text">
+      <string>Use mhchem &amp;package automatically</string>
+     </property>
+     <property name="checked">
+      <bool>false</bool>
+     </property>
+    </widget>
+   </item>
+   <item row="5" column="0">
+    <widget class="QCheckBox" name="mhchemCB">
+     <property name="text">
+      <string>Use mh&amp;chem package</string>
+     </property>
+    </widget>
+   </item>
+   <item row="6" column="0">
     <spacer>
-     <property name="orientation" >
+     <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
-     <property name="sizeType" >
+     <property name="sizeType">
       <enum>QSizePolicy::Expanding</enum>
      </property>
-     <property name="sizeHint" >
+     <property name="sizeHint" stdset="0">
       <size>
        <width>20</width>
        <height>20</height>
    </item>
   </layout>
  </widget>
- <pixmapfunction></pixmapfunction>
- <includes>
-  <include location="local" >qt_i18n.h</include>
- </includes>
  <tabstops>
   <tabstop>amsautoCB</tabstop>
   <tabstop>esintautoCB</tabstop>
  </tabstops>
+ <includes>
+  <include location="local">qt_i18n.h</include>
+ </includes>
  <resources/>
  <connections/>
 </ui>
index 1d6d83baf8eb308990eabb19d52e2f6309feb084..b1af651497600f3d116a136b87898ae11218b84d 100644 (file)
@@ -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;
index bc90a37091c7781670147169f666dbdf3b527ac2..c57221a362644d9d3eb8f39871a821d1793009b8 100644 (file)
@@ -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") {