Store the citation engine in BufferParams as biblio::CiteEngine rather

than a triplet of bools. Results in a file format change.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8752 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Angus Leeming 2004-05-13 20:44:35 +00:00
parent b14ad898bf
commit 8424214209
20 changed files with 324 additions and 217 deletions

View File

@ -1,3 +1,7 @@
2004-05-12 Angus Leeming <leeming@lyx.org>
* FORMAT: document change to format 234.
2003-03-07 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* FORMAT: document jurabib.

View File

@ -1,6 +1,19 @@
LyX file-format changes
-----------------------
2004-05-12 Angus Leeming <leeming@lyx.org>
* format incremented to 234.
* the citation engine is specified explicitly rather than being
deduced from 3 bools.
\use_natbib 1
\use_numerical_citations 0 -> \cite_engine <style>
\use_jurabib 0
where <style> is one of "basic", "natbib_authoryear",
"natbib_numerical" or "jurabib".
2004-04-29 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* format incremented to 233.

View File

@ -1,3 +1,11 @@
2004-05-12 Angus Leeming <leeming@lyx.org>
* lyx_1_4.py (convert_cite_engine, revert_cite_engine): new functions
to convert the code that specifies the type of the citation engine
(basic, natbib or jurabib).
* parser_tools.py: up the format to 234.
2004-05-11 José Matos <jamatos@lyx.org>

View File

@ -1259,6 +1259,69 @@ def revert_names(lines, opt):
return
##
# \use_natbib 1 \cite_engine <style>
# \use_numerical_citations 0 -> where <style> is one of
# \use_jurabib 0 "basic", "natbib_authoryear",
# "natbib_numerical" or "jurabib"
def convert_cite_engine(header, opt):
a = find_token(header, "\\use_natbib", 0)
if a == -1:
opt.warning("Malformed lyx file: Missing '\\use_natbib'")
return
b = find_token(header, "\\use_numerical_citations", 0)
if b == -1 or b != a+1:
opt.warning("Malformed lyx file: Missing '\\use_numerical_citations'")
return
c = find_token(header, "\\use_jurabib", 0)
if c == -1 or c != b+1:
opt.warning("Malformed lyx file: Missing '\\use_jurabib'")
return
use_natbib = int(split(header[a])[1])
use_numerical_citations = int(split(header[b])[1])
use_jurabib = int(split(header[c])[1])
cite_engine = "basic"
if use_natbib:
if use_numerical_citations:
cite_engine = "natbib_numerical"
else:
cite_engine = "natbib_authoryear"
elif use_jurabib:
cite_engine = "jurabib"
del header[a:c+1]
header.insert(a, "\\cite_engine " + cite_engine)
def revert_cite_engine(header, opt):
i = find_token(header, "\\cite_engine", 0)
if i == -1:
opt.warning("Malformed lyx file: Missing '\\cite_engine'")
return
cite_engine = split(header[i])[1]
use_natbib = '0'
use_numerical = '0'
use_jurabib = '0'
if cite_engine == "natbib_numerical":
use_natbib = '1'
use_numerical = '1'
elif cite_engine == "natbib_authoryear":
use_natbib = '1'
elif cite_engine == "jurabib":
use_jurabib = '1'
del header[i]
header.insert(i, "\\use_jurabib " + use_jurabib)
header.insert(i, "\\use_numerical_citations " + use_numerical)
header.insert(i, "\\use_natbib " + use_natbib)
##
# Convertion hub
#
@ -1328,8 +1391,18 @@ def convert(header, body, opt):
convert_graphics(body, opt)
convert_names(body, opt)
opt.format = 233
if opt.end == opt.format: return
if opt.format < 234:
convert_cite_engine(header, opt)
opt.format = 234
def revert(header, body, opt):
if opt.format > 233:
revert_cite_engine(header, opt)
opt.format = 233
if opt.end == opt.format: return
if opt.format > 232:
revert_names(body, opt)
opt.format = 232

View File

