The branch, master, has been updated.

- Log -----------------------------------------------------------------

commit 56ece75ad9becba27ff1eaa12a0b8e3c68bb317b
Author: Georg Baum <[email protected]>
Date:   Fri Dec 28 19:51:28 2012 +0100

    Fix bug #8464: stackrel with subscript.
    
    The fix is basically mechanical, the additional code for fraction like 
insets
    with three arguments was stolen from \unitfrac. As any math package,
    stackrel.sty needs a buffer parameter to switch it off.
    I also added the two stackrel flavours to the toolbar.

diff --git a/development/FORMAT b/development/FORMAT
index 033e9be..0a8bdbf 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in 
lyx2lyx.
 
 -----------------------
 
+2012-12-28 Georg Baum  <[email protected]>
+       * Format incremented to 457
+         support for the LaTeX-package stackrel (fix bug 8464)
+         New buffer param \use_package stackrel
+
 2012-12-28 Jürgen Spitzmüller <[email protected]>
        * Format incremented to 456: Proper support for memoir \epigraph
          \epigraph{text}{source} > begin_layout Epigraph, <source> as
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 7fe8e42..96ed545 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -978,6 +978,8 @@ dist_imagesmath_DATA = \
        images/math/ssearrow.png \
        images/math/sslash.png \
        images/math/sswarrow.png \
+       images/math/stackrel.png \
+       images/math/stackrelthree.png \
        images/math/star.png \
        images/math/style.png \
        images/math/sub.png \
diff --git a/lib/chkconfig.ltx b/lib/chkconfig.ltx
index 22297e5..b9926b5 100644
--- a/lib/chkconfig.ltx
+++ b/lib/chkconfig.ltx
@@ -343,6 +343,7 @@
 \TestPackage{slashed}
 \TestPackage{soul}
 \TestPackage{splitidx}
+\TestPackage{stackrel}
 \TestPackage{stmaryrd}
 \TestPackage{subfig}
 \TestPackage{Sweave}
diff --git a/lib/doc/LaTeXConfig.lyx b/lib/doc/LaTeXConfig.lyx
index 01de5ab..e961727 100644
--- a/lib/doc/LaTeXConfig.lyx
+++ b/lib/doc/LaTeXConfig.lyx
@@ -6581,6 +6581,36 @@ splitindex
 \end_layout
 
 \begin_layout Subsection
+stackrel
+\end_layout
+
+\begin_layout Description
+Found: 
+\begin_inset Info
+type  "package"
+arg   "stackrel"
+\end_inset
+
+
+\end_layout
+
+\begin_layout Description
+CTAN: 
+\family typewriter
+macros/latex/contrib/oberdiek
+\end_layout
+
+\begin_layout Description
+Notes: The package 
+\family sans
+stackrel
+\family default
+ is needed by LyX to be able to output formulas using the 
+\backslash
+stackrel command with subscript.
+\end_layout
+
+\begin_layout Subsection
 stmaryrd
 \end_layout
 
diff --git a/lib/images/math/stackrel.png b/lib/images/math/stackrel.png
new file mode 100644
index 0000000..05bee5f
Binary files /dev/null and b/lib/images/math/stackrel.png differ
diff --git a/lib/images/math/stackrelthree.png 
b/lib/images/math/stackrelthree.png
new file mode 100644
index 0000000..0c53985
Binary files /dev/null and b/lib/images/math/stackrelthree.png differ
diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py
index 847fc4b..6bc9710 100644
--- a/lib/lyx2lyx/lyx_2_1.py
+++ b/lib/lyx2lyx/lyx_2_1.py
@@ -495,6 +495,49 @@ def revert_use_stmaryrd(document):
             i = j
 
 
