Buffer param \cite_engine_type (authoryear|numerical).

To avoid duplicity, remove natbib_authoryear and natbib_numerical
and replace them by natbib, and keep track of the engine `type'
in the new \cite_engine_type document setting. This will make it
easier to add more citation engines.

LyX format incremented to 424.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@40592 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Julien Rioux 2012-01-09 13:16:38 +00:00
parent db9e633b7f
commit e3f65fd088
17 changed files with 185 additions and 75 deletions

View File

@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
----------------------- -----------------------
2012-01-09 Julien Rioux <jrioux@lyx.org>
* Format incremented to 424 (r40592)
New buffer param \cite_engine_type to specify the type of
citation labels being used, authoryear or numerical.
2012-01-05 Georg Baum <Georg.Baum@post.rwth-aachen.de> 2012-01-05 Georg Baum <Georg.Baum@post.rwth-aachen.de>
* Format incremented to 423 (r40574) * Format incremented to 423 (r40574)
support for the LaTeX-package mathtools (fix bug 7949) support for the LaTeX-package mathtools (fix bug 7949)

View File

@ -419,6 +419,37 @@ def revert_use_mathtools(document):
i = j 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)
if i == -1:
return
engine = get_value(document.header, "\\cite_engine", i)
if "_" in engine:
engine, type = engine.split("_")
else:
type = {"basic": "numerical", "jurabib": "authoryear"}[engine]
document.header[i] = "\\cite_engine " + engine
document.header.insert(i + 1, "\\cite_engine_type " + type)
def revert_cite_engine_type(document):
"Natbib had the type appended with an underscore."
engine_type = "numerical"
i = find_token(document.header, "\\cite_engine_type" , 0)
if i == -1:
document.warning("No \\cite_engine_type line. Assuming numerical.")
else:
engine_type = get_value(document.header, "\\cite_engine_type", i)
del document.header[i]
# We are looking for the natbib citation engine
i = find_token(document.header, "\\cite_engine natbib", i)
if i == -1:
return
document.header[i] = "\\cite_engine natbib_" + engine_type
## ##
# Conversion hub # Conversion hub
# #
@ -435,9 +466,11 @@ convert = [
[421, [convert_longtable_captions]], [421, [convert_longtable_captions]],
[422, [convert_use_packages]], [422, [convert_use_packages]],
[423, [convert_use_mathtools]], [423, [convert_use_mathtools]],
[424, [convert_cite_engine_type]],
] ]
revert = [ revert = [
[423, [revert_cite_engine_type]],
[422, [revert_use_mathtools]], [422, [revert_use_mathtools]],
[421, [revert_use_packages]], [421, [revert_use_packages]],
[420, [revert_longtable_captions]], [420, [revert_longtable_captions]],

View File

@ -692,8 +692,8 @@ bool BiblioInfo::isBibtex(docstring const & key) const
vector<docstring> const BiblioInfo::getCiteStrings( vector<docstring> const BiblioInfo::getCiteStrings(
docstring const & key, Buffer const & buf) const docstring const & key, Buffer const & buf) const
{ {
CiteEngine const engine = buf.params().citeEngine(); CiteEngineType const engine_type = buf.params().citeEngineType();
if (engine == ENGINE_BASIC || engine == ENGINE_NATBIB_NUMERICAL) if (engine_type == ENGINE_TYPE_NUMERICAL)
return getNumericalStrings(key, buf); return getNumericalStrings(key, buf);
else else
return getAuthorYearStrings(key, buf); return getAuthorYearStrings(key, buf);
@ -711,7 +711,8 @@ vector<docstring> const BiblioInfo::getNumericalStrings(
if (author.empty() || year.empty()) if (author.empty() || year.empty())
return vector<docstring>(); return vector<docstring>();
vector<CiteStyle> const & styles = citeStyles(buf.params().citeEngine()); vector<CiteStyle> const & styles = citeStyles(buf.params().citeEngine(),
buf.params().citeEngineType());
vector<docstring> vec(styles.size()); vector<docstring> vec(styles.size());
for (size_t i = 0; i != vec.size(); ++i) { for (size_t i = 0; i != vec.size(); ++i) {
@ -770,7 +771,8 @@ vector<docstring> const BiblioInfo::getAuthorYearStrings(
if (author.empty() || year.empty()) if (author.empty() || year.empty())
return vector<docstring>(); return vector<docstring>();
vector<CiteStyle> const & styles = citeStyles(buf.params().citeEngine()); vector<CiteStyle> const & styles = citeStyles(buf.params().citeEngine(),
buf.params().citeEngineType());
vector<docstring> vec(styles.size()); vector<docstring> vec(styles.size());
for (size_t i = 0; i != vec.size(); ++i) { for (size_t i = 0; i != vec.size(); ++i) {
@ -892,9 +894,8 @@ void BiblioInfo::collectCitedEntries(Buffer const & buf)
void BiblioInfo::makeCitationLabels(Buffer const & buf) void BiblioInfo::makeCitationLabels(Buffer const & buf)
{ {
collectCitedEntries(buf); collectCitedEntries(buf);
CiteEngine const engine = buf.params().citeEngine(); CiteEngineType const engine_type = buf.params().citeEngineType();
bool const numbers = bool const numbers = (engine_type == ENGINE_TYPE_NUMERICAL);
(engine == ENGINE_BASIC || engine == ENGINE_NATBIB_NUMERICAL);
int keynumber = 0; int keynumber = 0;
char modifier = 0; char modifier = 0;
@ -1025,17 +1026,18 @@ string citationStyleToString(const CitationStyle & s)
return cite; return cite;
} }
vector<CiteStyle> citeStyles(CiteEngine engine) vector<CiteStyle> citeStyles(CiteEngine engine, CiteEngineType engine_type)
{ {
vector<CiteStyle> styles(0); vector<CiteStyle> styles(0);
switch (engine) { if (engine_type == ENGINE_TYPE_AUTHORYEAR) {
switch (engine) {
case ENGINE_BASIC: case ENGINE_BASIC:
styles.push_back(CITE); styles.push_back(CITE);
break; break;
case ENGINE_JURABIB: case ENGINE_JURABIB:
styles.push_back(CITE); styles.push_back(CITE);
case ENGINE_NATBIB_AUTHORYEAR: case ENGINE_NATBIB:
styles.push_back(CITET); styles.push_back(CITET);
styles.push_back(CITEP); styles.push_back(CITEP);
styles.push_back(CITEALT); styles.push_back(CITEALT);
@ -1044,7 +1046,15 @@ vector<CiteStyle> citeStyles(CiteEngine engine)
styles.push_back(CITEYEAR); styles.push_back(CITEYEAR);
styles.push_back(CITEYEARPAR); styles.push_back(CITEYEARPAR);
break; break;
case ENGINE_NATBIB_NUMERICAL: }
} else {
switch (engine) {
case ENGINE_BASIC:
styles.push_back(CITE);
break;
case ENGINE_JURABIB:
styles.push_back(CITE);
case ENGINE_NATBIB:
styles.push_back(CITET); styles.push_back(CITET);
styles.push_back(CITEALT); styles.push_back(CITEALT);
styles.push_back(CITEAUTHOR); styles.push_back(CITEAUTHOR);
@ -1053,6 +1063,7 @@ vector<CiteStyle> citeStyles(CiteEngine engine)
styles.push_back(CITEYEAR); styles.push_back(CITEYEAR);
styles.push_back(CITEYEARPAR); styles.push_back(CITEYEARPAR);
break; break;
}
} }
styles.push_back(NOCITE); styles.push_back(NOCITE);

View File

@ -29,7 +29,7 @@ class Buffer;
/// FIXME: To Citation.cpp? /// FIXME: To Citation.cpp?
/// Returns a vector of available Citation styles. /// Returns a vector of available Citation styles.
std::vector<CiteStyle> citeStyles(CiteEngine); std::vector<CiteStyle> citeStyles(CiteEngine, CiteEngineType);
/// \param latex_str a LaTeX command, "cite", "Citep*", etc /// \param latex_str a LaTeX command, "cite", "Citep*", etc
CitationStyle citationStyleFromString(std::string const & latex_str); CitationStyle citationStyleFromString(std::string const & latex_str);
/// the other way round /// the other way round

View File

@ -265,8 +265,7 @@ typedef Translator<string, CiteEngine> CiteEngineTranslator;
CiteEngineTranslator const init_citeenginetranslator() CiteEngineTranslator const init_citeenginetranslator()
{ {
CiteEngineTranslator translator("basic", ENGINE_BASIC); CiteEngineTranslator translator("basic", ENGINE_BASIC);
translator.addPair("natbib_numerical", ENGINE_NATBIB_NUMERICAL); translator.addPair("natbib", ENGINE_NATBIB);
translator.addPair("natbib_authoryear", ENGINE_NATBIB_AUTHORYEAR);
translator.addPair("jurabib", ENGINE_JURABIB); translator.addPair("jurabib", ENGINE_JURABIB);
return translator; return translator;
} }
@ -279,6 +278,24 @@ CiteEngineTranslator const & citeenginetranslator()
} }
typedef Translator<string, CiteEngineType> CiteEngineTypeTranslator;
CiteEngineTypeTranslator const init_citeenginetypetranslator()
{
CiteEngineTypeTranslator translator("authoryear", ENGINE_TYPE_AUTHORYEAR);
translator.addPair("numerical", ENGINE_TYPE_NUMERICAL);
return translator;
}
CiteEngineTypeTranslator const & citeenginetypetranslator()
{
static CiteEngineTypeTranslator translator = init_citeenginetypetranslator();
return translator;
}
// Spacing // Spacing
typedef Translator<string, Spacing::Space> SpaceTranslator; typedef Translator<string, Spacing::Space> SpaceTranslator;
@ -362,6 +379,7 @@ BufferParams::BufferParams()
orientation = ORIENTATION_PORTRAIT; orientation = ORIENTATION_PORTRAIT;
use_geometry = false; use_geometry = false;
cite_engine_ = ENGINE_BASIC; cite_engine_ = ENGINE_BASIC;
cite_engine_type_ = ENGINE_TYPE_NUMERICAL;
biblio_style = "plain"; biblio_style = "plain";
use_bibtopic = false; use_bibtopic = false;
use_indices = false; use_indices = false;
@ -711,6 +729,10 @@ string BufferParams::readToken(Lexer & lex, string const & token,
string engine; string engine;
lex >> engine; lex >> engine;
cite_engine_ = citeenginetranslator().find(engine); cite_engine_ = citeenginetranslator().find(engine);
} else if (token == "\\cite_engine_type") {
string engine_type;
lex >> engine_type;
cite_engine_type_ = citeenginetypetranslator().find(engine_type);
} else if (token == "\\biblio_style") { } else if (token == "\\biblio_style") {
lex.eatLine(); lex.eatLine();
biblio_style = lex.getString(); biblio_style = lex.getString();
@ -1016,6 +1038,7 @@ void BufferParams::writeFile(ostream & os) const
os << "\n\\use_package " << packages[i] << ' ' os << "\n\\use_package " << packages[i] << ' '
<< use_package(packages[i]); << use_package(packages[i]);
os << "\n\\cite_engine " << citeenginetranslator().find(cite_engine_) os << "\n\\cite_engine " << citeenginetranslator().find(cite_engine_)
<< "\n\\cite_engine_type " << citeenginetypetranslator().find(cite_engine_type_)
<< "\n\\biblio_style " << biblio_style << "\n\\biblio_style " << biblio_style
<< "\n\\use_bibtopic " << convert<string>(use_bibtopic) << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
<< "\n\\use_indices " << convert<string>(use_indices) << "\n\\use_indices " << convert<string>(use_indices)
@ -2922,9 +2945,8 @@ CiteEngine BufferParams::citeEngine() const
{ {
// FIXME the class should provide the numerical/ // FIXME the class should provide the numerical/
// authoryear choice // authoryear choice
if (documentClass().provides("natbib") if (documentClass().provides("natbib"))
&& cite_engine_ != ENGINE_NATBIB_NUMERICAL) return ENGINE_NATBIB;
return ENGINE_NATBIB_AUTHORYEAR;
return cite_engine_; return cite_engine_;
} }

View File

@ -409,6 +409,13 @@ public:
/// ///
void setCiteEngine(CiteEngine const); void setCiteEngine(CiteEngine const);
/// the type of cite engine (authoryear or numerical)
CiteEngineType const & citeEngineType() const
{ return cite_engine_type_; }
/// set the cite engine type
void setCiteEngineType(CiteEngineType const & engine_type)
{ cite_engine_type_ = engine_type; }
/// the default BibTeX style file for the document /// the default BibTeX style file for the document
std::string biblio_style; std::string biblio_style;
@ -472,6 +479,8 @@ private:
mutable DefaultFlavorCache default_flavors_; mutable DefaultFlavorCache default_flavors_;
/// for use with natbib /// for use with natbib
CiteEngine cite_engine_; CiteEngine cite_engine_;
/// the type of cite engine (authoryear or numerical)
CiteEngineType cite_engine_type_;
/// ///
DocumentClass * doc_class_; DocumentClass * doc_class_;
/// ///

View File

@ -18,11 +18,15 @@ class Buffer;
enum CiteEngine { enum CiteEngine {
ENGINE_BASIC, ENGINE_BASIC,
ENGINE_NATBIB_AUTHORYEAR, ENGINE_NATBIB,
ENGINE_NATBIB_NUMERICAL,
ENGINE_JURABIB ENGINE_JURABIB
}; };
enum CiteEngineType {
ENGINE_TYPE_AUTHORYEAR = 1,
ENGINE_TYPE_NUMERICAL = 2,
};
enum CiteStyle { enum CiteStyle {
CITE, CITE,
CITET, CITET,

View File

@ -769,7 +769,7 @@ string const LaTeXFeatures::getPackages() const
// This special case is indicated by the "natbib-internal" key. // This special case is indicated by the "natbib-internal" key.
if (mustProvide("natbib") && !tclass.provides("natbib-internal")) { if (mustProvide("natbib") && !tclass.provides("natbib-internal")) {
packages << "\\usepackage["; packages << "\\usepackage[";
if (params_.citeEngine() == ENGINE_NATBIB_NUMERICAL) if (params_.citeEngineType() == ENGINE_TYPE_NUMERICAL)
packages << "numbers"; packages << "numbers";
else else
packages << "authoryear"; packages << "authoryear";

View File

@ -510,10 +510,7 @@ QString GuiBibtex::styleFile() const
case ENGINE_BASIC: case ENGINE_BASIC:
defaultstyle = "plain"; defaultstyle = "plain";
break; break;
case ENGINE_NATBIB_AUTHORYEAR: case ENGINE_NATBIB:
defaultstyle = "plainnat";
break;
case ENGINE_NATBIB_NUMERICAL:
defaultstyle = "plainnat"; defaultstyle = "plainnat";
break; break;
case ENGINE_JURABIB: case ENGINE_JURABIB:

View File

@ -211,9 +211,7 @@ void GuiCitation::updateControls(BiblioInfo const & bi)
void GuiCitation::updateFormatting(CiteStyle currentStyle) void GuiCitation::updateFormatting(CiteStyle currentStyle)
{ {
CiteEngine const engine = citeEngine(); CiteEngine const engine = citeEngine();
bool const natbib_engine = bool const natbib_engine = engine == ENGINE_NATBIB;
engine == ENGINE_NATBIB_AUTHORYEAR ||
engine == ENGINE_NATBIB_NUMERICAL;
bool const basic_engine = engine == ENGINE_BASIC; bool const basic_engine = engine == ENGINE_BASIC;
bool const haveSelection = bool const haveSelection =
@ -624,7 +622,8 @@ bool GuiCitation::initialiseParams(string const & data)
{ {
InsetCommand::string2params(data, params_); InsetCommand::string2params(data, params_);
CiteEngine const engine = citeEngine(); CiteEngine const engine = citeEngine();
citeStyles_ = citeStyles(engine); CiteEngineType const engine_type = citeEngineType();
citeStyles_ = citeStyles(engine, engine_type);
init(); init();
return true; return true;
} }
@ -664,6 +663,12 @@ CiteEngine GuiCitation::citeEngine() const
} }
CiteEngineType GuiCitation::citeEngineType() const
{
return documentBuffer().params().citeEngineType();
}
// Escape special chars. // Escape special chars.
// All characters are literals except: '.|*?+(){}[]^$\' // All characters are literals except: '.|*?+(){}[]^$\'
// These characters are literals when preceded by a "\", which is done here // These characters are literals when preceded by a "\", which is done here

View File

@ -134,6 +134,8 @@ private:
std::vector<docstring> & keyVector, docstring entryType); std::vector<docstring> & keyVector, docstring entryType);
/// ///
CiteEngine citeEngine() const; CiteEngine citeEngine() const;
///
CiteEngineType citeEngineType() const;
/// Search a given string within the passed keys. /// Search a given string within the passed keys.
/// \return the vector of matched keys. /// \return the vector of matched keys.

View File

@ -1132,6 +1132,10 @@ GuiDocument::GuiDocument(GuiView & lv)
// biblio // biblio
biblioModule = new UiWidget<Ui::BiblioUi>; biblioModule = new UiWidget<Ui::BiblioUi>;
connect(biblioModule->citeDefaultRB, SIGNAL(toggled(bool)),
this, SLOT(setNumerical(bool)));
connect(biblioModule->citeJurabibRB, SIGNAL(toggled(bool)),
this, SLOT(setAuthorYear(bool)));
connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)), connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
biblioModule->citationStyleL, SLOT(setEnabled(bool))); biblioModule->citationStyleL, SLOT(setEnabled(bool)));
connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)), connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
@ -2045,6 +2049,22 @@ void GuiDocument::bibtexChanged(int n)
} }
void GuiDocument::setAuthorYear(bool authoryear)
{
if (authoryear)
biblioModule->citeStyleCO->setCurrentIndex(0);
biblioChanged();
}
void GuiDocument::setNumerical(bool numerical)
{
if (numerical)
biblioModule->citeStyleCO->setCurrentIndex(1);
biblioChanged();
}
namespace { namespace {
// FIXME unicode // FIXME unicode
// both of these should take a vector<docstring> // both of these should take a vector<docstring>
@ -2279,17 +2299,16 @@ void GuiDocument::applyView()
// biblio // biblio
bp_.setCiteEngine(ENGINE_BASIC); bp_.setCiteEngine(ENGINE_BASIC);
if (biblioModule->citeNatbibRB->isChecked()) { if (biblioModule->citeNatbibRB->isChecked())
bool const use_numerical_citations = bp_.setCiteEngine(ENGINE_NATBIB);
biblioModule->citeStyleCO->currentIndex(); else if (biblioModule->citeJurabibRB->isChecked())
if (use_numerical_citations)
bp_.setCiteEngine(ENGINE_NATBIB_NUMERICAL);
else
bp_.setCiteEngine(ENGINE_NATBIB_AUTHORYEAR);
} else if (biblioModule->citeJurabibRB->isChecked())
bp_.setCiteEngine(ENGINE_JURABIB); bp_.setCiteEngine(ENGINE_JURABIB);
if (biblioModule->citeStyleCO->currentIndex())
bp_.setCiteEngineType(ENGINE_TYPE_NUMERICAL);
else
bp_.setCiteEngineType(ENGINE_TYPE_AUTHORYEAR);
bp_.use_bibtopic = bp_.use_bibtopic =
biblioModule->bibtopicCB->isChecked(); biblioModule->bibtopicCB->isChecked();
@ -2692,11 +2711,10 @@ void GuiDocument::paramsToDialog()
bp_.citeEngine() == ENGINE_BASIC); bp_.citeEngine() == ENGINE_BASIC);
biblioModule->citeNatbibRB->setChecked( biblioModule->citeNatbibRB->setChecked(
bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL || bp_.citeEngine() == ENGINE_NATBIB);
bp_.citeEngine() == ENGINE_NATBIB_AUTHORYEAR);
biblioModule->citeStyleCO->setCurrentIndex( biblioModule->citeStyleCO->setCurrentIndex(
bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL); bp_.citeEngineType() == ENGINE_TYPE_NUMERICAL);
biblioModule->citeJurabibRB->setChecked( biblioModule->citeJurabibRB->setChecked(
bp_.citeEngine() == ENGINE_JURABIB); bp_.citeEngine() == ENGINE_JURABIB);

View File

@ -107,6 +107,8 @@ private Q_SLOTS:
void languagePackageChanged(int); void languagePackageChanged(int);
void biblioChanged(); void biblioChanged();
void bibtexChanged(int); void bibtexChanged(int);
void setAuthorYear(bool);
void setNumerical(bool);
void updateModuleInfo(); void updateModuleInfo();
void modulesChanged(); void modulesChanged();
void changeBackgroundColor(); void changeBackgroundColor();

View File

@ -1490,7 +1490,8 @@ void MenuDefinition::expandCiteStyles(BufferView const * bv)
if (contains(key, ',')) if (contains(key, ','))
key = qstring_to_ucs4(toqstr(key).split(',')[0]); key = qstring_to_ucs4(toqstr(key).split(',')[0]);
vector<CiteStyle> citeStyleList = citeStyles(buf->params().citeEngine()); vector<CiteStyle> citeStyleList = citeStyles(buf->params().citeEngine(),
buf->params().citeEngineType());
docstring_list citeStrings = docstring_list citeStrings =
buf->masterBibInfo().getCiteStrings(key, bv->buffer()); buf->masterBibInfo().getCiteStrings(key, bv->buffer());

View File

@ -936,9 +936,8 @@ docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
{ {
BiblioInfo const & bibinfo = buffer().masterBibInfo(); BiblioInfo const & bibinfo = buffer().masterBibInfo();
vector<docstring> const & cites = bibinfo.citedEntries(); vector<docstring> const & cites = bibinfo.citedEntries();
CiteEngine const engine = buffer().params().citeEngine(); CiteEngineType const engine_type = buffer().params().citeEngineType();
bool const numbers = bool const numbers = (engine_type == ENGINE_TYPE_NUMERICAL);
(engine == ENGINE_BASIC || engine == ENGINE_NATBIB_NUMERICAL);
docstring reflabel = from_ascii("References"); docstring reflabel = from_ascii("References");
Language const * l = buffer().params().language; Language const * l = buffer().params().language;

View File

@ -143,18 +143,18 @@ docstring InsetCitation::toolTip(BufferView const & bv, int, int) const
namespace { namespace {
// FIXME See the header for the issue. // FIXME See the header for the issue.
string defaultCiteCommand(CiteEngine engine) string defaultCiteCommand(CiteEngine engine, CiteEngineType engine_type)
{ {
string str; string str;
switch (engine) { switch (engine) {
case ENGINE_BASIC: case ENGINE_BASIC:
str = "cite"; str = "cite";
break; break;
case ENGINE_NATBIB_AUTHORYEAR: case ENGINE_NATBIB:
str = "citet"; if (engine_type == ENGINE_TYPE_AUTHORYEAR)
break; str = "citet";
case ENGINE_NATBIB_NUMERICAL: else
str = "citep"; str = "citep";
break; break;
case ENGINE_JURABIB: case ENGINE_JURABIB:
str = "cite"; str = "cite";
@ -164,9 +164,10 @@ string defaultCiteCommand(CiteEngine engine)
} }
string asValidLatexCommand(string const & input, CiteEngine const engine) string asValidLatexCommand(string const & input, CiteEngine const engine,
CiteEngineType const engine_type)
{ {
string const default_str = defaultCiteCommand(engine); string const default_str = defaultCiteCommand(engine, engine_type);
if (!InsetCitation::isCompatibleCommand(input)) if (!InsetCitation::isCompatibleCommand(input))
return default_str; return default_str;
@ -179,8 +180,7 @@ string asValidLatexCommand(string const & input, CiteEngine const engine)
output = default_str; output = default_str;
break; break;
case ENGINE_NATBIB_AUTHORYEAR: case ENGINE_NATBIB:
case ENGINE_NATBIB_NUMERICAL:
if (input == "cite" || input == "citefield" if (input == "cite" || input == "citefield"
|| input == "citetitle" || input == "cite*") || input == "citetitle" || input == "cite*")
output = default_str; output = default_str;
@ -259,8 +259,9 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
// CITE: author/<before field> // CITE: author/<before field>
CiteEngine const engine = buffer().params().citeEngine(); CiteEngine const engine = buffer().params().citeEngine();
CiteEngineType const engine_type = buffer().params().citeEngineType();
// We don't currently use the full or forceUCase fields. // We don't currently use the full or forceUCase fields.
string cite_type = asValidLatexCommand(getCmdName(), engine); string cite_type = asValidLatexCommand(getCmdName(), engine, engine_type);
if (cite_type[0] == 'C') if (cite_type[0] == 'C')
// If we were going to use them, this would mean ForceUCase // If we were going to use them, this would mean ForceUCase
cite_type = string(1, 'c') + cite_type.substr(1); cite_type = string(1, 'c') + cite_type.substr(1);
@ -350,13 +351,13 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
// authors_last (<before> year, <after>) // authors_last (<before> year, <after>)
else if (cite_type == "citet") { else if (cite_type == "citet") {
switch (engine) { switch (engine) {
case ENGINE_NATBIB_AUTHORYEAR: case ENGINE_NATBIB:
label += author + op_str + before_str + if (engine_type == ENGINE_TYPE_AUTHORYEAR)
wrapCitation(*it, year, for_xhtml) + cp + sep_str; label += author + op_str + before_str +
break; wrapCitation(*it, year, for_xhtml) + cp + sep_str;
case ENGINE_NATBIB_NUMERICAL: else
label += author + op_str + before_str + label += author + op_str + before_str +
wrapCitation(*it, citenum, for_xhtml) + cp + sep_str; wrapCitation(*it, citenum, for_xhtml) + cp + sep_str;
break; break;
case ENGINE_JURABIB: case ENGINE_JURABIB:
label += before_str + author + op_str + label += before_str + author + op_str +
@ -369,7 +370,7 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
// author, year; author, year; ... // author, year; author, year; ...
else if (cite_type == "citep" || else if (cite_type == "citep" ||
cite_type == "citealp") { cite_type == "citealp") {
if (engine == ENGINE_NATBIB_NUMERICAL) { if (engine_type == ENGINE_TYPE_NUMERICAL) {
label += wrapCitation(*it, citenum, for_xhtml) + sep_str; label += wrapCitation(*it, citenum, for_xhtml) + sep_str;
} else { } else {
label += wrapCitation(*it, author + ", " + year, for_xhtml) + sep_str; label += wrapCitation(*it, author + ", " + year, for_xhtml) + sep_str;
@ -380,13 +381,13 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
// authors_last <before> year, <after>) // authors_last <before> year, <after>)
else if (cite_type == "citealt") { else if (cite_type == "citealt") {
switch (engine) { switch (engine) {
case ENGINE_NATBIB_AUTHORYEAR: case ENGINE_NATBIB:
label += author + ' ' + before_str + if (engine_type == ENGINE_TYPE_AUTHORYEAR)
wrapCitation(*it, year, for_xhtml) + sep_str; label += author + ' ' + before_str +
break; wrapCitation(*it, year, for_xhtml) + sep_str;
case ENGINE_NATBIB_NUMERICAL: else
label += author + ' ' + before_str + '#' + label += author + ' ' + before_str + '#' +
wrapCitation(*it, citenum, for_xhtml) + sep_str; wrapCitation(*it, citenum, for_xhtml) + sep_str;
break; break;
case ENGINE_JURABIB: case ENGINE_JURABIB:
label += before_str + label += before_str +
@ -416,7 +417,8 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
label.insert(label.size() - 1, after_str); label.insert(label.size() - 1, after_str);
} else { } else {
bool const add = bool const add =
!(engine == ENGINE_NATBIB_NUMERICAL && !(engine == ENGINE_NATBIB &&
engine_type == ENGINE_TYPE_NUMERICAL &&
(cite_type == "citeauthor" || (cite_type == "citeauthor" ||
cite_type == "citeyear")); cite_type == "citeyear"));
if (add) if (add)
@ -567,10 +569,11 @@ void InsetCitation::forToc(docstring & os, size_t) const
void InsetCitation::latex(otexstream & os, OutputParams const & runparams) const void InsetCitation::latex(otexstream & os, OutputParams const & runparams) const
{ {
CiteEngine cite_engine = buffer().params().citeEngine(); CiteEngine cite_engine = buffer().params().citeEngine();
CiteEngineType cite_engine_type = buffer().params().citeEngineType();
BiblioInfo const & bi = buffer().masterBibInfo(); BiblioInfo const & bi = buffer().masterBibInfo();
// FIXME UNICODE // FIXME UNICODE
docstring const cite_str = from_utf8( docstring const cite_str = from_utf8(
asValidLatexCommand(getCmdName(), cite_engine)); asValidLatexCommand(getCmdName(), cite_engine, cite_engine_type));
if (runparams.inulemcmd) if (runparams.inulemcmd)
os << "\\mbox{"; os << "\\mbox{";
@ -600,8 +603,7 @@ void InsetCitation::validate(LaTeXFeatures & features) const
switch (features.bufferParams().citeEngine()) { switch (features.bufferParams().citeEngine()) {
case ENGINE_BASIC: case ENGINE_BASIC:
break; break;
case ENGINE_NATBIB_AUTHORYEAR: case ENGINE_NATBIB:
case ENGINE_NATBIB_NUMERICAL:
features.require("natbib"); features.require("natbib");
break; break;
case ENGINE_JURABIB: case ENGINE_JURABIB:

View File

@ -30,7 +30,7 @@ extern char const * const lyx_version_info;
// Do not remove the comment below, so we get merge conflict in // Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own. // independent branches. Instead add your own.
#define LYX_FORMAT_LYX 423 // baum : \\use_package mathtools #define LYX_FORMAT_LYX 424 // jrioux : \cite_engine_type (authoryear|numerical)
#define LYX_FORMAT_TEX2LYX 423 #define LYX_FORMAT_TEX2LYX 423
#if LYX_FORMAT_FOR_TEX2LYX != LYX_FORMAT_FOR_LYX #if LYX_FORMAT_FOR_TEX2LYX != LYX_FORMAT_FOR_LYX