@ -265,7 +265,7 @@ def set_version(lines, version):
format_re = re.compile(r"(\d)[\.,]?(\d\d)")
fileformat = re.compile(r"\\lyxformat\s*(\S*)")
lst_ft = [210, 215, 216, 217, 218, 220, 221, 223, 224, 225, 226, 227, 228, 229,
230, 231, 232, 233]
230, 231, 232, 233, 234]
format_relation = [("0_10", [210], ["0.10.7","0.10"]),
("0_12", [215], ["0.12","0.12.1","0.12"]),
@ -277,7 +277,7 @@ format_relation = [("0_10", [210], ["0.10.7","0.10"]),
("1_1_6fix3", [218], ["1.1.6fix3","1.1.6fix4","1.1"]),
("1_2", [220], ["1.2.0","1.2.1","1.2.3","1.2.4","1.2"]),
("1_3", [221], ["1.3.0","1.3.1","1.3.2","1.3.3","1.3.4","1.3"]),
("1_4", [223,224,225,226,227,228,229,230,231,232,233], ["1.4.0cvs","1.4"])]
("1_4", [223,224,225,226,227,228,229,230,231,232,233,234], ["1.4.0cvs","1.4"])]
def lyxformat(format, opt):
@ -290,7 +290,7 @@ def lyxformat(format, opt):
if format in lst_ft:
return format
opt.error(str(format) + ": " + "Format no supported.")
opt.error(str(format) + ": " + "Format not supported.")
return None

View File

@ -1,3 +1,11 @@
2004-05-12 Angus Leeming <leeming@lyx.org>
* buffer.C: up LYX_FORMAT to 234.
* bufferparams.[Ch]: replace the three bools, use_natbib, use_jurabib,
use_numerical_citations with a single biblio::CiteEngine cite_engine
variable.
* LaTeXFeatures.C (getPackages): use BufferParams::cite_engine.
2004-05-13 José Matos <jamatos@lyx.org>
* converter.h:

View File