+def convert_use_stackrel(document):
+    "insert use_package stackrel"
+    i = find_token(document.header, "\\use_package", 0)
+    if i == -1:
+        document.warning("Malformed LyX document: Can't find \\use_package.")
+        return;
+    j = find_token(document.preamble, "\\usepackage{stackrel}", 0)
+    if j == -1:
+        document.header.insert(i + 1, "\\use_package stackrel 0")
+    else:
+        document.header.insert(i + 1, "\\use_package stackrel 2")
+        del document.preamble[j]
+
+
+def revert_use_stackrel(document):
+    "remove use_package stackrel"
+    regexp = re.compile(r'(\\use_package\s+stackrel)')
+    i = find_re(document.header, regexp, 0)
+    value = "1" # default is auto
+    if i != -1:
+        value = get_value(document.header, "\\use_package" , i).split()[1]
+        del document.header[i]
+    if value == "2": # on
+        add_to_preamble(document, ["\\usepackage{stackrel}"])
+    elif value == "1": # auto
+        regcmd = re.compile(r'.*\\stackrel\s*\[')
+        i = 0
+        while True:
+            i = find_token(document.body, '\\begin_inset Formula', i)
+            if i == -1:
+                return
+            j = find_end_of_inset(document.body, i)
+            if j == -1:
+                document.warning("Malformed LyX document: Can't find end of 
Formula inset at line " + str(i))
+                i += 1
+                continue
+            code = "\n".join(document.body[i:j])
+            if regcmd.match(code):
+                add_to_preamble(document, ["\\usepackage{stackrel}"])
+                return
+            i = j
+
+
 def convert_cite_engine_type(document):
     "Determine the \\cite_engine_type from the citation engine."
     i = find_token(document.header, "\\cite_engine", 0)
@@ -3022,10 +3065,12 @@ convert = [
            [453, [convert_use_stmaryrd]],
            [454, [convert_overprint]],
            [455, []],
-           [456, [convert_epigraph]]
+           [456, [convert_epigraph]],
+           [457, [convert_use_stackrel]]
           ]
 
 revert =  [
+           [456, [revert_use_stackrel]],
            [455, [revert_epigraph]],
            [454, [revert_frametitle]],
            [453, [revert_overprint]],
diff --git a/lib/ui/stdtoolbars.inc b/lib/ui/stdtoolbars.inc
index 2098dea..5e5f038 100644
--- a/lib/ui/stdtoolbars.inc
+++ b/lib/ui/stdtoolbars.inc
@@ -435,6 +435,8 @@ ToolbarSet
                Item "bcancel" "math-insert \bcancel"
                Item "xcancel" "math-insert \xcancel"
                Item "cancelto" "math-insert \cancelto"
+               Item "stackrel" "math-insert \stackrel"
+               Item "stackrelthree" "math-insert \stackrelthree"
        End
 
        Toolbar "latex_arrow" "Arrows"
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 4a009aa..0b0965c 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -454,6 +454,7 @@ vector<string> const & BufferParams::auto_packages()
                packages.push_back("mathdots");
                packages.push_back("mathtools");
                packages.push_back("mhchem");
+               packages.push_back("stackrel");
                packages.push_back("stmaryrd");
                packages.push_back("undertilde");
        }
diff --git a/src/BufferParams.h b/src/BufferParams.h
index 80025ab..1bff132 100644
--- a/src/BufferParams.h
+++ b/src/BufferParams.h
@@ -519,7 +519,7 @@ private:
 
        typedef std::map<std::string, Package> PackageMap;
        /** Whether and how to load packages like amsmath, esint, mhchem,
-        *  mathdots and undertilde.
+        *  mathdots, stackrel, stmaryrd and undertilde.
         */
        PackageMap use_packages;
 
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index 9a73c8e..6b23fc5 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -851,6 +851,10 @@ string const LaTeXFeatures::getPackages() const
            params_.use_package("stmaryrd") != BufferParams::package_off)
                packages << "\\usepackage{stmaryrd}\n";
 
+       if (mustProvide("stackrel") &&
+           params_.use_package("stackrel") != BufferParams::package_off)
+               packages << "\\usepackage{stackrel}\n";
+
        if (mustProvide("undertilde") &&
                params_.use_package("undertilde") != BufferParams::package_off)
                packages << "\\usepackage{undertilde}\n";
