Basic support for natbib & jurabib options

This re-uses the options line edit introduced for biblatex.
This commit is contained in:
Juergen Spitzmueller 2017-01-13 18:23:42 +01:00
parent 7b57bea5d5
commit fc546b7dcc
8 changed files with 82 additions and 9 deletions

View 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

View 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]],

View 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:

View 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_;

View 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")) {

View 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);
}

View File

@ -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>

View 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