@ -299,7 +299,7 @@ string const LaTeXFeatures::getPackages() const
// natbib.sty
if (isRequired("natbib") && ! tclass.provides(LyXTextClass::natbib)) {
packages << "\\usepackage[";
if (params_.use_numerical_citations) {
if (params_.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL) {
packages << "numbers";
} else {
packages << "authoryear";

View File

@ -136,7 +136,7 @@ extern BufferList bufferlist;
namespace {
const int LYX_FORMAT = 233;
const int LYX_FORMAT = 234;
} // namespace anon

View File

@ -113,9 +113,7 @@ BufferParams::BufferParams()
orientation = ORIENTATION_PORTRAIT;
use_geometry = false;
use_amsmath = AMS_AUTO;
use_natbib = false;
use_numerical_citations = false;
use_jurabib = false;
cite_engine = biblio::ENGINE_BASIC;
use_bibtopic = false;
tracking_changes = false;
secnumdepth = 3;
@ -317,15 +315,18 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
lex.nextToken();
use_amsmath = static_cast<AMS>(
lex.getInteger());
} else if (token == "\\use_natbib") {
} else if (token == "\\cite_engine") {
lex.nextToken();
use_natbib = lex.getInteger();
} else if (token == "\\use_numerical_citations") {
lex.nextToken();
use_numerical_citations = lex.getInteger();
} else if (token == "\\use_jurabib") {
lex.nextToken();
use_jurabib = lex.getInteger();
string const engine = lex.getString();
cite_engine = biblio::ENGINE_BASIC;
if (engine == "natbib_numerical")
cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
else if (engine == "natbib_authoryear")
cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
else if (engine == "jurabib")
cite_engine = biblio::ENGINE_JURABIB;
} else if (token == "\\use_bibtopic") {
lex.nextToken();
use_bibtopic = lex.getInteger();
@ -540,14 +541,27 @@ void BufferParams::writeFile(ostream & os) const
spacing().writeFile(os);
string cite_engine_str = "basic";
switch (cite_engine) {
case biblio::ENGINE_BASIC:
break;
case biblio::ENGINE_NATBIB_NUMERICAL:
cite_engine_str = "natbib_numerical";
break;
case biblio::ENGINE_NATBIB_AUTHORYEAR:
cite_engine_str = "natbib_authoryear";
break;
case biblio::ENGINE_JURABIB:
cite_engine_str = "jurabib";
break;
}
os << "\\papersize " << string_papersize[papersize2]
<< "\n\\paperpackage " << string_paperpackages[paperpackage]
<< "\n\\use_geometry " << use_geometry
<< "\n\\use_amsmath " << use_amsmath
<< "\n\\use_natbib " << use_natbib
<< "\n\\use_numerical_citations " << use_numerical_citations
<< "\n\\use_jurabib " << use_jurabib
<< "\n\\use_bibtopic " << use_bibtopic
<< "\n\\cite_engine " << cite_engine_str
<< "\n\\use_bibtopic " << use_bibtopic
<< "\n\\paperorientation " << string_orientation[orientation]
<< '\n';

View File

@ -20,6 +20,8 @@
#include "insets/insetquotes.h"
#include "frontends/controllers/biblio.h"
#include "support/copied_ptr.h"
#include "support/types.h"
@ -179,11 +181,7 @@ public:
};
AMS use_amsmath;
///
bool use_natbib;
///
bool use_numerical_citations;
///
bool use_jurabib;
biblio::CiteEngine cite_engine;
///
bool use_bibtopic;
/// revision tracking for this buffer ?

View File

@ -1,3 +1,7 @@
2004-05-12 Angus Leeming <leeming@lyx.org>
* biblio.C (getEngine): reduced to the trivial.
2004-05-10 Angus Leeming <leeming@lyx.org>
* biblio.[Ch]: create a new biblio::CiteEngine enum. Use it instead of

View File

@ -564,20 +564,7 @@ string const getCiteCommand(CiteStyle command, bool full, bool forceUCase)
CiteEngine getEngine(Buffer const & buffer)
{
CiteEngine engine = ENGINE_BASIC;
if (buffer.params().use_natbib) {
if (buffer.params().use_numerical_citations) {
engine = ENGINE_NATBIB_NUMERICAL;
} else {
engine = ENGINE_NATBIB_AUTHORYEAR;
}
}
if (buffer.params().use_jurabib)
engine = ENGINE_JURABIB;
return engine;
return buffer.params().cite_engine;
}

View File

@ -1,3 +1,8 @@
2004-05-12 Angus Leeming <leeming@lyx.org>
* QDocument.C (apply, update): get, set data with
BufferParams::cite_engine.
2004-05-10 Angus Leeming <leeming@lyx.org>
* QCitation.C: simplified code to use the biblio::CiteEngine

View File

@ -191,12 +191,19 @@ void QDocument::apply()
fromqstr(dialog_->preambleModule->preambleMLE->text());
// biblio
params.use_natbib =
dialog_->biblioModule->citeNatbibRB->isChecked();
params.use_numerical_citations =
dialog_->biblioModule->citeStyleCO->currentItem();
params.use_jurabib =
dialog_->biblioModule->citeJurabibRB->isChecked();
params.cite_engine = biblio::ENGINE_BASIC;
if (dialog_->biblioModule->citeNatbibRB->isChecked()) {
bool const use_numerical_citations =
dialog_->biblioModule->citeStyleCO->currentItem();
if (use_numerical_citations)
params.cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
else
params.cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
} else if (dialog_->biblioModule->citeJurabibRB->isChecked())
params.cite_engine = biblio::ENGINE_JURABIB;
params.use_bibtopic =
dialog_->biblioModule->bibtopicCB->isChecked();
@ -446,13 +453,18 @@ void QDocument::update_contents()
// biblio
dialog_->biblioModule->citeDefaultRB->setChecked(
!params.use_natbib && !params.use_jurabib);
params.cite_engine == biblio::ENGINE_BASIC);
dialog_->biblioModule->citeNatbibRB->setChecked(
params.use_natbib);
params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL ||
params.cite_engine == biblio::ENGINE_NATBIB_AUTHORYEAR);
dialog_->biblioModule->citeStyleCO->setCurrentItem(
params.use_numerical_citations ? 1 : 0);
params.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL);
dialog_->biblioModule->citeJurabibRB->setChecked(
params.use_jurabib);
params.cite_engine == biblio::ENGINE_JURABIB);
dialog_->biblioModule->bibtopicCB->setChecked(
params.use_bibtopic);

