commit fc546b7dcc793a77b44c2f3e3abc780d768a18ed
Author: Juergen Spitzmueller <[email protected]>
Date:   Fri Jan 13 18:23:42 2017 +0100

    Basic support for natbib & jurabib options
    
    This re-uses the options line edit introduced for biblatex.
---
 development/FORMAT                |    4 +++
 lib/lyx2lyx/lyx_2_3.py            |   48 ++++++++++++++++++++++++++++++++++++-
 src/CiteEnginesList.cpp           |    6 ++++
 src/CiteEnginesList.h             |    2 +
 src/LaTeXFeatures.cpp             |   10 ++++++-
 src/frontends/qt4/GuiDocument.cpp |   13 ++++++++-
 src/frontends/qt4/ui/BiblioUi.ui  |    4 +-
 src/version.h                     |    4 +-
 8 files changed, 82 insertions(+), 9 deletions(-)

diff --git a/development/FORMAT b/development/FORMAT
index eb60572..3c4f115 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -8,6 +8,10 @@ changes happened in particular if possible. A good example 
would be
 -----------------------
 
 2017-01-13 Jürgen Spitzmüller <[email protected]>
+       * Format incremented to 530: Support natbib & jurabib package options.
+
+
+2017-01-13 Jürgen Spitzmüller <[email protected]>
        * Format incremented to 529:
          \begin_inset CommandInset citation
            New LatexCommand value: keyonly -> outputs only the key,
diff --git a/lib/lyx2lyx/lyx_2_3.py b/lib/lyx2lyx/lyx_2_3.py
index a2adde7..762c884 100644
--- a/lib/lyx2lyx/lyx_2_3.py
+++ b/lib/lyx2lyx/lyx_2_3.py
@@ -1400,6 +1400,50 @@ def revert_citekeyonly(document):
         i = j + 1
 
 
