mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-27 22:41:09 +00:00
Improve the display of BibTeX info in InsetCitation by retrieving missing
fields from the crossref. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28193 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
bb24f02188
commit
32950f6c6c
@ -72,6 +72,16 @@ docstring const & BibTeXInfo::operator[](string const & field) const
|
||||
}
|
||||
|
||||
|
||||
docstring BibTeXInfo::getValueForKey(string const & key,
|
||||
BibTeXInfo const * const xref) const
|
||||
{
|
||||
docstring const ret = operator[](key);
|
||||
if (!ret.empty() or !xref)
|
||||
return ret;
|
||||
return (*xref)[key];
|
||||
}
|
||||
|
||||
|
||||
docstring familyName(docstring const & name)
|
||||
{
|
||||
if (name.empty())
|
||||
@ -174,6 +184,14 @@ docstring const BibTeXInfo::getYear() const
|
||||
}
|
||||
|
||||
|
||||
docstring const BibTeXInfo::getXRef() const
|
||||
{
|
||||
if (!is_bibtex_)
|
||||
return docstring();
|
||||
return operator[]("crossref");
|
||||
}
|
||||
|
||||
|
||||
namespace {
|
||||
|
||||
docstring convertLaTeXCommands(docstring const & str)
|
||||
@ -274,7 +292,7 @@ namespace {
|
||||
} // anon namespace
|
||||
|
||||
|
||||
docstring const BibTeXInfo::getInfo() const
|
||||
docstring const BibTeXInfo::getInfo(BibTeXInfo const * const xref) const
|
||||
{
|
||||
if (!info_.empty())
|
||||
return info_;
|
||||
@ -290,31 +308,31 @@ docstring const BibTeXInfo::getInfo() const
|
||||
// field to customize the output based upon entry type.
|
||||
|
||||
// Search for all possible "required" fields
|
||||
docstring author = operator[]("author");
|
||||
docstring author = getValueForKey("author", xref);
|
||||
if (author.empty())
|
||||
author = operator[]("editor");
|
||||
author = getValueForKey("editor", xref);
|
||||
|
||||
docstring year = operator[]("year");
|
||||
docstring title = operator[]("title");
|
||||
docstring docLoc = operator[]("pages");
|
||||
docstring year = getValueForKey("year", xref);
|
||||
docstring title = getValueForKey("title", xref);
|
||||
docstring docLoc = getValueForKey("pages", xref);
|
||||
if (docLoc.empty()) {
|
||||
docLoc = operator[]("chapter");
|
||||
docLoc = getValueForKey("chapter", xref);
|
||||
if (!docLoc.empty())
|
||||
docLoc = from_ascii("Ch. ") + docLoc;
|
||||
} else {
|
||||
docLoc = from_ascii("pp. ") + docLoc;
|
||||
}
|
||||
|
||||
docstring media = operator[]("journal");
|
||||
docstring media = getValueForKey("journal", xref);
|
||||
if (media.empty()) {
|
||||
media = operator[]("publisher");
|
||||
media = getValueForKey("publisher", xref);
|
||||
if (media.empty()) {
|
||||
media = operator[]("school");
|
||||
media = getValueForKey("school", xref);
|
||||
if (media.empty())
|
||||
media = operator[]("institution");
|
||||
media = getValueForKey("institution");
|
||||
}
|
||||
}
|
||||
docstring volume = operator[]("volume");
|
||||
docstring volume = getValueForKey("volume", xref);
|
||||
|
||||
odocstringstream result;
|
||||
if (!author.empty())
|
||||
@ -324,7 +342,7 @@ docstring const BibTeXInfo::getInfo() const
|
||||
if (!media.empty())
|
||||
result << ", " << media;
|
||||
if (!year.empty())
|
||||
result << ", " << year;
|
||||
result << " (" << year << ")";
|
||||
if (!docLoc.empty())
|
||||
result << ", " << docLoc;
|
||||
|
||||
@ -408,6 +426,18 @@ docstring const BiblioInfo::getYear(docstring const & key) const
|
||||
if (it == end())
|
||||
return docstring();
|
||||
BibTeXInfo const & data = it->second;
|
||||
docstring year = data.getYear();
|
||||
if (!year.empty())
|
||||
return year;
|
||||
// let's try the crossref
|
||||
docstring const xref = data.getXRef();
|
||||
if (xref.empty())
|
||||
return year; // no luck
|
||||
BiblioInfo::const_iterator const xrefit = find(xref);
|
||||
if (xrefit == end())
|
||||
return year; // no luck again
|
||||
BibTeXInfo const & xref_data = xrefit->second;
|
||||
return xref_data.getYear();
|
||||
return data.getYear();
|
||||
}
|
||||
|
||||
@ -418,7 +448,14 @@ docstring const BiblioInfo::getInfo(docstring const & key) const
|
||||
if (it == end())
|
||||
return docstring();
|
||||
BibTeXInfo const & data = it->second;
|
||||
return data.getInfo();
|
||||
BibTeXInfo const * xrefptr = 0;
|
||||
docstring const xref = data.getXRef();
|
||||
if (!xref.empty()) {
|
||||
BiblioInfo::const_iterator const xrefit = find(xref);
|
||||
if (xrefit != end())
|
||||
xrefptr = &(xrefit->second);
|
||||
}
|
||||
return data.getInfo(xrefptr);
|
||||
}
|
||||
|
||||
|
||||
|
@ -59,8 +59,11 @@ public:
|
||||
docstring const getAbbreviatedAuthor() const;
|
||||
///
|
||||
docstring const getYear() const;
|
||||
///
|
||||
docstring const getXRef() const;
|
||||
/// \return formatted BibTeX data suitable for framing.
|
||||
docstring const getInfo() const;
|
||||
/// \param pointer to crossref information
|
||||
docstring const getInfo(BibTeXInfo const * const xref = 0) const;
|
||||
///
|
||||
int count(docstring const & f) const { return bimap_.count(f); }
|
||||
///
|
||||
@ -84,6 +87,9 @@ public:
|
||||
///
|
||||
docstring entryType() const { return entry_type_; }
|
||||
private:
|
||||
/// like operator[], except it will also check the given xref
|
||||
docstring getValueForKey(std::string const & key,
|
||||
BibTeXInfo const * const xref = 0) const;
|
||||
/// true if from BibTeX; false if from bibliography environment
|
||||
bool is_bibtex_;
|
||||
/// the BibTeX key for this entry
|
||||
@ -114,9 +120,12 @@ public:
|
||||
/// \return the short form of an authorlist
|
||||
docstring const getAbbreviatedAuthor(docstring const & key) const;
|
||||
/// \return the year from the bibtex data record
|
||||
/// Note that this will get the year from the crossref if it's
|
||||
/// not present in the record itself
|
||||
docstring const getYear(docstring const & key) const;
|
||||
/// \return formatted BibTeX data associated with a given key.
|
||||
/// Empty if no info exists.
|
||||
/// Note that this will retrieve data from the crossref as needed.
|
||||
docstring const getInfo(docstring const & key) const;
|
||||
/**
|
||||
* "Translates" the available Citation Styles into strings for a given key,
|
||||
|
Loading…
Reference in New Issue
Block a user