View File

@ -1,3 +1,8 @@
2004-05-12 Angus Leeming <leeming@lyx.org>
* FormDocument.[Ch], forms/form_document.fd: get, set data with
BufferParams::cite_engine.
2004-05-10 Angus Leeming <leeming@lyx.org>
* FormCitation.C: simplified code to use the biblio::CiteEngine

View File

@ -308,26 +308,19 @@ void FormDocument::build()
bcview().addReadOnly(options_->counter_secnumdepth);
bcview().addReadOnly(options_->counter_tocdepth);
bcview().addReadOnly(options_->choice_ams_math);
bcview().addReadOnly(options_->radio_use_defcite);
bcview().addReadOnly(options_->radio_use_jurabib);
bcview().addReadOnly(options_->radio_use_natbib);
bcview().addReadOnly(options_->choice_cite_engine);
bcview().addReadOnly(options_->check_bibtopic);
bcview().addReadOnly(options_->choice_citation_format);
bcview().addReadOnly(options_->input_float_placement);
bcview().addReadOnly(options_->choice_postscript_driver);
// add cite style radio buttons
citestyle_.init(options_->radio_use_defcite, DEFCITE);
citestyle_.init(options_->radio_use_natbib, NATBIB);
citestyle_.init(options_->radio_use_jurabib, JURABIB);
string const cite_choices =
_(" Basic | Natbib author-year | Natbib numerical | Jurabib ");
fl_addto_choice(options_->choice_cite_engine, cite_choices.c_str());
// set up the tooltips for optionss form
string str = _("Use LaTeX's default citation style");
tooltips().init(options_->radio_use_defcite, str);
str = _("Use the natbib styles for natural sciences and arts");
tooltips().init(options_->radio_use_natbib, str);
str = _("Use the jurabib styles for law and humanities");
tooltips().init(options_->radio_use_jurabib, str);
string str = _("Natbib is used often for natural sciences and arts\n"
"Jurabib is more common in law and humanities");
tooltips().init(options_->choice_cite_engine, str);
str = _("Select this if you want to split your bibliography into sections");
tooltips().init(options_->check_bibtopic, str);
@ -343,8 +336,6 @@ void FormDocument::build()
fl_addto_choice(options_->choice_postscript_driver,
tex_graphics[n]);
}
fl_addto_choice(options_->choice_citation_format,
_(" Author-year | Numerical ").c_str());
// the document bullets form
bullets_.reset(build_document_bullet(this));
@ -535,12 +526,6 @@ ButtonPolicy::SMInput FormDocument::input(FL_OBJECT * ob, long)
fl_set_choice_text(class_->choice_skip_units,
default_unit.c_str());
} else if (ob == options_->radio_use_jurabib ||
ob == options_->radio_use_defcite ||
ob == options_->radio_use_natbib) {
setEnabled(options_->choice_citation_format,
fl_get_button(options_->radio_use_natbib));
} else if (ob == branch_->browser_all_branches ||
ob == branch_->browser_selection ||
ob == branch_->button_add_branch ||
@ -1028,10 +1013,23 @@ bool FormDocument::options_apply(BufferParams & params)
params.graphicsDriver = getString(options_->choice_postscript_driver);
params.use_amsmath = static_cast<BufferParams::AMS>(
fl_get_choice(options_->choice_ams_math) - 1);
params.use_natbib = fl_get_button(options_->radio_use_natbib);
params.use_numerical_citations =
fl_get_choice(options_->choice_citation_format) - 1;
params.use_jurabib = fl_get_button(options_->radio_use_jurabib);
int const cite_choice = fl_get_choice(options_->choice_cite_engine);
switch (cite_choice) {
case 1:
params.cite_engine = biblio::ENGINE_BASIC;
break;
case 2:
params.cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
break;
case 3:
params.cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
break;
case 4:
params.cite_engine = biblio::ENGINE_JURABIB;
break;
}
params.use_bibtopic = fl_get_button(options_->check_bibtopic);
int tmpchar = int(fl_get_counter_value(options_->counter_secnumdepth));
@ -1198,11 +1196,24 @@ void FormDocument::options_update(BufferParams const & params)
fl_set_choice_text(options_->choice_postscript_driver,
params.graphicsDriver.c_str());
fl_set_choice(options_->choice_ams_math, params.use_amsmath + 1);
fl_set_button(options_->radio_use_natbib, params.use_natbib);
fl_set_choice(options_->choice_citation_format,
int(params.use_numerical_citations)+1);
setEnabled(options_->choice_citation_format, params.use_natbib);
fl_set_button(options_->radio_use_jurabib, params.use_jurabib);
int cite_choice = 1;
switch (params.cite_engine) {
case biblio::ENGINE_BASIC:
cite_choice = 1;
break;
case biblio::ENGINE_NATBIB_AUTHORYEAR:
cite_choice = 2;
break;
case biblio::ENGINE_NATBIB_NUMERICAL:
cite_choice = 3;
break;
case biblio::ENGINE_JURABIB:
cite_choice = 4;
break;
}
fl_set_choice(options_->choice_cite_engine, cite_choice);
fl_set_button(options_->check_bibtopic, params.use_bibtopic);
fl_set_counter_value(options_->counter_secnumdepth, params.secnumdepth);
fl_set_counter_value(options_->counter_tocdepth, params.tocdepth);

View File

@ -14,7 +14,6 @@
#include "FormDialogView.h"
#include "BranchList.h"
#include "RadioButtonGroup.h"
#include <boost/scoped_ptr.hpp>
@ -133,9 +132,6 @@ private:
std::vector<std::string> lang_;
/// Contains all legal branches for this doc
BranchList branchlist_;
/// citation style buttons
RadioButtonGroup citestyle_;
};
#endif

View File

@ -328,7 +328,7 @@ argument:
--------------------
class: FL_BEGIN_GROUP
type: 0
box: 0 0 0 0
box: 0 10 10 0
boxtype: FL_NO_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_CENTER
@ -928,7 +928,7 @@ argument: 0
--------------------
class: FL_BEGIN_GROUP
type: 0
box: 0 0 0 0
box: 0 10 10 0
boxtype: FL_NO_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_CENTER
@ -1000,7 +1000,7 @@ argument:
--------------------
class: FL_BEGIN_GROUP
type: 0
box: 0 0 0 0
box: 0 10 10 0
boxtype: FL_NO_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_CENTER
@ -1072,7 +1072,7 @@ argument:
--------------------
class: FL_BEGIN_GROUP
type: 0
box: 0 0 0 0
box: 0 10 10 0
boxtype: FL_NO_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_CENTER
@ -1260,7 +1260,7 @@ argument: 0
Name: form_document_options
Width: 395
Height: 315
Number of Objects: 12
Number of Objects: 8
--------------------
class: FL_BOX
@ -1360,42 +1360,6 @@ name: choice_postscript_driver
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_ROUND3DBUTTON
type: RADIO_BUTTON
box: 25 205 140 25
boxtype: FL_NO_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Natbib|#N
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: radio_use_natbib
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_CHOICE
type: NORMAL_CHOICE
box: 235 230 140 25
boxtype: FL_FRAME_BOX
colors: FL_COL1 FL_BLACK
alignment: FL_ALIGN_TOP_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Natbib style:|#i
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: choice_citation_format
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_CHOICE
type: NORMAL_CHOICE
@ -1414,67 +1378,13 @@ name: choice_ams_math
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_LABELFRAME
type: ENGRAVED_FRAME
box: 15 170 370 95
boxtype: FL_NO_BOX
colors: FL_BLACK FL_COL1
alignment: FL_ALIGN_TOP_LEFT
style: FL_NORMAL_STYLE
size: FL_DEFAULT_SIZE
lcol: FL_BLACK
label: Cite Styles
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name:
callback:
argument:
--------------------
class: FL_ROUND3DBUTTON
type: RADIO_BUTTON
box: 25 230 140 25
boxtype: FL_NO_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Jurabib|#J
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: radio_use_jurabib
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_ROUND3DBUTTON
type: RADIO_BUTTON
box: 25 180 155 25
boxtype: FL_NO_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Default (numerical)|#D
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: radio_use_defcite
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_CHECKBUTTON
type: PUSH_BUTTON
box: 15 270 255 25
box: 185 190 25 25
boxtype: FL_NO_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_CENTER
alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
@ -1486,6 +1396,24 @@ name: check_bibtopic
callback: C_FormDialogView_InputCB
argument: 0
--------------------
class: FL_CHOICE
type: NORMAL_CHOICE
box: 185 160 140 25
boxtype: FL_FRAME_BOX
colors: FL_COL1 FL_BLACK
alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Citation Style:|#C
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: choice_cite_engine
callback: C_FormDialogView_InputCB
argument: 0
=============== FORM ===============
Name: form_document_bullet
Width: 395
@ -1585,7 +1513,7 @@ argument: 0
--------------------
class: FL_BEGIN_GROUP
type: 0
box: 0 0 0 0
box: 0 10 10 0
boxtype: FL_NO_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_CENTER
@ -1694,7 +1622,7 @@ argument:
--------------------
class: FL_BEGIN_GROUP
type: 0
box: 0 0 0 0
box: 0 10 10 0
boxtype: FL_NO_BOX
colors: FL_COL1 FL_MCOL
alignment: FL_ALIGN_CENTER

