- introduce option to suppress the LaTeX package mhchem, fileformat change

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
This commit is contained in:
Uwe Stöhr 2009-11-11 01:48:07 +00:00
parent 3d44bc9fde
commit d5099c8605
10 changed files with 125 additions and 39 deletions

View 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.

View 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]],

View 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;

View 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())

View 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?

View 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";

View 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;

View 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>
@ -71,14 +82,13 @@
</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>

View 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;

View 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") {