commit 3f8c15a7c66a7ca67776bfaaa16380560ba17dd5
Author: Uwe Stöhr <[email protected]>
Date: Tue Apr 25 02:28:10 2017 +0200
support for the document class option leqno
- fileformat change
---
development/FORMAT | 4 ++
lib/lyx2lyx/lyx_2_3.py | 45 ++++++++++++++++++-
src/BufferParams.cpp | 7 +++
src/BufferParams.h | 4 ++
src/frontends/qt4/GuiDocument.cpp | 23 +++++++++
src/frontends/qt4/ui/MathsUi.ui | 90 ++++++++++++++++++++++++++-----------
src/tex2lyx/Preamble.cpp | 9 ++++
src/tex2lyx/Preamble.h | 1 +
src/version.h | 4 +-
9 files changed, 157 insertions(+), 30 deletions(-)
diff --git a/development/FORMAT b/development/FORMAT
index 252c393..07a76ca 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -6,6 +6,10 @@ changes happened in particular if possible. A good example
would be
2010-01-10 entry.
-----------------------
+2017-04-25 Uwe Stöhr <[email protected]>
+ * Format incremented to 542: support for document class option "leqno"
+ New buffer parameter \math_number_before
+
2017-04-19 Günter Milde <[email protected]>
* Format incremented to 541: changes \SpecialChar:
- new argument "allowbreak" to mark an optional line break
diff --git a/lib/lyx2lyx/lyx_2_3.py b/lib/lyx2lyx/lyx_2_3.py
index dc7e2f0..c43bfa4 100644
--- a/lib/lyx2lyx/lyx_2_3.py
+++ b/lib/lyx2lyx/lyx_2_3.py
@@ -2122,6 +2122,7 @@ def revert_rotfloat(document):
i = i + 1
+
def convert_allowbreak(document):
" Zero widths Space-inset -> \SpecialChar allowbreak. "
body = "\n".join(document.body)
@@ -2131,6 +2132,7 @@ def convert_allowbreak(document):
"\\SpecialChar allowbreak\n")
document.body = body.split("\n")
+
def revert_allowbreak(document):
" \SpecialChar allowbreak -> Zero widths Space-inset. "
body = "\n".join(document.body)
@@ -2141,6 +2143,45 @@ def revert_allowbreak(document):
document.body = body.split("\n")
+def convert_mathnumberpos(document):
+ " add the \math_number_before tag "
+ # check if the document uses the class option "leqno"
+ k = find_token(document.header, "\\quotes_style", 0)
+ regexp = re.compile(r'^.*leqno.*')
+ i = find_re(document.header, regexp, 0)
+ if i != -1:
+ document.header.insert(k, "\\math_number_before 1")
+ # delete the found option
+ document.header[i] = document.header[i].replace(",leqno", "")
+ document.header[i] = document.header[i].replace(", leqno", "")
+ document.header[i] = document.header[i].replace("leqno,", "")
+ j = find_re(document.header, regexp, 0)
+ if i == j:
+ # then we have fleqn as the only option
+ del document.header[i]
+ else:
+ document.header.insert(k, "\\math_number_before 0")
+
+
+def revert_mathnumberpos(document):
+ " add the document class option leqno"
+ regexp = re.compile(r'(\\math_number_before 1)')
+ i = find_re(document.header, regexp, 0)
+ if i == -1:
+ regexp = re.compile(r'(\\math_number_before)')
+ j = find_re(document.header, regexp, 0)
+ del document.header[j]
+ else:
+ k = find_token(document.header, "\\options", 0)
+ if k != -1:
+ document.header[k] = document.header[k].replace("\\options",
"\\options leqno,")
+ del document.header[i]
+ else:
+ l = find_token(document.header, "\\use_default_options", 0)
+ document.header.insert(l, "\\options leqno")
+ del document.header[i + 1]
+
+
##
# Conversion hub
#
@@ -2180,9 +2221,11 @@ convert = [
[539, []],
[540, []],
[541, [convert_allowbreak]],
- ]
+ [542, [convert_mathnumberpos]]
+ ]
revert = [
+ [541, [revert_mathnumberpos]],
[540, [revert_allowbreak]],
[539, [revert_rotfloat]],
[538, [revert_baselineskip]],
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 9ef1fdb..bdfbc59 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -385,6 +385,7 @@ BufferParams::BufferParams()
makeDocumentClass();
paragraph_separation = ParagraphIndentSeparation;
is_math_indent = false;
+ math_number_before = false;
quotes_style = InsetQuotesParams::EnglishQuotes;
dynamic_quotes = false;
fontsize = "default";
@@ -852,6 +853,8 @@ string BufferParams::readToken(Lexer & lex, string const &
token,
} else if (token == "\\math_indentation") {
lex.next();
pimpl_->mathindent = Length(lex.getString());
+ } else if (token == "\\math_number_before") {
+ lex >> math_number_before;
} else if (token == "\\quotes_style") {
string qstyle;
lex >> qstyle;
@@ -1352,6 +1355,7 @@ void BufferParams::writeFile(ostream & os, Buffer const *
buf) const
os << "\n\\is_math_indent " << is_math_indent;
if (is_math_indent && !getMathIndent().empty())
os << "\n\\math_indentation " << getMathIndent().asString();
+ os << "\n\\math_number_before " << math_number_before;
os << "\n\\quotes_style "
<< string_quotes_style[quotes_style]
<< "\n\\dynamic_quotes " << dynamic_quotes
@@ -1636,6 +1640,9 @@ bool BufferParams::writeLaTeX(otexstream & os,
LaTeXFeatures & features,
if (is_math_indent)
clsoptions << "fleqn,";
+ if (math_number_before)
+ clsoptions << "leqno,";
+
// language should be a parameter to \documentclass
if (language->babel() == "hebrew"
&& default_language->babel() != "hebrew")
diff --git a/src/BufferParams.h b/src/BufferParams.h
index 3b4724d..1c23d6c 100644
--- a/src/BufferParams.h
+++ b/src/BufferParams.h
@@ -109,6 +109,10 @@ public:
/// Whether formulas are indented
bool is_math_indent;
+
+ /// number formulas before them
+ bool math_number_before;
+
/** Whether paragraphs are separated by using a indent like in
* articles or by using a little skip like in letters.
*/
diff --git a/src/frontends/qt4/GuiDocument.cpp
b/src/frontends/qt4/GuiDocument.cpp
index 9d45890..353cd32 100644
--- a/src/frontends/qt4/GuiDocument.cpp
+++ b/src/frontends/qt4/GuiDocument.cpp
@@ -1279,6 +1279,12 @@ GuiDocument::GuiDocument(GuiView & lv)
this, SLOT(change_adaptor()));
connect(mathsModule->allPackagesNotPB, SIGNAL(clicked()),
this, SLOT(change_adaptor()));
+ connect(mathsModule->MathNumberingPosCO, SIGNAL(activated(int)),
+ this, SLOT(change_adaptor()));
+
+ mathsModule->MathNumberingPosCO->addItem(qt_("Before"));
+ mathsModule->MathNumberingPosCO->addItem(qt_("After"));
+ mathsModule->MathNumberingPosCO->setCurrentIndex(2);
// latex class
@@ -2922,6 +2928,19 @@ void GuiDocument::applyView()
textLayoutModule->MathIndentLengthCO));
bp_.setMathIndent(mathindent);
}
+ switch (mathsModule->MathNumberingPosCO->currentIndex()) {
+ case 0:
+ bp_.math_number_before = true;
+ break;
+ case 1:
+ bp_.math_number_before = false;
+ break;
+ default:
+ // this should never happen
+ bp_.math_number_before = false;
+ break;
+ }
+
// Page Layout
if (pageLayoutModule->pagestyleCO->currentIndex() == 0)
bp_.pagestyle = "default";
@@ -3403,6 +3422,10 @@ void GuiDocument::paramsToDialog()
textLayoutModule->MathIndentCO->setCurrentIndex(indent);
setMathIndent(indent);
}
+ if (bp_.math_number_before)
+ mathsModule->MathNumberingPosCO->setCurrentIndex(0);
+ else
+ mathsModule->MathNumberingPosCO->setCurrentIndex(1);
map<string, string> const & packages = BufferParams::auto_packages();
for (map<string, string>::const_iterator it = packages.begin();
diff --git a/src/frontends/qt4/ui/MathsUi.ui b/src/frontends/qt4/ui/MathsUi.ui
index 691d205..ec3e8c4 100644
--- a/src/frontends/qt4/ui/MathsUi.ui
+++ b/src/frontends/qt4/ui/MathsUi.ui
@@ -13,30 +13,7 @@
<property name="windowTitle">
<string/>
</property>
- <layout class="QGridLayout" name="gridLayout_2">
- <item row="0" column="0" colspan="4">
- <widget class="QTableWidget" name="packagesTW">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="columnCount">
- <number>4</number>
- </property>
- <attribute name="horizontalHeaderStretchLastSection">
- <bool>false</bool>
- </attribute>
- <attribute name="verticalHeaderVisible">
- <bool>false</bool>
- </attribute>
- <column/>
- <column/>
- <column/>
- <column/>
- </widget>
- </item>
+ <layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="allPakcagesLA">
<property name="text">
@@ -44,27 +21,86 @@
</property>
</widget>
</item>
- <item row="1" column="1">
+ <item row="1" column="1" colspan="2">
<widget class="QPushButton" name="allPackagesAutoPB">
<property name="text">
<string>Load A&utomatically</string>
</property>
</widget>
</item>
- <item row="1" column="2">
+ <item row="1" column="3">
<widget class="QPushButton" name="allPackagesAlwaysPB">
<property name="text">
<string>Load Alwa&ys</string>
</property>
</widget>
</item>
- <item row="1" column="3">
+ <item row="1" column="4" colspan="2">
<widget class="QPushButton" name="allPackagesNotPB">
<property name="text">
<string>Do &Not Load</string>
</property>
</widget>
</item>
+ <item row="2" column="0" colspan="2">
+ <widget class="QLabel" name="MathNumberingPosL">
+ <property name="minimumSize">
+ <size>
+ <width>115</width>
+ <height>18</height>
+ </size>
+ </property>
+ <property name="text">
+ <string>Number formulas:</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="2" colspan="2">
+ <widget class="QComboBox" name="MathNumberingPosCO">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="toolTip">
+ <string>Size of the indentation</string>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="5">
+ <spacer name="horizontalSpacer_1">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>268</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="0" column="0" colspan="6">
+ <widget class="QTableWidget" name="packagesTW">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="columnCount">
+ <number>4</number>
+ </property>
+ <attribute name="horizontalHeaderStretchLastSection">
+ <bool>false</bool>
+ </attribute>
+ <attribute name="verticalHeaderVisible">
+ <bool>false</bool>
+ </attribute>
+ <column/>
+ <column/>
+ <column/>
+ <column/>
+ </widget>
+ </item>
</layout>
</widget>
<includes>
diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index 08d019c..9465331 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -494,6 +494,7 @@ Preamble::Preamble() : one_language(true),
explicit_babel(false),
h_font_tt_scale[1] = "100";
//h_font_cjk
h_is_mathindent = "0";
+ h_math_number_before = "0";
h_graphics = "default";
h_default_output_format = "default";
h_html_be_strict = "false";
@@ -1293,6 +1294,7 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc,
string const & outfiled
os << "\\is_math_indent " << h_is_mathindent << "\n";
if (!h_mathindentation.empty())
os << "\\math_indentation " << h_mathindentation << "\n";
+ os << "\\math_number_before " << h_math_number_before << "\n";
os << "\\quotes_style " << h_quotes_style << "\n"
<< "\\dynamic_quotes " << h_dynamic_quotes << "\n"
<< "\\papercolumns " << h_papercolumns << "\n"
@@ -1687,6 +1689,13 @@ void Preamble::parse(Parser & p, string const &
forceclass,
h_is_mathindent = "1";
opts.erase(it);
}
+ // formula numbering side
+ if ((it = find(opts.begin(), opts.end(), "leqno"))
+ != opts.end()) {
+ h_math_number_before = "1";
+ opts.erase(it);
+ }
+
// paper orientation
if ((it = find(opts.begin(), opts.end(), "landscape"))
!= opts.end()) {
h_paperorientation = "landscape";
diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h
index 68842b6..8461983 100644
--- a/src/tex2lyx/Preamble.h
+++ b/src/tex2lyx/Preamble.h
@@ -154,6 +154,7 @@ private:
std::string h_font_cjk;
std::string h_use_microtype;
std::string h_is_mathindent;
+ std::string h_math_number_before;
std::string h_mathindentation;
std::string h_graphics;
std::string h_default_output_format;
diff --git a/src/version.h b/src/version.h
index 84690c4..fd86ea6 100644
--- a/src/version.h
+++ b/src/version.h
@@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 541 // milde: \SpecialChar allowbreak
-#define LYX_FORMAT_TEX2LYX 541
+#define LYX_FORMAT_LYX 542 // uwestoehr: support for class option leqno
+#define LYX_FORMAT_TEX2LYX 542
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER