]> git.lyx.org Git - features.git/commitdiff
Basic support for natbib & jurabib options
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 13 Jan 2017 17:23:42 +0000 (18:23 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 13 Jan 2017 17:23:42 +0000 (18:23 +0100)
This re-uses the options line edit introduced for biblatex.

development/FORMAT
lib/lyx2lyx/lyx_2_3.py
src/CiteEnginesList.cpp
src/CiteEnginesList.h
src/LaTeXFeatures.cpp
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/ui/BiblioUi.ui
src/version.h

index eb6057221609d443e56246e11f4b5966572a4442..3c4f11553f3b9274023368a1d6ccdd6681bc02d5 100644 (file)
@@ -7,6 +7,10 @@ changes happened in particular if possible. A good example would be
 
 -----------------------
 
+2017-01-13 Jürgen Spitzmüller <spitz@lyx.org>
+       * Format incremented to 530: Support natbib & jurabib package options.
+
+
 2017-01-13 Jürgen Spitzmüller <spitz@lyx.org>
        * Format incremented to 529:
          \begin_inset CommandInset citation
index a2adde7339a48cebfad4112c61a2e583b77354ff..762c884790153483f8326cf2c748c62a8a044501 100644 (file)
@@ -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]],
index 2b8de0525546952bfef69a25fa059f93bfa64be6..3c10b4003cb4f16a349009eb072f8f528016e90f 100644 (file)
@@ -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:
index 83fb87516182d1c2a1c52f2d3249ca582760d2ff..a9ed959648d1da3e5532729a6a50782f98a01c7d 100644 (file)
@@ -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_;
index 4c993b6f7b9c55041a4a08e1e9b2f0490b5725d2..5e4aac0637972123b6bd1f8d6c337eb0c8ab518b 100644 (file)
@@ -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")) {
index b89082558c687666d2dba74126d4352885531bc6..20fbd02cf91735f76440a90eb78fd1619bb8d9e6 100644 (file)
@@ -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);
 }
 
 
index 78f50b1aa735d414d1de480981af17dd4009edf3..aca90873ab01223673aaac7d199e3d8e80175a42 100644 (file)
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>534</width>
+    <width>545</width>
     <height>481</height>
    </rect>
   </property>
            </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>
index 140811fae621afc1bf32b19b93a07ddf073028bf..a0b5c973b6025dead9f49a3f769fb1c11074ea40 100644 (file)
@@ -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