mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Support for nocite, provided by Bernhard Reiter.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22217 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
1f3234b3ae
commit
e285d2a7d8
@ -1,6 +1,9 @@
|
||||
LyX file-format changes
|
||||
-----------------------
|
||||
|
||||
2007-12-11 Bernhard Reiter <ockham@gmx.net>
|
||||
* Format incremented to 309: support for \nocite
|
||||
|
||||
2007-12-15 Uwe Stöhr <uwestoehr@web.de>
|
||||
* Format incremented to 308: support for Serbian (Latin)
|
||||
|
||||
|
@ -80,7 +80,7 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)),
|
||||
("1_3", [221], minor_versions("1.3" , 7)),
|
||||
("1_4", range(222,246), minor_versions("1.4" , 5)),
|
||||
("1_5", range(246,277), minor_versions("1.5" , 2)),
|
||||
("1_6", range(277,309), minor_versions("1.6" , 0))] # Uwe: Serbian-Latin
|
||||
("1_6", range(277,310), minor_versions("1.6" , 0))] # Bernhard Reiter: nocite
|
||||
|
||||
|
||||
def formats_list():
|
||||
|
@ -945,6 +945,39 @@ def revert_nobreakdash(document):
|
||||
document.header[j] = "\\use_amsmath 2"
|
||||
|
||||
|
||||
def revert_nocite_key(body, start, end):
|
||||
'key "..." -> \nocite{...}'
|
||||
for i in range(start, end):
|
||||
if (body[i][0:5] == 'key "'):
|
||||
body[i] = body[i].replace('key "', "\\backslash\nnocite{")
|
||||
body[i] = body[i].replace('"', "}")
|
||||
else:
|
||||
body[i] = ""
|
||||
|
||||
|
||||
def revert_nocite(document):
|
||||
"Revert LatexCommand nocite to ERT"
|
||||
i = 0
|
||||
while 1:
|
||||
i = find_token(document.body, "\\begin_inset CommandInset citation", i)
|
||||
if i == -1:
|
||||
return
|
||||
i = i + 1
|
||||
if (document.body[i] == "LatexCommand nocite"):
|
||||
j = find_end_of_inset(document.body, i + 1)
|
||||
if j == -1:
|
||||
#this should not happen
|
||||
document.warning("End of CommandInset citation not found in revert_nocite!")
|
||||
revert_nocite_key(document.body, i + 1, len(document.body))
|
||||
return
|
||||
revert_nocite_key(document.body, i + 1, j)
|
||||
document.body[i-1] = "\\begin_inset ERT"
|
||||
document.body[i] = "status collapsed\n\n" \
|
||||
"\\begin_layout Standard"
|
||||
document.body.insert(j, "\\end_layout\n");
|
||||
i = j
|
||||
|
||||
|
||||
def revert_bahasam(document):
|
||||
"Set language Bahasa Malaysia to Bahasa Indonesia"
|
||||
i = 0
|
||||
@ -1032,10 +1065,12 @@ convert = [[277, [fix_wrong_tables]],
|
||||
[305, []],
|
||||
[306, []],
|
||||
[307, []],
|
||||
[308, []]
|
||||
[308, []],
|
||||
[309, []]
|
||||
]
|
||||
|
||||
revert = [[307, [revert_serbianlatin]],
|
||||
revert = [[308, [revert_nocite]],
|
||||
[307, [revert_serbianlatin]],
|
||||
[306, [revert_slash, revert_nobreakdash]],
|
||||
[305, [revert_interlingua]],
|
||||
[304, [revert_bahasam]],
|
||||
|
@ -282,7 +282,8 @@ vector<docstring> const BiblioInfo::getCiteStrings(
|
||||
docstring const & key, Buffer const & buf) const
|
||||
{
|
||||
biblio::CiteEngine const engine = buf.params().getEngine();
|
||||
if (engine == biblio::ENGINE_NATBIB_NUMERICAL)
|
||||
if (engine == biblio::ENGINE_BASIC ||
|
||||
engine == biblio::ENGINE_NATBIB_NUMERICAL)
|
||||
return getNumericalStrings(key, buf);
|
||||
else
|
||||
return getAuthorYearStrings(key, buf);
|
||||
@ -304,7 +305,7 @@ vector<docstring> const BiblioInfo::getNumericalStrings(
|
||||
biblio::getCiteStyles(buf.params().getEngine());
|
||||
|
||||
vector<docstring> vec(styles.size());
|
||||
for (size_t i = 0; i != vec.size(); ++i) {
|
||||
for (vector<docstring>::size_type i = 0; i != vec.size(); ++i) {
|
||||
docstring str;
|
||||
|
||||
switch (styles[i]) {
|
||||
@ -313,6 +314,10 @@ vector<docstring> const BiblioInfo::getNumericalStrings(
|
||||
str = from_ascii("[#ID]");
|
||||
break;
|
||||
|
||||
case biblio::NOCITE:
|
||||
str = _("Add to bibliography only.");
|
||||
break;
|
||||
|
||||
case biblio::CITET:
|
||||
str = author + " [#ID]";
|
||||
break;
|
||||
@ -370,6 +375,10 @@ vector<docstring> const BiblioInfo::getAuthorYearStrings(
|
||||
str = author + "/<" + _("before") + '>';
|
||||
break;
|
||||
|
||||
case biblio::NOCITE:
|
||||
str = _("Add to bibliography only.");
|
||||
break;
|
||||
|
||||
case biblio::CITET:
|
||||
str = author + " (" + year + ')';
|
||||
break;
|
||||
@ -435,15 +444,15 @@ namespace {
|
||||
|
||||
|
||||
char const * const citeCommands[] = {
|
||||
"cite", "citet", "citep", "citealt", "citealp", "citeauthor",
|
||||
"citeyear", "citeyearpar" };
|
||||
"cite", "nocite", "citet", "citep", "citealt", "citealp",
|
||||
"citeauthor", "citeyear", "citeyearpar" };
|
||||
|
||||
unsigned int const nCiteCommands =
|
||||
sizeof(citeCommands) / sizeof(char *);
|
||||
|
||||
CiteStyle const citeStyles[] = {
|
||||
CITE, CITET, CITEP, CITEALT, CITEALP,
|
||||
CITEAUTHOR, CITEYEAR, CITEYEARPAR };
|
||||
CITE, NOCITE, CITET, CITEP, CITEALT,
|
||||
CITEALP, CITEAUTHOR, CITEYEAR, CITEYEARPAR };
|
||||
|
||||
unsigned int const nCiteStyles =
|
||||
sizeof(citeStyles) / sizeof(CiteStyle);
|
||||
@ -517,7 +526,7 @@ vector<CiteStyle> const getCiteStyles(CiteEngine const engine)
|
||||
|
||||
switch (engine) {
|
||||
case ENGINE_BASIC:
|
||||
nStyles = 1;
|
||||
nStyles = 2;
|
||||
start = 0;
|
||||
break;
|
||||
case ENGINE_NATBIB_AUTHORYEAR:
|
||||
|
@ -36,6 +36,7 @@ enum CiteEngine {
|
||||
|
||||
enum CiteStyle {
|
||||
CITE,
|
||||
NOCITE,
|
||||
CITET,
|
||||
CITEP,
|
||||
CITEALT,
|
||||
|
@ -118,7 +118,7 @@ namespace os = support::os;
|
||||
|
||||
namespace {
|
||||
|
||||
int const LYX_FORMAT = 308; // Uwe: Serbian-Latin
|
||||
int const LYX_FORMAT = 309; // Bernhard Reiter: support for \nocite
|
||||
|
||||
} // namespace anon
|
||||
|
||||
|
@ -82,7 +82,7 @@ GuiCitation::GuiCitation(GuiView & lv)
|
||||
setViewTitle(_("Citation"));
|
||||
|
||||
connect(citationStyleCO, SIGNAL(activated(int)),
|
||||
this, SLOT(changed()));
|
||||
this, SLOT(on_citationStyleCO_currentIndexChanged(int)));
|
||||
connect(fulllistCB, SIGNAL(clicked()),
|
||||
this, SLOT(changed()));
|
||||
connect(forceuppercaseCB, SIGNAL(clicked()),
|
||||
@ -188,7 +188,7 @@ void GuiCitation::updateView()
|
||||
// called in update() do not need to be called for INTERNAL updates,
|
||||
// such as when addPB is pressed, as the list of fields, entries, etc,
|
||||
// will not have changed. At the moment, however, the division between
|
||||
// fillStyles() and updateStyles() doesn't lend itself to dividing the
|
||||
// fillStyles() and updateStyle() doesn't lend itself to dividing the
|
||||
// two methods, though they should be divisible.
|
||||
void GuiCitation::updateDialog()
|
||||
{
|
||||
@ -212,7 +212,7 @@ void GuiCitation::updateDialog()
|
||||
}
|
||||
|
||||
|
||||
void GuiCitation::updateStyle()
|
||||
void GuiCitation::updateFormatting(biblio::CiteStyle currentStyle)
|
||||
{
|
||||
biblio::CiteEngine const engine = getEngine();
|
||||
bool const natbib_engine =
|
||||
@ -222,15 +222,22 @@ void GuiCitation::updateStyle()
|
||||
|
||||
bool const haveSelection =
|
||||
selectedLV->model()->rowCount() > 0;
|
||||
fulllistCB->setEnabled(natbib_engine && haveSelection);
|
||||
forceuppercaseCB->setEnabled(natbib_engine && haveSelection);
|
||||
textBeforeED->setEnabled(!basic_engine && haveSelection);
|
||||
textBeforeLA->setEnabled(!basic_engine && haveSelection);
|
||||
textAfterED->setEnabled(haveSelection);
|
||||
textAfterLA->setEnabled(haveSelection);
|
||||
citationStyleCO->setEnabled(!basic_engine && haveSelection);
|
||||
citationStyleLA->setEnabled(!basic_engine && haveSelection);
|
||||
|
||||
bool const isNocite = currentStyle == biblio::NOCITE;
|
||||
|
||||
fulllistCB->setEnabled(natbib_engine && haveSelection && !isNocite);
|
||||
forceuppercaseCB->setEnabled(natbib_engine && haveSelection && !isNocite);
|
||||
textBeforeED->setEnabled(!basic_engine && haveSelection && !isNocite);
|
||||
textBeforeLA->setEnabled(!basic_engine && haveSelection && !isNocite);
|
||||
textAfterED->setEnabled(haveSelection && !isNocite);
|
||||
textAfterLA->setEnabled(haveSelection && !isNocite);
|
||||
citationStyleCO->setEnabled(haveSelection);
|
||||
citationStyleLA->setEnabled(haveSelection);
|
||||
}
|
||||
|
||||
|
||||
void GuiCitation::updateStyle()
|
||||
{
|
||||
string const & command = params_.getCmdName();
|
||||
|
||||
// Find the style of the citekeys
|
||||
@ -255,9 +262,9 @@ void GuiCitation::updateStyle()
|
||||
fulllistCB->setChecked(false);
|
||||
forceuppercaseCB->setChecked(false);
|
||||
}
|
||||
updateFormatting(cs.style);
|
||||
}
|
||||
|
||||
|
||||
//This one needs to be called whenever citationStyleCO needs
|
||||
//to be updated---and this would be on anything that changes the
|
||||
//selection in selectedLV, or on a general update.
|
||||
@ -283,12 +290,10 @@ void GuiCitation::fillStyles()
|
||||
|
||||
QStringList sty = citationStyles(curr);
|
||||
|
||||
bool const basic_engine = (getEngine() == biblio::ENGINE_BASIC);
|
||||
citationStyleCO->setEnabled(!sty.isEmpty());
|
||||
citationStyleLA->setEnabled(!sty.isEmpty());
|
||||
|
||||
citationStyleCO->setEnabled(!sty.isEmpty() && !basic_engine);
|
||||
citationStyleLA->setEnabled(!sty.isEmpty() && !basic_engine);
|
||||
|
||||
if (sty.isEmpty() || basic_engine)
|
||||
if (sty.isEmpty())
|
||||
return;
|
||||
|
||||
citationStyleCO->insertItems(0, sty);
|
||||
@ -403,6 +408,15 @@ void GuiCitation::on_entriesCO_currentIndexChanged(int /*index*/)
|
||||
}
|
||||
|
||||
|
||||
void GuiCitation::on_citationStyleCO_currentIndexChanged(int index)
|
||||
{
|
||||
if (index >= 0 && index < citationStyleCO->count()) {
|
||||
vector<biblio::CiteStyle> const & styles = citeStyles_;
|
||||
updateFormatting(styles[index]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void GuiCitation::on_findLE_textChanged(const QString & text)
|
||||
{
|
||||
clearPB->setDisabled(text.isEmpty());
|
||||
@ -426,19 +440,24 @@ void GuiCitation::on_regexCB_stateChanged(int)
|
||||
|
||||
void GuiCitation::changed()
|
||||
{
|
||||
fillStyles();
|
||||
setButtons();
|
||||
}
|
||||
|
||||
|
||||
void GuiCitation::apply(int const choice, bool const full, bool const force,
|
||||
void GuiCitation::apply(int const choice, bool full, bool force,
|
||||
QString before, QString after)
|
||||
{
|
||||
if (cited_keys_.isEmpty())
|
||||
return;
|
||||
|
||||
vector<biblio::CiteStyle> const & styles = citeStyles_;
|
||||
|
||||
if (styles[choice] == biblio::NOCITE) {
|
||||
full = false;
|
||||
force = false;
|
||||
before.clear();
|
||||
after.clear();
|
||||
}
|
||||
|
||||
string const command =
|
||||
biblio::CitationStyle(styles[choice], full, force)
|
||||
.asLatexStr();
|
||||
@ -575,17 +594,9 @@ bool GuiCitation::initialiseParams(string const & data)
|
||||
|
||||
biblio::CiteEngine const engine = buffer().params().getEngine();
|
||||
|
||||
bool use_styles = engine != biblio::ENGINE_BASIC;
|
||||
|
||||
bibkeysInfo_.fillWithBibKeys(&buffer());
|
||||
|
||||
if (citeStyles_.empty())
|
||||
citeStyles_ = biblio::getCiteStyles(engine);
|
||||
else {
|
||||
if ((use_styles && citeStyles_.size() == 1) ||
|
||||
(!use_styles && citeStyles_.size() != 1))
|
||||
citeStyles_ = biblio::getCiteStyles(engine);
|
||||
}
|
||||
citeStyles_ = biblio::getCiteStyles(engine);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ private Q_SLOTS:
|
||||
void on_findLE_textChanged(const QString & text);
|
||||
void on_fieldsCO_currentIndexChanged(int index);
|
||||
void on_entriesCO_currentIndexChanged(int index);
|
||||
void on_citationStyleCO_currentIndexChanged(int index);
|
||||
void on_caseCB_stateChanged(int);
|
||||
void on_regexCB_stateChanged(int);
|
||||
void changed();
|
||||
@ -84,6 +85,8 @@ private:
|
||||
void fillEntries();
|
||||
/// set the styles combo
|
||||
void updateStyle();
|
||||
/// set the formatting widgets
|
||||
void updateFormatting(biblio::CiteStyle currentStyle);
|
||||
/// last used citation style
|
||||
int style_;
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "BufferParams.h"
|
||||
#include "support/debug.h"
|
||||
#include "DispatchResult.h"
|
||||
#include "support/gettext.h"
|
||||
#include "FuncRequest.h"
|
||||
#include "LaTeXFeatures.h"
|
||||
|
||||
@ -36,7 +37,7 @@ namespace {
|
||||
vector<string> const init_possible_cite_commands()
|
||||
{
|
||||
char const * const possible[] = {
|
||||
"cite", "citet", "citep", "citealt", "citealp",
|
||||
"cite", "nocite", "citet", "citep", "citealt", "citealp",
|
||||
"citeauthor", "citeyear", "citeyearpar",
|
||||
"citet*", "citep*", "citealt*", "citealp*", "citeauthor*",
|
||||
"Citet", "Citep", "Citealt", "Citealp", "Citeauthor",
|
||||
@ -91,7 +92,7 @@ string const
|
||||
string output;
|
||||
switch (engine) {
|
||||
case biblio::ENGINE_BASIC:
|
||||
output = default_str;
|
||||
output = input;
|
||||
break;
|
||||
|
||||
case biblio::ENGINE_NATBIB_AUTHORYEAR:
|
||||
@ -125,7 +126,7 @@ string const
|
||||
}
|
||||
|
||||
|
||||
docstring const getNatbibLabel(Buffer const & buffer,
|
||||
docstring const getComplexLabel(Buffer const & buffer,
|
||||
string const & citeType, docstring const & keyList,
|
||||
docstring const & before, docstring const & after,
|
||||
biblio::CiteEngine engine)
|
||||
@ -209,16 +210,25 @@ docstring const getNatbibLabel(Buffer const & buffer,
|
||||
}
|
||||
|
||||
docstring after_str;
|
||||
if (!after.empty()) {
|
||||
// The "after" key is appended only to the end of the whole.
|
||||
// The "after" key is appended only to the end of the whole.
|
||||
if (cite_type == "nocite")
|
||||
after_str = " (" + _("not cited") + ')';
|
||||
else if (!after.empty()) {
|
||||
after_str = ", " + after;
|
||||
}
|
||||
|
||||
// One day, these might be tunable (as they are in BibTeX).
|
||||
char const op = '('; // opening parenthesis.
|
||||
char const cp = ')'; // closing parenthesis.
|
||||
// puctuation mark separating citation entries.
|
||||
char const * const sep = ";";
|
||||
char op, cp; // opening and closing parenthesis.
|
||||
char * sep; // punctuation mark separating citation entries.
|
||||
if (engine == biblio::ENGINE_BASIC) {
|
||||
op = '[';
|
||||
cp = ']';
|
||||
sep = ",";
|
||||
} else {
|
||||
op = '(';
|
||||
cp = ')';
|
||||
sep = ";";
|
||||
}
|
||||
|
||||
docstring const op_str = ' ' + docstring(1, op);
|
||||
docstring const cp_str = docstring(1, cp) + ' ';
|
||||
@ -239,11 +249,19 @@ docstring const getNatbibLabel(Buffer const & buffer,
|
||||
|
||||
// authors1/<before>; ... ;
|
||||
// authors_last, <after>
|
||||
if (cite_type == "cite" && engine == biblio::ENGINE_JURABIB) {
|
||||
if (it == keys.begin())
|
||||
label += author + before_str + sep_str;
|
||||
else
|
||||
label += author + sep_str;
|
||||
if (cite_type == "cite") {
|
||||
if (engine == biblio::ENGINE_BASIC) {
|
||||
label += *it + sep_str;
|
||||
} else if (engine == biblio::ENGINE_JURABIB) {
|
||||
if (it == keys.begin())
|
||||
label += author + before_str + sep_str;
|
||||
else
|
||||
label += author + sep_str;
|
||||
}
|
||||
|
||||
// nocite
|
||||
} else if (cite_type == "nocite") {
|
||||
label += *it + sep_str;
|
||||
|
||||
// (authors1 (<before> year); ... ;
|
||||
// authors_last (<before> year, <after>)
|
||||
@ -324,7 +342,8 @@ docstring const getNatbibLabel(Buffer const & buffer,
|
||||
label = before_str + label;
|
||||
}
|
||||
|
||||
if (cite_type == "citep" || cite_type == "citeyearpar")
|
||||
if (cite_type == "citep" || cite_type == "citeyearpar" ||
|
||||
(cite_type == "cite" && engine == biblio::ENGINE_BASIC) )
|
||||
label = op + label + cp;
|
||||
|
||||
return label;
|
||||
@ -390,10 +409,8 @@ docstring const InsetCitation::generateLabel(Buffer const & buffer) const
|
||||
|
||||
docstring label;
|
||||
biblio::CiteEngine const engine = buffer.params().getEngine();
|
||||
if (engine != biblio::ENGINE_BASIC) {
|
||||
label = getNatbibLabel(buffer, getCmdName(), getParam("key"),
|
||||
before, after, engine);
|
||||
}
|
||||
label = getComplexLabel(buffer, getCmdName(), getParam("key"),
|
||||
before, after, engine);
|
||||
|
||||
// Fallback to fail-safe
|
||||
if (label.empty())
|
||||
|
@ -87,7 +87,7 @@ string parse_text_snippet(Parser & p, unsigned flags, const bool outer,
|
||||
}
|
||||
|
||||
|
||||
char const * const known_latex_commands[] = { "ref", "cite", "label",
|
||||
char const * const known_latex_commands[] = { "ref", "cite", "nocite", "label",
|
||||
"index", "printindex", "pageref", "url", "vref", "vpageref", "prettyref",
|
||||
"eqref", 0 };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user