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.
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
#
[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]],
// 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;
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;
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;
<< "\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)
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())
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?
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";
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()));
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
else
bp_.use_amsmath = BufferParams::package_off;
}
-
if (mathsModule->esintautoCB->isChecked())
bp_.use_esint = BufferParams::package_auto;
else {
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)
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;
<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>
<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>&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 &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 &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 &esint package</string>
</property>
</widget>
</item>
- <item>
+ <item row="4" column="0">
+ <widget class="QCheckBox" name="mhchemautoCB">
+ <property name="text">
+ <string>Use mhchem &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&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>
#include "frontends/FontLoader.h"
+#include "Buffer.h"
+#include "BufferParams.h"
#include "Encoding.h"
#include "LyX.h" // use_gui
#include "OutputParams.h"
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;
#include "MathSupport.h"
#include "Buffer.h"
+#include "BufferParams.h"
#include "Encoding.h"
#include "Lexer.h"
}
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") {