+
+def revert_bibpackopts(document):
+    " Revert support for natbib/jurabib package options "
+
+    engine = "basic"
+    i = find_token(document.header, "\\cite_engine", 0)
+    if i == -1:
+        document.warning("Malformed document! Missing \\cite_engine")
+    else:
+        engine = get_value(document.header, "\\cite_engine", i)
+
+    biblatex = False
+    if engine not in ["natbib", "jurabib"]:
+        return
+
+    biblio_options = ""
+    i = find_token(document.header, "\\biblio_options", 0)
+    if i != -1:
+        biblio_options = get_value(document.header, "\\biblio_options", i)
+        del document.header[i]
+
+    i = find_token(document.header, "\\begin_local_layout", 0)
+    if i == -1:
+        k = find_token(document.header, "\\language", 0)
+        if k == -1:
+            # this should not happen
+            document.warning("Malformed LyX document! No \\language header 
found!")
+            return
+        document.header[k-1 : k-1] = ["\\begin_local_layout", 
"\\end_local_layout"]
+        i = k - 1
+
+    j = find_end_of(document.header, i, "\\begin_local_layout", 
"\\end_local_layout")
+    if j == -1:
+        # this should not happen
+        document.warning("Malformed LyX document! Can't find end of local 
layout!")
+        return
+
+    document.header[i+1 : i+1] = [
+        "### Inserted by lyx2lyx (bibliography package options) ###",
+        "PackageOptions " + engine + " " + biblio_options,
+        "### End of insertion by lyx2lyx (bibliography package options) ###"
+    ]
+
+
 ##
 # Conversion hub
 #
@@ -1426,10 +1470,12 @@ convert = [
            [526, []],
            [527, []],
            [528, []],
-           [529, []]
+           [529, []],
+           [530, []]
           ]
 
 revert =  [
+           [529, [revert_bibpackopts]],
            [528, [revert_citekeyonly]],
            [527, [revert_biblatex]],
            [526, [revert_noprefix]],
diff --git a/src/CiteEnginesList.cpp b/src/CiteEnginesList.cpp
index 2b8de05..3c10b40 100644
--- a/src/CiteEnginesList.cpp
+++ b/src/CiteEnginesList.cpp
@@ -110,6 +110,12 @@ bool LyXCiteEngine::isDefaultBiblio(string const & bf) 
const
 }
 
 
+bool LyXCiteEngine::requires(const string p) const
+{
+       return find(package_list_.begin(), package_list_.end(), p) != 
package_list_.end();
+}
+
+
 // used when sorting the cite engine list.
 class EngineSorter {
 public:
diff --git a/src/CiteEnginesList.h b/src/CiteEnginesList.h
index 83fb875..a9ed959 100644
--- a/src/CiteEnginesList.h
+++ b/src/CiteEnginesList.h
@@ -80,6 +80,8 @@ public:
        ///
        std::vector<std::string> const & getPackageList() const
                { return package_list_; }
+       ///
+       bool requires(std::string const p) const;
 private:
        /// what appears in the ui
        std::string name_;
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index 4c993b6..5e4aac0 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -1211,6 +1211,8 @@ string const LaTeXFeatures::getPackages() const
                        packages << "numbers";
                else
                        packages << "authoryear";
+               if (!params_.biblio_opts.empty())
+                       packages << ',' << params_.biblio_opts;
                packages << "]{natbib}\n";
        }
 
@@ -1222,8 +1224,12 @@ string const LaTeXFeatures::getPackages() const
        }
 
        // jurabib -- we need version 0.6 at least.
-       if (mustProvide("jurabib"))
-               packages << "\\usepackage{jurabib}[2004/01/25]\n";
+       if (mustProvide("jurabib")) {
+               packages << "\\usepackage";
+               if (!params_.biblio_opts.empty())
+                       packages << '[' << params_.biblio_opts << ']';
+               packages << "{jurabib}[2004/01/25]\n";
+       }
 
        // opcit -- we pass custombst as we output \bibliographystyle ourselves
        if (mustProvide("opcit")) {
diff --git a/src/frontends/qt4/GuiDocument.cpp 
b/src/frontends/qt4/GuiDocument.cpp
index b890825..20fbd02 100644
--- a/src/frontends/qt4/GuiDocument.cpp
+++ b/src/frontends/qt4/GuiDocument.cpp
@@ -2378,8 +2378,6 @@ void GuiDocument::updateEngineDependends()
        biblioModule->bibtopicCB->setEnabled(!biblatex);
 
        // These are only useful with Biblatex
-       biblioModule->citePackageOptionsLE->setEnabled(biblatex);
-       biblioModule->citePackageOptionsL->setEnabled(biblatex);
        biblioModule->biblatexBbxCO->setEnabled(biblatex);
        biblioModule->biblatexBbxLA->setEnabled(biblatex);
        biblioModule->biblatexCbxCO->setEnabled(biblatex);
@@ -2387,6 +2385,17 @@ void GuiDocument::updateEngineDependends()
        biblioModule->resetBbxPB->setEnabled(biblatex);
        biblioModule->resetCbxPB->setEnabled(biblatex);
        biblioModule->matchBbxPB->setEnabled(biblatex);
+
+       // These are useful with biblatex, jurabib and natbib
+       QString const engine =
+               biblioModule->citeEngineCO->itemData(
+                               
biblioModule->citeEngineCO->currentIndex()).toString();
+       LyXCiteEngine const * ce = theCiteEnginesList[fromqstr(engine)];
+
+       bool const citepack = ce->requires("biblatex.sty") || 
ce->requires("jurabib.sty")
+                       || ce->requires("natbib.sty");
+       biblioModule->citePackageOptionsLE->setEnabled(citepack);
+       biblioModule->citePackageOptionsL->setEnabled(citepack);
 }
 
 
diff --git a/src/frontends/qt4/ui/BiblioUi.ui b/src/frontends/qt4/ui/BiblioUi.ui
index 78f50b1..aca9087 100644
--- a/src/frontends/qt4/ui/BiblioUi.ui
+++ b/src/frontends/qt4/ui/BiblioUi.ui
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>534</width>
+    <width>545</width>
     <height>481</height>
    </rect>
   </property>
@@ -131,7 +131,7 @@
            </sizepolicy>
           </property>
           <property name="toolTip">
-           <string>Here you can enter further options of the biblatex 
package</string>
+           <string>Here you can enter further options of the bibliography 
package</string>
           </property>
          </widget>
         </item>
diff --git a/src/version.h b/src/version.h
index 140811f..a0b5c97 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 529 // spitz: keyonly cite type
-#define LYX_FORMAT_TEX2LYX 529
+#define LYX_FORMAT_LYX 530 // spitz: natbib/jurabib package options
+#define LYX_FORMAT_TEX2LYX 530
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER

Reply via email to