Am Samstag, den 08.12.2007, 11:08 +0100 schrieb Jürgen Spitzmüller: > Excellent. Note, however, that this is a file format change (because "nocite" > has to be reverted to ERT). You'll have to increment the file format and > provide a lyx2lyx function to revert nocite (which should be very easy). > > Regarding "\nocite" in the label: I think this is too LaTeX-centric. I would > rather append something like _("not cited").
Done. The whole job took a bit longer than expected, as I noticed a couple of other issues (re inset and citation style options labelling for \nocite and \cite, in case of biblio::BASIC_ENGINE) I had previously overlooked. > > This also fixes a bug I've stumbled across while working on it: > > In a document with citations, after changing the bibliography style (eg > > from plain to natbib or from natbib to jurabib), the citation style > > shown in the citation dialog is different from the actual inset. This is > > fixed by having initialiseParams re-evaluate getCitationStyles each time > > the dialog is opened no matter what -- which is required for the \nocite > > functionality anyway. > > > > If there's interest, I'll also roll out a patch for 1.5. > > I don't see this neither in 1.5 nor 1.6 (or I didn't understand your > receipt). In a document with citations, saved with bibliography citation style eg "Natbib" (as set from Document>Settings>Bibliography, not the BibTeX dialog stuff!), and "individual" citation style eg "Author (Year)", change that "global" citation style to Jurabib and set the individual citation style of some citation eg to "Author". The inset will then be labelled with the year instead of the author (ie the layout that comes after the one actually selected; departing from jurabib to natibib, it's the other way round). > Actually, your patch disables the optimization of the bibfiles cache, which > means that opening the dialog needs very long when you have a big > bibliography database. Why is it required for \nocite anyway? Does it really? I was thinking I'd just be affecting the (~ 10) "individual" citation styles (\cite, \nocite, \citet etc), not the bibfiles cache. The previous optimisations didn't update the styles when biblio::BASIC_ENGINE (instead of natbib/jurabib) was used, as there was only one citation style available in that case -- now with \nocite, it's two. > > Regarding a \nocite{*} option: what about enabling the "Contents" combo > > in the BibTeX dialog also for non-sectioned bibliographies, just without > > the "all uncited references" option? > > Yes. That'll have to wait a little -- exams pending. Bernhard
Index: src/BiblioInfo.h =================================================================== --- src/BiblioInfo.h (Revision 22130) +++ src/BiblioInfo.h (Arbeitskopie) @@ -36,6 +36,7 @@ enum CiteStyle { CITE, + NOCITE, CITET, CITEP, CITEALT, Index: src/BiblioInfo.cpp =================================================================== --- src/BiblioInfo.cpp (Revision 22130) +++ src/BiblioInfo.cpp (Arbeitskopie) @@ -282,7 +282,8 @@ 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 @@ 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 @@ 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 @@ str = author + "/<" + _("before") + '>'; break; + case biblio::NOCITE: + str = _("Add to bibliography only."); + break; + case biblio::CITET: str = author + " (" + year + ')'; break; @@ -435,15 +444,15 @@ 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 @@ switch (engine) { case ENGINE_BASIC: - nStyles = 1; + nStyles = 2; start = 0; break; case ENGINE_NATBIB_AUTHORYEAR: Index: src/insets/InsetCitation.cpp =================================================================== --- src/insets/InsetCitation.cpp (Revision 22130) +++ src/insets/InsetCitation.cpp (Arbeitskopie) @@ -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 @@ 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 output; switch (engine) { case biblio::ENGINE_BASIC: - output = default_str; + output = input; break; case biblio::ENGINE_NATBIB_AUTHORYEAR: @@ -125,7 +126,7 @@ } -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 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,12 +249,20 @@ // 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>) } else if (cite_type == "citet") { @@ -324,7 +342,8 @@ 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 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()) Index: src/frontends/qt4/GuiCitation.h =================================================================== --- src/frontends/qt4/GuiCitation.h (Revision 22130) +++ src/frontends/qt4/GuiCitation.h (Arbeitskopie) @@ -65,6 +65,7 @@ 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 @@ void fillEntries(); /// set the styles combo void updateStyle(); + /// set the formatting widgets + void updateFormatting(biblio::CiteStyle currentStyle); /// last used citation style int style_; Index: src/frontends/qt4/GuiCitation.cpp =================================================================== --- src/frontends/qt4/GuiCitation.cpp (Revision 22130) +++ src/frontends/qt4/GuiCitation.cpp (Arbeitskopie) @@ -82,7 +82,7 @@ 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 @@ // 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::updateStyle() +void GuiCitation::updateFormatting(biblio::CiteStyle currentStyle) { biblio::CiteEngine const engine = getEngine(); bool const natbib_engine = @@ -222,15 +222,22 @@ 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 @@ 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 @@ 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_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::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 @@ 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; } Index: src/tex2lyx/text.cpp =================================================================== --- src/tex2lyx/text.cpp (Revision 22130) +++ src/tex2lyx/text.cpp (Arbeitskopie) @@ -86,7 +86,7 @@ } -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 }; Index: src/Buffer.cpp =================================================================== --- src/Buffer.cpp (Revision 22130) +++ src/Buffer.cpp (Arbeitskopie) @@ -116,7 +116,7 @@ namespace { -int const LYX_FORMAT = 307; // JSpitzm: support for \slash +int const LYX_FORMAT = 308; // Bernhard Reiter: support for \nocite } // namespace anon Index: lib/lyx2lyx/LyX.py =================================================================== --- lib/lyx2lyx/LyX.py (Revision 22130) +++ lib/lyx2lyx/LyX.py (Arbeitskopie) @@ -80,7 +80,7 @@ ("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,308), minor_versions("1.6" , 0))] + ("1_6", range(277,309), minor_versions("1.6" , 0))] def formats_list(): Index: lib/lyx2lyx/lyx_1_6.py =================================================================== --- lib/lyx2lyx/lyx_1_6.py (Revision 22130) +++ lib/lyx2lyx/lyx_1_6.py (Arbeitskopie) @@ -945,6 +945,38 @@ 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 + 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 @@ -1014,10 +1046,12 @@ [304, [convert_framed_notes]], [305, []], [306, []], - [307, []] + [307, []], + [308, []] ] -revert = [[306, [revert_slash, revert_nobreakdash]], +revert = [[307, [revert_nocite]], + [306, [revert_slash, revert_nobreakdash]], [305, [revert_interlingua]], [304, [revert_bahasam]], [303, [revert_framed_notes]], Index: development/FORMAT =================================================================== --- development/FORMAT (Revision 22130) +++ development/FORMAT (Arbeitskopie) @@ -1,6 +1,9 @@ LyX file-format changes ----------------------- +2007-12-11 Bernhard Reiter <[EMAIL PROTECTED]> + * Format incremented to 308: support for \nocite + 2007-12-05 Jürgen Spitzmüller <[EMAIL PROTECTED]> * Format incremented to 307: support for \slash and \nobreakdash.