diff --git a/src/frontends/qt4/GuiDocument.cpp 
b/src/frontends/qt4/GuiDocument.cpp
index 180a83a..2ce8393 100644
--- a/src/frontends/qt4/GuiDocument.cpp
+++ b/src/frontends/qt4/GuiDocument.cpp
@@ -156,6 +156,10 @@ char const * packages_gui[][4] =
         N_("Use mhchem &package automatically"),
         N_("Use mh&chem package"),
         N_("The LaTeX package mhchem is only used if either the command \\ce 
or \\cf is inserted into formulas")},
+       {"stackrel",
+        N_("Use stackrel package automatically"),
+        N_("Use stackrel package"),
+        N_("The LaTeX package stackrel is only used if the command \\stackrel 
with subscript is inserted into formulas")},
        {"stmaryrd",
         N_("Use stmaryrd package automatically"),
         N_("Use stmaryrd package"),
diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp
index 0e43525..e3ed60a 100644
--- a/src/mathed/InsetMathNest.cpp
+++ b/src/mathed/InsetMathNest.cpp
@@ -2099,6 +2099,7 @@ MathCompletionList::MathCompletionList(Cursor const & cur)
        globals.push_back(from_ascii("\\root"));
        globals.push_back(from_ascii("\\tabular"));
        globals.push_back(from_ascii("\\stackrel"));
+       globals.push_back(from_ascii("\\stackrelthree"));
        globals.push_back(from_ascii("\\binom"));
        globals.push_back(from_ascii("\\choose"));
        globals.push_back(from_ascii("\\brace"));
diff --git a/src/mathed/InsetMathStackrel.cpp b/src/mathed/InsetMathStackrel.cpp
index 200fde5..d8b9e97 100644
--- a/src/mathed/InsetMathStackrel.cpp
+++ b/src/mathed/InsetMathStackrel.cpp
@@ -12,6 +12,7 @@
 
 #include "InsetMathStackrel.h"
 
+#include "Cursor.h"
 #include "LaTeXFeatures.h"
 #include "MathData.h"
 #include "MathStream.h"
@@ -20,7 +21,8 @@ using namespace std;
 
 namespace lyx {
 
-InsetMathStackrel::InsetMathStackrel(Buffer * buf) : InsetMathFracBase(buf)
+InsetMathStackrel::InsetMathStackrel(Buffer * buf, bool sub)
+       : InsetMathFracBase(buf, sub ? 3 : 2)
 {}
 
 
@@ -30,6 +32,24 @@ Inset * InsetMathStackrel::clone() const
 }
 
 
+bool InsetMathStackrel::idxUpDown(Cursor & cur, bool up) const
+{
+       if (up) {
+               if (cur.idx() == 0)
+                       return false;
+       } else {
+               if (cur.idx() + 1 ==  nargs())
+                       return false;
+       }
+       InsetMath::idx_type target = up ? cur.idx() - 1 : cur.idx() + 1;
+       if (cur.idx() == target)
+               return false;
+       cur.idx() = target;
+       cur.pos() = cell(target).x2pos(&cur.bv(), cur.x_target());
+       return true;
+}
+
+
 void InsetMathStackrel::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        Dimension dim1;
@@ -37,9 +57,17 @@ void InsetMathStackrel::metrics(MetricsInfo & mi, Dimension 
& dim) const
        FracChanger dummy(mi.base);
        Dimension dim0;
        cell(0).metrics(mi, dim0);
-       dim.wid = max(dim0.width(), dim1.width()) + 4;
-       dim.asc = dim1.ascent() + dim0.height() + 4;
-       dim.des = dim1.descent();
+       if (nargs() > 2) {
+               Dimension dim2;
+               cell(2).metrics(mi, dim2);
+               dim.wid = max(max(dim0.width(), dim1.width()), dim2.width()) + 
4;
+               dim.asc = dim1.ascent() + dim0.height() + 4;
+               dim.des = dim1.descent() + dim2.height() + dim2.descent() + 1;
+       } else {
+               dim.wid = max(dim0.width(), dim1.width()) + 4;
+               dim.asc = dim1.ascent() + dim0.height() + 4;
+               dim.des = dim1.descent();
+       }
        metricsMarkers(dim);
 }
 
@@ -54,6 +82,11 @@ void InsetMathStackrel::draw(PainterInfo & pi, int x, int y) 
const
        cell(1).draw(pi, m - dim1.width() / 2, y);
        FracChanger dummy(pi.base);
        cell(0).draw(pi, m - dim0.width() / 2, yo);
+       if (nargs() > 2) {
+               Dimension const & dim2 = cell(2).dimension(*pi.base.bv);
+               int y2 = y + dim1.descent() + dim2.ascent() + 1;
+               cell(2).draw(pi, m - dim2.width() / 2, y2);
+       }
        drawMarkers(pi, x, y);
 }
 
@@ -61,40 +94,69 @@ void InsetMathStackrel::draw(PainterInfo & pi, int x, int 
y) const
 void InsetMathStackrel::write(WriteStream & os) const
 {
        MathEnsurer ensurer(os);
-       os << "\\stackrel{" << cell(0) << "}{" << cell(1) << '}';
+       os << "\\stackrel";
+       if (nargs() > 2)
+               os << '[' << cell(2) << ']';
+       os << '{' << cell(0) << "}{" << cell(1) << '}';
 }
 
 
 void InsetMathStackrel::normalize(NormalStream & os) const
 {
-       os << "[stackrel " << cell(0) << ' ' << cell(1) << ']';
+       os << "[stackrel " << cell(0) << ' ' << cell(1);
+       if (nargs() > 2)
+               os << ' ' << cell(2);
+       os << ']';
 }
 
 
 void InsetMathStackrel::mathmlize(MathStream & ms) const
 {
-       ms << "<mover accent='false'>" << cell(1) << cell(0) << "</mover>";
+       if (nargs() > 2)
+               ms << "<munderover>" << cell(1) << cell(2) << cell(0) << 
"</munderover>";
+       else
+               ms << "<mover accent='false'>" << cell(1) << cell(0) << 
"</mover>";
 }
 
 
 void InsetMathStackrel::htmlize(HtmlStream & os) const
 {
-       // at the moment, this is exactly the same as overset
-       os << MTag("span", "class='overset'")
-                << MTag("span", "class='top'") << cell(0) << ETag("span")
-                << MTag("span") << cell(1) << ETag("span")
-                << ETag("span");
+       if (nargs() > 2) {
+               os << MTag("span", "class='underoverset'")
+                  << MTag("span", "class='top'") << cell(0) << ETag("span")
+                  << MTag("span") << cell(1) << ETag("span")
+                  << MTag("span", "class='bottom'") << cell(2) << ETag("span");
+       } else {
+               // at the moment, this is exactly the same as overset
+               os << MTag("span", "class='overset'")
+                  << MTag("span", "class='top'") << cell(0) << ETag("span")
+                  << MTag("span") << cell(1) << ETag("span");
+       }
+       os << ETag("span");
 }
 
 
 void InsetMathStackrel::validate(LaTeXFeatures & features) const
 {
-       // from overset
-       if (features.runparams().math_flavor == OutputParams::MathAsHTML)
-               features.addCSSSnippet(
-                       "span.overset{display: inline-block; vertical-align: 
bottom; text-align:center;}\n"
-                       "span.overset span {display: block;}\n"
-                       "span.top{font-size: 66%;}");
+       if (features.runparams().math_flavor == OutputParams::MathAsHTML) {
+               if (nargs() > 2) {
+                       // FIXME: "vertical-align: middle" works only if the
+                       // height of sub and super script is approximately 
equal.
+                       features.addCSSSnippet(
+                               "span.underoverset{display: inline-block; 
vertical-align: middle; text-align:center;}\n"
+                               "span.underoverset span {display: block;}\n"
+                               "span.bottom{font-size: 66%;}\n"
+                               "span.top{font-size: 66%;}");
+               } else {
+                       // from overset
+                       features.addCSSSnippet(
+                               "span.overset{display: inline-block; 
vertical-align: bottom; text-align:center;}\n"
+                               "span.overset span {display: block;}\n"
+                               "span.top{font-size: 66%;}");
+               }
+       }
+       if (nargs() > 2)
+               features.require("stackrel");
 
        InsetMathNest::validate(features);
 }
