Hi,
These two patches adds a buffer param \cite_engine_type which can be
either authoryear or numerical. This simplifies the natbib handling to a
single cite engine instead of two; that engine can take either `type'.
The basic engine is a numerical one and jurabib is an authoryear one.
Later when adding new citation packages they will fall into one type or
another or both.
I welcome your comments,
Julien
>From 0ecb46dca12dc161f14e7d5dcfbd972443964dfd Mon Sep 17 00:00:00 2001
From: Julien Rioux <jri...@lyx.org>
Date: Sun, 9 Oct 2011 21:16:58 +0200
Subject: [PATCH 1/3] 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 422.
---
development/FORMAT | 5 +++
lib/lyx2lyx/lyx_2_1.py | 33 +++++++++++++++++++
src/BiblioInfo.cpp | 33 +++++++++++++------
src/BiblioInfo.h | 2 +-
src/BufferParams.cpp | 32 ++++++++++++++++---
src/BufferParams.h | 9 +++++
src/Citation.h | 8 +++-
src/LaTeXFeatures.cpp | 2 +-
src/frontends/qt4/GuiBibtex.cpp | 5 +--
src/frontends/qt4/GuiCitation.cpp | 13 +++++--
src/frontends/qt4/GuiCitation.h | 2 +
src/frontends/qt4/GuiDocument.cpp | 42 ++++++++++++++++++-------
src/frontends/qt4/GuiDocument.h | 2 +
src/frontends/qt4/Menus.cpp | 3 +-
src/insets/InsetBibtex.cpp | 5 +--
src/insets/InsetCitation.cpp | 62 +++++++++++++++++++------------------
src/version.h | 2 +-
17 files changed, 185 insertions(+), 75 deletions(-)
diff --git a/development/FORMAT b/development/FORMAT
index e5e6987..2db1675 100644
--- a/development/FORMAT
+++ b/development/FORMAT
@@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
-----------------------
+2011-12-18 Julien Rioux <jri...@lyx.org>
+ * Format incremented to 422 (r_____)
+ New buffer param \cite_engine_type to specify the type of
+ citation labels being used, authoryear or numerical.
+
2011-12-18 Georg Baum <georg.b...@post.rwth-aachen.de>
* Format incremented to 421 (r40522)
The caption flag of longtable rows is no longer exclusive to the head
diff --git a/lib/lyx2lyx/lyx_2_1.py b/lib/lyx2lyx/lyx_2_1.py
index a708c2d..11d6f68 100644
--- a/lib/lyx2lyx/lyx_2_1.py
+++ b/lib/lyx2lyx/lyx_2_1.py
@@ -332,6 +332,37 @@ def revert_longtable_captions(document):
handle_longtable_captions(document, False)
+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
#
@@ -346,9 +377,11 @@ convert = [
[419, []],
[420, [convert_biblio_style]],
[421, [convert_longtable_captions]],
+ [422, [convert_cite_engine_type]],
]
revert = [
+ [421, [revert_cite_engine_type]],
[420, [revert_longtable_captions]],
[419, [revert_biblio_style]],
[418, [revert_australian]],
diff --git a/src/BiblioInfo.cpp b/src/BiblioInfo.cpp
index 8eede65..8269044 100644
--- a/src/BiblioInfo.cpp
+++ b/src/BiblioInfo.cpp
@@ -692,8 +692,8 @@ bool BiblioInfo::isBibtex(docstring const & key) const
vector<docstring> const BiblioInfo::getCiteStrings(
docstring const & key, Buffer const & buf) const
{
- CiteEngine const engine = buf.params().citeEngine();
- if (engine == ENGINE_BASIC || engine == ENGINE_NATBIB_NUMERICAL)
+ CiteEngineType const engine_type = buf.params().citeEngineType();
+ if (engine_type == ENGINE_TYPE_NUMERICAL)
return getNumericalStrings(key, buf);
else
return getAuthorYearStrings(key, buf);
@@ -711,7 +711,8 @@ vector<docstring> const BiblioInfo::getNumericalStrings(
if (author.empty() || year.empty())
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());
for (size_t i = 0; i != vec.size(); ++i) {
@@ -770,7 +771,8 @@ vector<docstring> const BiblioInfo::getAuthorYearStrings(
if (author.empty() || year.empty())
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());
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)
{
collectCitedEntries(buf);
- CiteEngine const engine = buf.params().citeEngine();
- bool const numbers =
- (engine == ENGINE_BASIC || engine == ENGINE_NATBIB_NUMERICAL);
+ CiteEngineType const engine_type = buf.params().citeEngineType();
+ bool const numbers = (engine_type == ENGINE_TYPE_NUMERICAL);
int keynumber = 0;
char modifier = 0;
@@ -1025,17 +1026,18 @@ string citationStyleToString(const CitationStyle & s)
return cite;
}
-vector<CiteStyle> citeStyles(CiteEngine engine)
+vector<CiteStyle> citeStyles(CiteEngine engine, CiteEngineType engine_type)
{
vector<CiteStyle> styles(0);
- switch (engine) {
+ if (engine_type == ENGINE_TYPE_AUTHORYEAR) {
+ switch (engine) {
case ENGINE_BASIC:
styles.push_back(CITE);
break;
case ENGINE_JURABIB:
styles.push_back(CITE);
- case ENGINE_NATBIB_AUTHORYEAR:
+ case ENGINE_NATBIB:
styles.push_back(CITET);
styles.push_back(CITEP);
styles.push_back(CITEALT);
@@ -1044,7 +1046,15 @@ vector<CiteStyle> citeStyles(CiteEngine engine)
styles.push_back(CITEYEAR);
styles.push_back(CITEYEARPAR);
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(CITEALT);
styles.push_back(CITEAUTHOR);
@@ -1053,6 +1063,7 @@ vector<CiteStyle> citeStyles(CiteEngine engine)
styles.push_back(CITEYEAR);
styles.push_back(CITEYEARPAR);
break;
+ }
}
styles.push_back(NOCITE);
diff --git a/src/BiblioInfo.h b/src/BiblioInfo.h
index cc62660..c84300f 100644
--- a/src/BiblioInfo.h
+++ b/src/BiblioInfo.h
@@ -29,7 +29,7 @@ class Buffer;
/// FIXME: To Citation.cpp?
/// 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
CitationStyle citationStyleFromString(std::string const & latex_str);
/// the other way round
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 38f298c..8af7e9d 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -265,8 +265,7 @@ typedef Translator<string, CiteEngine> CiteEngineTranslator;
CiteEngineTranslator const init_citeenginetranslator()
{
CiteEngineTranslator translator("basic", ENGINE_BASIC);
- translator.addPair("natbib_numerical", ENGINE_NATBIB_NUMERICAL);
- translator.addPair("natbib_authoryear", ENGINE_NATBIB_AUTHORYEAR);
+ translator.addPair("natbib", ENGINE_NATBIB);
translator.addPair("jurabib", ENGINE_JURABIB);
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
typedef Translator<string, Spacing::Space> SpaceTranslator;
@@ -367,6 +384,7 @@ BufferParams::BufferParams()
use_mathdots = package_auto;
use_undertilde = package_auto;
cite_engine_ = ENGINE_BASIC;
+ cite_engine_type_ = ENGINE_TYPE_NUMERICAL;
biblio_style = "plain";
use_bibtopic = false;
use_indices = false;
@@ -699,6 +717,10 @@ string BufferParams::readToken(Lexer & lex, string const & token,
string engine;
lex >> 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") {
lex.eatLine();
biblio_style = lex.getString();
@@ -1005,6 +1027,7 @@ void BufferParams::writeFile(ostream & os) const
<< "\n\\use_mathdots " << use_mathdots
<< "\n\\use_undertilde " << use_undertilde
<< "\n\\cite_engine " << citeenginetranslator().find(cite_engine_)
+ << "\n\\cite_engine_type " << citeenginetypetranslator().find(cite_engine_type_)
<< "\n\\biblio_style " << biblio_style
<< "\n\\use_bibtopic " << convert<string>(use_bibtopic)
<< "\n\\use_indices " << convert<string>(use_indices)
@@ -2905,9 +2928,8 @@ CiteEngine BufferParams::citeEngine() const
{
// FIXME the class should provide the numerical/
// authoryear choice
- if (documentClass().provides("natbib")
- && cite_engine_ != ENGINE_NATBIB_NUMERICAL)
- return ENGINE_NATBIB_AUTHORYEAR;
+ if (documentClass().provides("natbib"))
+ return ENGINE_NATBIB;
return cite_engine_;
}
diff --git a/src/BufferParams.h b/src/BufferParams.h
index 5432a09..6750fb2 100644
--- a/src/BufferParams.h
+++ b/src/BufferParams.h
@@ -413,6 +413,13 @@ public:
///
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
std::string biblio_style;
@@ -476,6 +483,8 @@ private:
mutable DefaultFlavorCache default_flavors_;
/// for use with natbib
CiteEngine cite_engine_;
+ /// the type of cite engine (authoryear or numerical)
+ CiteEngineType cite_engine_type_;
///
DocumentClass * doc_class_;
///
diff --git a/src/Citation.h b/src/Citation.h
index 2e0fc3d..1eb4de8 100644
--- a/src/Citation.h
+++ b/src/Citation.h
@@ -18,11 +18,15 @@ class Buffer;
enum CiteEngine {
ENGINE_BASIC,
- ENGINE_NATBIB_AUTHORYEAR,
- ENGINE_NATBIB_NUMERICAL,
+ ENGINE_NATBIB,
ENGINE_JURABIB
};
+enum CiteEngineType {
+ ENGINE_TYPE_AUTHORYEAR = 1,
+ ENGINE_TYPE_NUMERICAL = 2,
+};
+
enum CiteStyle {
CITE,
CITET,
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index 1f66ce5..d8d561b 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -766,7 +766,7 @@ string const LaTeXFeatures::getPackages() const
// This special case is indicated by the "natbib-internal" key.
if (mustProvide("natbib") && !tclass.provides("natbib-internal")) {
packages << "\\usepackage[";
- if (params_.citeEngine() == ENGINE_NATBIB_NUMERICAL)
+ if (params_.citeEngineType() == ENGINE_TYPE_NUMERICAL)
packages << "numbers";
else
packages << "authoryear";
diff --git a/src/frontends/qt4/GuiBibtex.cpp b/src/frontends/qt4/GuiBibtex.cpp
index a2390a1..9286144 100644
--- a/src/frontends/qt4/GuiBibtex.cpp
+++ b/src/frontends/qt4/GuiBibtex.cpp
@@ -510,10 +510,7 @@ QString GuiBibtex::styleFile() const
case ENGINE_BASIC:
defaultstyle = "plain";
break;
- case ENGINE_NATBIB_AUTHORYEAR:
- defaultstyle = "plainnat";
- break;
- case ENGINE_NATBIB_NUMERICAL:
+ case ENGINE_NATBIB:
defaultstyle = "plainnat";
break;
case ENGINE_JURABIB:
diff --git a/src/frontends/qt4/GuiCitation.cpp b/src/frontends/qt4/GuiCitation.cpp
index 54f9ceb..6cd534b 100644
--- a/src/frontends/qt4/GuiCitation.cpp
+++ b/src/frontends/qt4/GuiCitation.cpp
@@ -211,9 +211,7 @@ void GuiCitation::updateControls(BiblioInfo const & bi)
void GuiCitation::updateFormatting(CiteStyle currentStyle)
{
CiteEngine const engine = citeEngine();
- bool const natbib_engine =
- engine == ENGINE_NATBIB_AUTHORYEAR ||
- engine == ENGINE_NATBIB_NUMERICAL;
+ bool const natbib_engine = engine == ENGINE_NATBIB;
bool const basic_engine = engine == ENGINE_BASIC;
bool const haveSelection =
@@ -624,7 +622,8 @@ bool GuiCitation::initialiseParams(string const & data)
{
InsetCommand::string2params(data, params_);
CiteEngine const engine = citeEngine();
- citeStyles_ = citeStyles(engine);
+ CiteEngineType const engine_type = citeEngineType();
+ citeStyles_ = citeStyles(engine, engine_type);
init();
return true;
}
@@ -664,6 +663,12 @@ CiteEngine GuiCitation::citeEngine() const
}
+CiteEngineType GuiCitation::citeEngineType() const
+{
+ return documentBuffer().params().citeEngineType();
+}
+
+
// Escape special chars.
// All characters are literals except: '.|*?+(){}[]^$\'
// These characters are literals when preceded by a "\", which is done here
diff --git a/src/frontends/qt4/GuiCitation.h b/src/frontends/qt4/GuiCitation.h
index 65e0dd6..3ca1b50 100644
--- a/src/frontends/qt4/GuiCitation.h
+++ b/src/frontends/qt4/GuiCitation.h
@@ -134,6 +134,8 @@ private:
std::vector<docstring> & keyVector, docstring entryType);
///
CiteEngine citeEngine() const;
+ ///
+ CiteEngineType citeEngineType() const;
/// Search a given string within the passed keys.
/// \return the vector of matched keys.
diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp
index 44f2afd..3b6bdb0 100644
--- a/src/frontends/qt4/GuiDocument.cpp
+++ b/src/frontends/qt4/GuiDocument.cpp
@@ -1101,6 +1101,10 @@ GuiDocument::GuiDocument(GuiView & lv)
// biblio
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)),
biblioModule->citationStyleL, SLOT(setEnabled(bool)));
connect(biblioModule->citeNatbibRB, SIGNAL(toggled(bool)),
@@ -2003,6 +2007,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 {
// FIXME unicode
// both of these should take a vector<docstring>
@@ -2237,17 +2257,16 @@ void GuiDocument::applyView()
// biblio
bp_.setCiteEngine(ENGINE_BASIC);
- if (biblioModule->citeNatbibRB->isChecked()) {
- bool const use_numerical_citations =
- biblioModule->citeStyleCO->currentIndex();
- if (use_numerical_citations)
- bp_.setCiteEngine(ENGINE_NATBIB_NUMERICAL);
- else
- bp_.setCiteEngine(ENGINE_NATBIB_AUTHORYEAR);
-
- } else if (biblioModule->citeJurabibRB->isChecked())
+ if (biblioModule->citeNatbibRB->isChecked())
+ bp_.setCiteEngine(ENGINE_NATBIB);
+ else if (biblioModule->citeJurabibRB->isChecked())
bp_.setCiteEngine(ENGINE_JURABIB);
+ if (biblioModule->citeStyleCO->currentIndex())
+ bp_.setCiteEngineType(ENGINE_TYPE_NUMERICAL);
+ else
+ bp_.setCiteEngineType(ENGINE_TYPE_AUTHORYEAR);
+
bp_.use_bibtopic =
biblioModule->bibtopicCB->isChecked();
@@ -2675,11 +2694,10 @@ void GuiDocument::paramsToDialog()
bp_.citeEngine() == ENGINE_BASIC);
biblioModule->citeNatbibRB->setChecked(
- bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL ||
- bp_.citeEngine() == ENGINE_NATBIB_AUTHORYEAR);
+ bp_.citeEngine() == ENGINE_NATBIB);
biblioModule->citeStyleCO->setCurrentIndex(
- bp_.citeEngine() == ENGINE_NATBIB_NUMERICAL);
+ bp_.citeEngineType() == ENGINE_TYPE_NUMERICAL);
biblioModule->citeJurabibRB->setChecked(
bp_.citeEngine() == ENGINE_JURABIB);
diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h
index fa0e504..0d2db66 100644
--- a/src/frontends/qt4/GuiDocument.h
+++ b/src/frontends/qt4/GuiDocument.h
@@ -107,6 +107,8 @@ private Q_SLOTS:
void languagePackageChanged(int);
void biblioChanged();
void bibtexChanged(int);
+ void setAuthorYear(bool);
+ void setNumerical(bool);
void updateModuleInfo();
void modulesChanged();
void changeBackgroundColor();
diff --git a/src/frontends/qt4/Menus.cpp b/src/frontends/qt4/Menus.cpp
index 4203e8e..7da40e6 100644
--- a/src/frontends/qt4/Menus.cpp
+++ b/src/frontends/qt4/Menus.cpp
@@ -1488,7 +1488,8 @@ void MenuDefinition::expandCiteStyles(BufferView const * bv)
if (contains(key, ','))
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 =
buf->masterBibInfo().getCiteStrings(key, bv->buffer());
diff --git a/src/insets/InsetBibtex.cpp b/src/insets/InsetBibtex.cpp
index bd95633..62f9e0e 100644
--- a/src/insets/InsetBibtex.cpp
+++ b/src/insets/InsetBibtex.cpp
@@ -936,9 +936,8 @@ docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
{
BiblioInfo const & bibinfo = buffer().masterBibInfo();
vector<docstring> const & cites = bibinfo.citedEntries();
- CiteEngine const engine = buffer().params().citeEngine();
- bool const numbers =
- (engine == ENGINE_BASIC || engine == ENGINE_NATBIB_NUMERICAL);
+ CiteEngineType const engine_type = buffer().params().citeEngineType();
+ bool const numbers = (engine_type == ENGINE_TYPE_NUMERICAL);
docstring reflabel = from_ascii("References");
Language const * l = buffer().params().language;
diff --git a/src/insets/InsetCitation.cpp b/src/insets/InsetCitation.cpp
index a53ed54..2406a2e 100644
--- a/src/insets/InsetCitation.cpp
+++ b/src/insets/InsetCitation.cpp
@@ -143,18 +143,18 @@ docstring InsetCitation::toolTip(BufferView const & bv, int, int) const
namespace {
// FIXME See the header for the issue.
-string defaultCiteCommand(CiteEngine engine)
+string defaultCiteCommand(CiteEngine engine, CiteEngineType engine_type)
{
string str;
switch (engine) {
case ENGINE_BASIC:
str = "cite";
break;
- case ENGINE_NATBIB_AUTHORYEAR:
- str = "citet";
- break;
- case ENGINE_NATBIB_NUMERICAL:
- str = "citep";
+ case ENGINE_NATBIB:
+ if (engine_type == ENGINE_TYPE_AUTHORYEAR)
+ str = "citet";
+ else
+ str = "citep";
break;
case ENGINE_JURABIB:
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))
return default_str;
@@ -179,8 +180,7 @@ string asValidLatexCommand(string const & input, CiteEngine const engine)
output = default_str;
break;
- case ENGINE_NATBIB_AUTHORYEAR:
- case ENGINE_NATBIB_NUMERICAL:
+ case ENGINE_NATBIB:
if (input == "cite" || input == "citefield"
|| input == "citetitle" || input == "cite*")
output = default_str;
@@ -259,8 +259,9 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
// CITE: author/<before field>
CiteEngine const engine = buffer().params().citeEngine();
+ CiteEngineType const engine_type = buffer().params().citeEngineType();
// 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 we were going to use them, this would mean ForceUCase
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>)
else if (cite_type == "citet") {
switch (engine) {
- case ENGINE_NATBIB_AUTHORYEAR:
- label += author + op_str + before_str +
- wrapCitation(*it, year, for_xhtml) + cp + sep_str;
- break;
- case ENGINE_NATBIB_NUMERICAL:
- label += author + op_str + before_str +
- wrapCitation(*it, citenum, for_xhtml) + cp + sep_str;
+ case ENGINE_NATBIB:
+ if (engine_type == ENGINE_TYPE_AUTHORYEAR)
+ label += author + op_str + before_str +
+ wrapCitation(*it, year, for_xhtml) + cp + sep_str;
+ else
+ label += author + op_str + before_str +
+ wrapCitation(*it, citenum, for_xhtml) + cp + sep_str;
break;
case ENGINE_JURABIB:
label += before_str + author + op_str +
@@ -369,7 +370,7 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
// author, year; author, year; ...
else if (cite_type == "citep" ||
cite_type == "citealp") {
- if (engine == ENGINE_NATBIB_NUMERICAL) {
+ if (engine_type == ENGINE_TYPE_NUMERICAL) {
label += wrapCitation(*it, citenum, for_xhtml) + sep_str;
} else {
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>)
else if (cite_type == "citealt") {
switch (engine) {
- case ENGINE_NATBIB_AUTHORYEAR:
- label += author + ' ' + before_str +
- wrapCitation(*it, year, for_xhtml) + sep_str;
- break;
- case ENGINE_NATBIB_NUMERICAL:
- label += author + ' ' + before_str + '#' +
- wrapCitation(*it, citenum, for_xhtml) + sep_str;
+ case ENGINE_NATBIB:
+ if (engine_type == ENGINE_TYPE_AUTHORYEAR)
+ label += author + ' ' + before_str +
+ wrapCitation(*it, year, for_xhtml) + sep_str;
+ else
+ label += author + ' ' + before_str + '#' +
+ wrapCitation(*it, citenum, for_xhtml) + sep_str;
break;
case ENGINE_JURABIB:
label += before_str +
@@ -416,7 +417,8 @@ docstring InsetCitation::complexLabel(bool for_xhtml) const
label.insert(label.size() - 1, after_str);
} else {
bool const add =
- !(engine == ENGINE_NATBIB_NUMERICAL &&
+ !(engine == ENGINE_NATBIB &&
+ engine_type == ENGINE_TYPE_NUMERICAL &&
(cite_type == "citeauthor" ||
cite_type == "citeyear"));
if (add)
@@ -567,10 +569,11 @@ void InsetCitation::forToc(docstring & os, size_t) const
void InsetCitation::latex(otexstream & os, OutputParams const & runparams) const
{
CiteEngine cite_engine = buffer().params().citeEngine();
+ CiteEngineType cite_engine_type = buffer().params().citeEngineType();
BiblioInfo const & bi = buffer().masterBibInfo();
// FIXME UNICODE
docstring const cite_str = from_utf8(
- asValidLatexCommand(getCmdName(), cite_engine));
+ asValidLatexCommand(getCmdName(), cite_engine, cite_engine_type));
if (runparams.inulemcmd)
os << "\\mbox{";
@@ -600,8 +603,7 @@ void InsetCitation::validate(LaTeXFeatures & features) const
switch (features.bufferParams().citeEngine()) {
case ENGINE_BASIC:
break;
- case ENGINE_NATBIB_AUTHORYEAR:
- case ENGINE_NATBIB_NUMERICAL:
+ case ENGINE_NATBIB:
features.require("natbib");
break;
case ENGINE_JURABIB:
diff --git a/src/version.h b/src/version.h
index ae49512..705092e 100644
--- a/src/version.h
+++ b/src/version.h
@@ -30,7 +30,7 @@ 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 421 // baum : longtable captions
+#define LYX_FORMAT_LYX 422 // jrioux : \cite_engine_type (authoryear|numerical)
#define LYX_FORMAT_TEX2LYX 421
#if LYX_FORMAT_FOR_TEX2LYX != LYX_FORMAT_FOR_LYX
--
1.7.3.4
>From 9b5a9e1d3a9e0d39a9dc3a6e4de765a7fa67e7cf Mon Sep 17 00:00:00 2001
From: Julien Rioux <jri...@lyx.org>
Date: Fri, 16 Dec 2011 14:28:58 +0100
Subject: [PATCH 2/3] Update tex2lyx to format 422.
The type of citation engine is determined by the citation package
being used and, in the case of natbib, its options.
---
src/tex2lyx/Preamble.cpp | 8 ++++++--
src/tex2lyx/Preamble.h | 1 +
src/version.h | 2 +-
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index f06d11e..6eb1576 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -401,6 +401,7 @@ Preamble::Preamble() : one_language(true)
//h_boxbgcolor;
h_biblio_style = "plain";
h_cite_engine = "basic";
+ h_cite_engine_type = "numerical";
h_defskip = "medskip";
//h_float_placement;
//h_fontcolor;
@@ -746,7 +747,8 @@ void Preamble::handle_package(Parser &p, string const & name,
else if (name == "natbib") {
h_biblio_style = "plainnat";
- h_cite_engine = "natbib_authoryear";
+ h_cite_engine = "natbib";
+ h_cite_engine_type = "authoryear";
vector<string>::iterator it =
find(options.begin(), options.end(), "authoryear");
if (it != options.end())
@@ -754,7 +756,7 @@ void Preamble::handle_package(Parser &p, string const & name,
else {
it = find(options.begin(), options.end(), "numbers");
if (it != options.end()) {
- h_cite_engine = "natbib_numerical";
+ h_cite_engine_type = "numerical";
options.erase(it);
}
}
@@ -763,6 +765,7 @@ void Preamble::handle_package(Parser &p, string const & name,
else if (name == "jurabib") {
h_biblio_style = "jurabib";
h_cite_engine = "jurabib";
+ h_cite_engine_type = "authoryear";
}
else if (name == "hyperref")
@@ -932,6 +935,7 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc)
<< "\\use_mathdots " << h_use_mathdots << "\n"
<< "\\use_undertilde " << h_use_undertilde << "\n"
<< "\\cite_engine " << h_cite_engine << "\n"
+ << "\\cite_engine_type " << h_cite_engine_type << "\n"
<< "\\biblio_style " << h_biblio_style << "\n"
<< "\\use_bibtopic " << h_use_bibtopic << "\n"
<< "\\use_indices " << h_use_indices << "\n"
diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h
index 14a7597..a6d9dbe 100644
--- a/src/tex2lyx/Preamble.h
+++ b/src/tex2lyx/Preamble.h
@@ -83,6 +83,7 @@ private:
std::string h_biblio_style;
std::string h_boxbgcolor;
std::string h_cite_engine;
+ std::string h_cite_engine_type;
std::string h_defskip;
std::string h_float_placement;
std::string h_fontcolor;
diff --git a/src/version.h b/src/version.h
index 705092e..a237cfd 100644
--- a/src/version.h
+++ b/src/version.h
@@ -31,7 +31,7 @@ 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 422 // jrioux : \cite_engine_type (authoryear|numerical)
-#define LYX_FORMAT_TEX2LYX 421
+#define LYX_FORMAT_TEX2LYX 422 // jrioux : \cite_engine_type (authoryear|numerical)
#if LYX_FORMAT_FOR_TEX2LYX != LYX_FORMAT_FOR_LYX
#warning "tex2lyx produces an out of date file format."
--
1.7.3.4