View File

@ -1,3 +1,8 @@
2004-05-12 Angus Leeming <leeming@lyx.org>
* insetcite.C: use BufferParams::cite_engine rather than the three
bools, use_natbib, use_jurabib, use_numerical_citations.
2004-05-10 Angus Leeming <leeming@lyx.org>
* insetcite.[Ch]: move the Cache::Style enum to biblio::CiteEngine.

View File

@ -40,7 +40,7 @@ namespace {
string const getNatbibLabel(Buffer const & buffer,
string const & citeType, string const & keyList,
string const & before, string const & after,
bool numerical, bool jura)
biblio::CiteEngine engine)
{
// Only start the process off after the buffer is loaded from file.
if (!buffer.fully_loaded())
@ -136,7 +136,7 @@ string const getNatbibLabel(Buffer const & buffer,
// authors1/<before>; ... ;
// authors_last, <after>
if (cite_type == "cite" && jura) {
if (cite_type == "cite" && engine == biblio::ENGINE_JURABIB) {
if (it == keys.begin())
label += author + before_str + sep_str;
else
@ -145,18 +145,27 @@ string const getNatbibLabel(Buffer const & buffer,
// (authors1 (<before> year); ... ;
// authors_last (<before> year, <after>)
} else if (cite_type == "citet") {
string const tmp = numerical ? '#' + *it : year;
if (!jura)
label += author + op_str + before_str + tmp +
cp + sep_str;
else
label += before_str + author + op_str + tmp +
cp + sep_str;
switch (engine) {
case biblio::ENGINE_NATBIB_AUTHORYEAR:
label += author + op_str + before_str +
year + cp + sep_str;
break;
case biblio::ENGINE_NATBIB_NUMERICAL:
label += author + op_str + before_str +
'#' + *it + cp + sep_str;
break;
case biblio::ENGINE_JURABIB:
label += before_str + author + op_str +
year + cp + sep_str;
break;
case biblio::ENGINE_BASIC:
break;
}
// author, year; author, year; ...
} else if (cite_type == "citep" ||
cite_type == "citealp") {
if (numerical) {
if (engine == biblio::ENGINE_NATBIB_NUMERICAL) {
label += *it + sep_str;
} else {
label += author + ", " + year + sep_str;
@ -165,11 +174,22 @@ string const getNatbibLabel(Buffer const & buffer,
// (authors1 <before> year;
// authors_last <before> year, <after>)
} else if (cite_type == "citealt") {
string const tmp = numerical ? '#' + *it : year;
if (!jura)
label += author + ' ' + before_str + tmp + sep_str;
else
label += before_str + author + ' ' + tmp + sep_str;
switch (engine) {
case biblio::ENGINE_NATBIB_AUTHORYEAR:
label += author + ' ' + before_str +
year + sep_str;
break;
case biblio::ENGINE_NATBIB_NUMERICAL:
label += author + ' ' + before_str +
'#' + *it + sep_str;
break;
case biblio::ENGINE_JURABIB:
label += before_str + author + ' ' +
year + sep_str;
break;
case biblio::ENGINE_BASIC:
break;
}
// author; author; ...
} else if (cite_type == "citeauthor") {
@ -188,9 +208,10 @@ string const getNatbibLabel(Buffer const & buffer,
// insert "after" before last ')'
label.insert(label.size() - 1, after_str);
} else {
bool const add = !(numerical &&
(cite_type == "citeauthor" ||
cite_type == "citeyear"));
bool const add =
!(engine == biblio::ENGINE_NATBIB_NUMERICAL &&
(cite_type == "citeauthor" ||
cite_type == "citeyear"));
if (add)
label += after_str;
}
@ -245,23 +266,22 @@ string const InsetCitation::generateLabel(Buffer const & buffer) const
string const after = getOptions();
string label;
if (buffer.params().use_natbib || buffer.params().use_jurabib) {
biblio::CiteEngine const engine = buffer.params().cite_engine;
if (engine != biblio::ENGINE_BASIC) {
string cmd = getCmdName();
if (buffer.params().use_natbib && cmd == "cite") {
if (cmd == "cite") {
// We may be "upgrading" from an older LyX version.
// If, however, we use "cite" because the necessary
// author/year info is not present in the biblio
// database, then getNatbibLabel will exit gracefully
// and we'll call getBasicLabel.
if (buffer.params().use_numerical_citations)
if (engine == biblio::ENGINE_NATBIB_NUMERICAL)
cmd = "citep";
else
else if (engine == biblio::ENGINE_NATBIB_AUTHORYEAR)
cmd = "citet";
}
label = getNatbibLabel(buffer, cmd, getContents(),
before, after,
buffer.params().use_numerical_citations,
buffer.params().use_jurabib);
before, after, engine);
}
// Fallback to fail-safe
@ -320,10 +340,19 @@ int InsetCitation::plaintext(Buffer const & buffer, ostream & os, int) const
int InsetCitation::latex(Buffer const & buffer, ostream & os,
OutputParams const &) const
{
biblio::CiteEngine const cite_engine = buffer.params().cite_engine;
os << "\\";
if (buffer.params().use_natbib)
switch (cite_engine) {
case biblio::ENGINE_BASIC:
os << "cite";
break;
case biblio::ENGINE_NATBIB_AUTHORYEAR:
case biblio::ENGINE_NATBIB_NUMERICAL:
os << getCmdName();
else if (buffer.params().use_jurabib) {
break;
case biblio::ENGINE_JURABIB:
{
// jurabib does not (yet) support "force upper case"
// and "full author name". Fallback.
string cmd = getCmdName();
@ -333,13 +362,13 @@ int InsetCitation::latex(Buffer const & buffer, ostream & os,
if (cmd[n] == '*')
cmd = cmd.substr(0,n);
os << cmd;
} else
os << "cite";
break;
}
}
string const before = getSecOptions();
string const after = getOptions();
if (!before.empty()
&& (buffer.params().use_natbib || buffer.params().use_jurabib))
if (!before.empty() && cite_engine != biblio::ENGINE_BASIC)
os << '[' << before << "][" << after << ']';
else if (!after.empty())
os << '[' << after << ']';
@ -364,8 +393,15 @@ int InsetCitation::latex(Buffer const & buffer, ostream & os,
void InsetCitation::validate(LaTeXFeatures & features) const
{
if (features.bufferParams().use_natbib)
switch (features.bufferParams().cite_engine) {
case biblio::ENGINE_BASIC:
break;
case biblio::ENGINE_NATBIB_AUTHORYEAR:
case biblio::ENGINE_NATBIB_NUMERICAL:
features.require("natbib");
else if (features.bufferParams().use_jurabib)
break;
case biblio::ENGINE_JURABIB:
features.require("jurabib");
break;
}
}