diff --git a/src/mathed/InsetMathStackrel.h b/src/mathed/InsetMathStackrel.h
index 11160c3..91862a7 100644
--- a/src/mathed/InsetMathStackrel.h
+++ b/src/mathed/InsetMathStackrel.h
@@ -20,7 +20,9 @@ namespace lyx {
 class InsetMathStackrel : public InsetMathFracBase {
 public:
        ///
-       InsetMathStackrel(Buffer * buf);
+       InsetMathStackrel(Buffer * buf, bool sub);
+       ///
+       bool idxUpDown(Cursor &, bool up) const;
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
diff --git a/src/mathed/MathFactory.cpp b/src/mathed/MathFactory.cpp
index 29d9a5f..5266eda 100644
--- a/src/mathed/MathFactory.cpp
+++ b/src/mathed/MathFactory.cpp
@@ -453,7 +453,10 @@ MathAtom createInsetMath(docstring const & s, Buffer * buf)
        if (s == "tabular")
                return MathAtom(new InsetMathTabular(buf, s, 1, 1));
        if (s == "stackrel")
-               return MathAtom(new InsetMathStackrel(buf));
+               return MathAtom(new InsetMathStackrel(buf, false));
+       // This string value is only for math toolbar use, no LaTeX name
+       if (s == "stackrelthree")
+               return MathAtom(new InsetMathStackrel(buf, true));
        if (s == "binom")
                return MathAtom(new InsetMathBinom(buf, InsetMathBinom::BINOM));
        if (s == "dbinom")
diff --git a/src/mathed/MathParser.cpp b/src/mathed/MathParser.cpp
index 1982af3..3f20df5 100644
--- a/src/mathed/MathParser.cpp
+++ b/src/mathed/MathParser.cpp
@@ -59,6 +59,7 @@ following hack as starting point to write some macros:
 #include "InsetMathSpace.h"
 #include "InsetMathSplit.h"
 #include "InsetMathSqrt.h"
+#include "InsetMathStackrel.h"
 #include "InsetMathString.h"
 #include "InsetMathTabular.h"
 #include "MathMacroTemplate.h"
@@ -1441,6 +1442,17 @@ bool Parser::parse1(InsetMathGrid & grid, unsigned flags,
                        parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode);
                }
 
+               else if (t.cs() == "stackrel") {
+                       // Here allowed formats are 
\stackrel[subscript]{superscript}{operator}
+                       MathData ar;
+                       parse(ar, FLAG_OPTION, mode);
+                       cell->push_back(MathAtom(new InsetMathStackrel(buf, 
!ar.empty())));
+                       if (!ar.empty())
+                               cell->back().nucleus()->cell(2) = ar;
+                       parse(cell->back().nucleus()->cell(0), FLAG_ITEM, mode);
+                       parse(cell->back().nucleus()->cell(1), FLAG_ITEM, mode);
+               }
+
                else if (t.cs() == "xrightarrow" || t.cs() == "xleftarrow") {
                        cell->push_back(createInsetMath(t.cs(), buf));
                        parse(cell->back().nucleus()->cell(1), FLAG_OPTION, 
mode);
diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index fe6de69..31ac091 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -517,6 +517,7 @@ Preamble::Preamble() : one_language(true), 
title_layout_found(false)
        h_use_packages["mhchem"]     = "0";
        h_use_packages["mathdots"]   = "0";
        h_use_packages["mathtools"]  = "0";
+       h_use_packages["stackrel"]   = "0";
        h_use_packages["stmaryrd"]   = "0";
        h_use_packages["undertilde"] = "0";
 }
@@ -703,8 +704,8 @@ void Preamble::handle_package(Parser &p, string const & 
name,
 
        else if (name == "amsmath" || name == "amssymb" ||
                 name == "esint" || name == "mhchem" || name == "mathdots" ||
-                name == "mathtools" || name == "stmaryrd" ||
-                name == "undertilde")
+                name == "mathtools" || name == "stackrel" ||
+                name == "stmaryrd" || name == "undertilde")
                h_use_packages[name] = "2";
 
        else if (name == "babel") {
diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt
index f2ae0ef..162d07f 100644
--- a/src/tex2lyx/TODO.txt
+++ b/src/tex2lyx/TODO.txt
@@ -97,6 +97,7 @@ Format LaTeX feature                        LyX feature
 455    beamer frametitle command            \begin_layout FrameTitle
        \frametitle<overlay>[short}{long}
 456    memoir: \epigraph{text}{source}      layout Epigraph, InsetArgument
+457    automatic stackrel loading           \use_package stackrel
 
 
 General
diff --git a/src/tex2lyx/test/CJK.lyx.lyx b/src/tex2lyx/test/CJK.lyx.lyx
index 6ebad1a..a6c5cda 100644
--- a/src/tex2lyx/test/CJK.lyx.lyx
+++ b/src/tex2lyx/test/CJK.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.1.0dev
-\lyxformat 456
+\lyxformat 457
 \begin_document
 \begin_header
 \textclass article
@@ -46,6 +46,7 @@
 \use_package mathdots 0
 \use_package mathtools 0
 \use_package mhchem 0
+\use_package stackrel 0
 \use_package stmaryrd 0
 \use_package undertilde 0
 \cite_engine basic
diff --git a/src/tex2lyx/test/DummyDocument.lyx 
b/src/tex2lyx/test/DummyDocument.lyx
index fefacc0..38d6bc3 100644
--- a/src/tex2lyx/test/DummyDocument.lyx
+++ b/src/tex2lyx/test/DummyDocument.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.1.0dev
-\lyxformat 456
+\lyxformat 457
 \begin_document
 \begin_header
 \textclass article
@@ -44,6 +44,7 @@
 \use_package mathdots 0
 \use_package mathtools 0
 \use_package mhchem 0
+\use_package stackrel 0
 \use_package stmaryrd 0
 \use_package undertilde 0
 \cite_engine natbib
diff --git a/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx 
b/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
index 23bf90d..b907949 100644
--- a/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
+++ b/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.1.0dev
-\lyxformat 456
+\lyxformat 457
 \begin_document
 \begin_header
 \textclass article
@@ -46,6 +46,7 @@
 \use_package mathdots 0
 \use_package mathtools 0
 \use_package mhchem 0
+\use_package stackrel 0
 \use_package stmaryrd 0
 \use_package undertilde 0
 \cite_engine basic
diff --git a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx 
b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
index 0ddc59d..1315f5e 100644
--- a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
+++ b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.1.0dev
-\lyxformat 456
+\lyxformat 457
 \begin_document
 \begin_header
 \textclass article
@@ -70,6 +70,7 @@
 \use_package mathdots 0
 \use_package mathtools 0
 \use_package mhchem 0
+\use_package stackrel 0
 \use_package stmaryrd 0
 \use_package undertilde 0
 \cite_engine basic
diff --git a/src/tex2lyx/test/test-insets.lyx.lyx 
b/src/tex2lyx/test/test-insets.lyx.lyx
index 7b1b4c9..df5c9cc 100644
--- a/src/tex2lyx/test/test-insets.lyx.lyx
+++ b/src/tex2lyx/test/test-insets.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.1.0dev
-\lyxformat 456
+\lyxformat 457
 \begin_document
 \begin_header
 \textclass article
@@ -50,6 +50,7 @@
 \use_package mathdots 0
 \use_package mathtools 0
 \use_package mhchem 0
+\use_package stackrel 0
 \use_package stmaryrd 0
 \use_package undertilde 0
 \cite_engine natbib
diff --git a/src/tex2lyx/test/test-modules.lyx.lyx 
b/src/tex2lyx/test/test-modules.lyx.lyx
index 226102c..f1bc385 100644
--- a/src/tex2lyx/test/test-modules.lyx.lyx
+++ b/src/tex2lyx/test/test-modules.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.1.0dev
-\lyxformat 456
+\lyxformat 457
 \begin_document
 \begin_header
 \textclass amsart
@@ -42,6 +42,7 @@ theorems-ams
 \use_package mathdots 0
 \use_package mathtools 0
 \use_package mhchem 0
+\use_package stackrel 0
 \use_package stmaryrd 0
 \use_package undertilde 0
 \cite_engine basic
diff --git a/src/tex2lyx/test/test-structure.lyx.lyx 
b/src/tex2lyx/test/test-structure.lyx.lyx
index ea9ddab..65ee7a3 100644
--- a/src/tex2lyx/test/test-structure.lyx.lyx
+++ b/src/tex2lyx/test/test-structure.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.1.0dev
-\lyxformat 456
+\lyxformat 457
 \begin_document
 \begin_header
 \textclass article
@@ -75,6 +75,7 @@ logicalmkup
 \use_package mathdots 0
 \use_package mathtools 0
 \use_package mhchem 0
+\use_package stackrel 0
 \use_package stmaryrd 0
 \use_package undertilde 0
 \cite_engine basic
diff --git a/src/tex2lyx/test/test.lyx.lyx b/src/tex2lyx/test/test.lyx.lyx
index ba14fab..4eaaba7 100644
--- a/src/tex2lyx/test/test.lyx.lyx
+++ b/src/tex2lyx/test/test.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.1.0dev
-\lyxformat 456
+\lyxformat 457
 \begin_document
 \begin_header
 \textclass article
@@ -46,6 +46,7 @@
 \use_package mathdots 0
 \use_package mathtools 0
 \use_package mhchem 0
+\use_package stackrel 0
 \use_package stmaryrd 0
 \use_package undertilde 0
 \cite_engine basic
diff --git a/src/version.h b/src/version.h
index 5cab79e..aad31fe 100644
--- a/src/version.h
+++ b/src/version.h
@@ -30,8 +30,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 456 // spitz: proper support for memoir epigraph
-#define LYX_FORMAT_TEX2LYX 456 // spitz: proper support for memoir epigraph
+#define LYX_FORMAT_LYX 457 // gb: automatic stackrel package loading
+#define LYX_FORMAT_TEX2LYX 457 // gb: automatic stackrel package loading
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER

commit 8693f5a91e6a394429498ab035e2aca4a48c4d29
Author: Georg Baum <[email protected]>
Date:   Fri Dec 28 14:29:46 2012 +0100

    Fix bug #8422.
    
    Both problems where caused by the fact that tex2lyx did not handle
    natbib/jurabib citations correctly if natbib/jurabib was loaded by the
    document class. Therefore it tried to parse the standard \cite syntax, and
    did not recognize \citet and \citep.

diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h
index db2242f..d438c95 100644
--- a/src/tex2lyx/Preamble.h
+++ b/src/tex2lyx/Preamble.h
@@ -62,6 +62,10 @@ public:
        ///
        void suppressDate(bool suppress);
        ///
+       std::string citeEngine() const { return h_cite_engine; }
+       ///
+       void citeEngine(std::string const & e) { h_cite_engine = e; }
+       ///
        bool titleLayoutFound() const { return title_layout_found; }
        ///
        void titleLayoutFound(bool found) { title_layout_found = found; }
diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp
index ceb4e92..ea20561 100644
--- a/src/tex2lyx/tex2lyx.cpp
+++ b/src/tex2lyx/tex2lyx.cpp
@@ -446,6 +446,13 @@ bool checkModule(string const & name, bool command)
 }
 
 
+bool isProvided(string const & name)
+{
+       // This works only for features that are named like the LaTeX packages
+       return textclass.provides(name) || preamble.isPackageUsed(name);
+}
+
+
 bool noweb_mode = false;
 bool pdflatex = false;
 bool xetex = false;
diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h
index e3da48b..94f2497 100644
--- a/src/tex2lyx/tex2lyx.h
+++ b/src/tex2lyx/tex2lyx.h
@@ -118,6 +118,8 @@ extern InsetLayout const * findInsetLayoutWithoutModule(
  * list of used modules if yes.
  */
 extern bool checkModule(std::string const & name, bool command);
+/// Is this feature already provided e.g. by the document class?
+extern bool isProvided(std::string const & name);
 // Access to environment stack
 extern std::vector<std::string> active_environments;
 std::string active_environment();
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index f406869..c90b3cd 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -2161,8 +2161,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, 
bool outer,
        // (needed for bibtex inset)
        string btprint;
        string bibliographystyle = "default";
-       bool const use_natbib = preamble.isPackageUsed("natbib");
-       bool const use_jurabib = preamble.isPackageUsed("jurabib");
+       bool const use_natbib = isProvided("natbib");
+       bool const use_jurabib = isProvided("jurabib");
        string last_env;
        while (p.good()) {
                Token const & t = p.get_token();
@@ -3371,6 +3371,10 @@ void parse_text(Parser & p, ostream & os, unsigned 
flags, bool outer,
                           << convert_command_inset_arg(p.verbatim_item())
                           << "\"\n";
                        end_inset(os);
+                       // Need to set the cite engine if natbib is loaded by
+                       // the document class directly
+                       if (preamble.citeEngine() == "basic")
+                               preamble.citeEngine("natbib");
                }
 
                else if (use_jurabib &&
@@ -3421,6 +3425,10 @@ void parse_text(Parser & p, ostream & os, unsigned 
flags, bool outer,
                        os << "before " << '"' << before << '"' << "\n";
                        os << "key " << '"' << citation << '"' << "\n";
                        end_inset(os);
+                       // Need to set the cite engine if jurabib is loaded by
+                       // the document class directly
+                       if (preamble.citeEngine() == "basic")
+                               preamble.citeEngine("jurabib");
                }
 
                else if (t.cs() == "cite"

commit 594c83261a1a7c124f17ffb3f1375704a75fbea0
Author: Georg Baum <[email protected]>
Date:   Fri Dec 28 14:22:49 2012 +0100

    Update tex2lyx test cases
    
    The recent file format changes do not change the output of the existing test
    cases, so only the version number needs to be updated.

diff --git a/src/tex2lyx/test/DummyDocument.lyx 
b/src/tex2lyx/test/DummyDocument.lyx
index 7f95c83..fefacc0 100644
--- a/src/tex2lyx/test/DummyDocument.lyx
+++ b/src/tex2lyx/test/DummyDocument.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.1.0dev
-\lyxformat 453
+\lyxformat 456
 \begin_document
 \begin_header
 \textclass article

-----------------------------------------------------------------------

Summary of changes:
 development/FORMAT                                 |    5 +
 lib/Makefile.am                                    |    2 +
 lib/chkconfig.ltx                                  |    1 +
 lib/doc/LaTeXConfig.lyx                            |   30 ++++++
 lib/images/math/stackrel.png                       |  Bin 0 -> 195 bytes
 lib/images/math/stackrelthree.png                  |  Bin 0 -> 209 bytes
 lib/lyx2lyx/lyx_2_1.py                             |   47 +++++++++-
 lib/ui/stdtoolbars.inc                             |    2 +
 src/BufferParams.cpp                               |    1 +
 src/BufferParams.h                                 |    2 +-
 src/LaTeXFeatures.cpp                              |    4 +
 src/frontends/qt4/GuiDocument.cpp                  |    4 +
 src/mathed/InsetMathNest.cpp                       |    1 +
 src/mathed/InsetMathStackrel.cpp                   |   98 ++++++++++++++++----
 src/mathed/InsetMathStackrel.h                     |    4 +-
 src/mathed/MathFactory.cpp                         |    5 +-
 src/mathed/MathParser.cpp                          |   12 +++
 src/tex2lyx/Preamble.cpp                           |    5 +-
 src/tex2lyx/Preamble.h                             |    4 +
 src/tex2lyx/TODO.txt                               |    1 +
 src/tex2lyx/test/CJK.lyx.lyx                       |    3 +-
 src/tex2lyx/test/DummyDocument.lyx                 |    3 +-
 src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx         |    3 +-
 .../test/box-color-size-space-align.lyx.lyx        |    3 +-
 src/tex2lyx/test/test-insets.lyx.lyx               |    3 +-
 src/tex2lyx/test/test-modules.lyx.lyx              |    3 +-
 src/tex2lyx/test/test-structure.lyx.lyx            |    3 +-
 src/tex2lyx/test/test.lyx.lyx                      |    3 +-
 src/tex2lyx/tex2lyx.cpp                            |    7 ++
 src/tex2lyx/tex2lyx.h                              |    2 +
 src/tex2lyx/text.cpp                               |   12 ++-
 src/version.h                                      |    4 +-
 32 files changed, 241 insertions(+), 36 deletions(-)
 create mode 100644 lib/images/math/stackrel.png
 create mode 100644 lib/images/math/stackrelthree.png


hooks/post-receive
-- 
The LyX Source Repository

Reply via email to