2002-04-24 10:00:39 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetcite.C
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2000-07-07 07:46:37 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* \author Angus Leeming
|
2003-09-07 01:45:40 +00:00
|
|
|
|
* \author Herbert Vo<EFBFBD>
|
2002-09-25 14:26:13 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-04-24 10:00:39 +00:00
|
|
|
|
*/
|
2000-06-07 08:53:40 +00:00
|
|
|
|
|
2000-07-07 07:46:37 +00:00
|
|
|
|
#include <config.h>
|
2000-06-07 08:53:40 +00:00
|
|
|
|
|
|
|
|
|
#include "insetcite.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
2001-07-19 14:12:37 +00:00
|
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2006-08-18 16:03:48 +00:00
|
|
|
|
#include "debug.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
#include "funcrequest.h"
|
2001-07-19 14:12:37 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
2004-05-14 13:13:20 +00:00
|
|
|
|
#include "frontends/controllers/biblio.h"
|
|
|
|
|
|
2006-08-19 10:39:03 +00:00
|
|
|
|
#include "support/fs_extras.h"
|
2000-07-19 08:37:26 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2000-07-15 23:51:46 +00:00
|
|
|
|
|
2006-10-09 14:21:11 +00:00
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
2006-04-15 11:46:17 +00:00
|
|
|
|
#include <boost/filesystem/operations.hpp>
|
2006-08-31 19:32:12 +00:00
|
|
|
|
#include <boost/filesystem/exception.hpp>
|
2006-04-15 11:46:17 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
using support::ascii_lowercase;
|
|
|
|
|
using support::contains;
|
2006-12-01 20:09:08 +00:00
|
|
|
|
using support::FileName;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
using support::getStringFromVector;
|
|
|
|
|
using support::getVectorFromString;
|
|
|
|
|
using support::ltrim;
|
|
|
|
|
using support::rtrim;
|
|
|
|
|
using support::split;
|
|
|
|
|
using support::tokenPos;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2006-08-18 16:03:48 +00:00
|
|
|
|
using std::endl;
|
2006-10-09 14:21:11 +00:00
|
|
|
|
using std::replace;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::ostream;
|
2002-04-24 10:00:39 +00:00
|
|
|
|
using std::vector;
|
|
|
|
|
using std::map;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
2006-04-15 11:46:17 +00:00
|
|
|
|
namespace fs = boost::filesystem;
|
2004-05-19 15:11:37 +00:00
|
|
|
|
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
2002-04-24 10:00:39 +00:00
|
|
|
|
namespace {
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
string const getNatbibLabel(Buffer const & buffer,
|
2002-04-24 10:00:39 +00:00
|
|
|
|
string const & citeType, string const & keyList,
|
|
|
|
|
string const & before, string const & after,
|
2004-05-13 20:44:35 +00:00
|
|
|
|
biblio::CiteEngine engine)
|
2000-06-07 08:53:40 +00:00
|
|
|
|
{
|
2003-10-22 13:15:18 +00:00
|
|
|
|
// Only start the process off after the buffer is loaded from file.
|
|
|
|
|
if (!buffer.fully_loaded())
|
|
|
|
|
return string();
|
|
|
|
|
|
2006-04-15 11:46:17 +00:00
|
|
|
|
// Cache the labels
|
2002-04-24 10:00:39 +00:00
|
|
|
|
typedef std::map<Buffer const *, biblio::InfoMap> CachedMap;
|
|
|
|
|
static CachedMap cached_keys;
|
|
|
|
|
|
2006-04-15 11:46:17 +00:00
|
|
|
|
// and cache the timestamp of the bibliography files.
|
2006-12-01 20:09:08 +00:00
|
|
|
|
static std::map<FileName, time_t> bibfileStatus;
|
2002-04-24 10:00:39 +00:00
|
|
|
|
|
2003-10-22 13:15:18 +00:00
|
|
|
|
biblio::InfoMap infomap;
|
2006-04-15 11:46:17 +00:00
|
|
|
|
|
2006-12-01 20:09:08 +00:00
|
|
|
|
vector<FileName> const & bibfilesCache = buffer.getBibfilesCache();
|
2006-04-15 11:46:17 +00:00
|
|
|
|
// compare the cached timestamps with the actual ones.
|
|
|
|
|
bool changed = false;
|
2006-12-01 20:09:08 +00:00
|
|
|
|
for (vector<FileName>::const_iterator it = bibfilesCache.begin();
|
2006-04-15 11:46:17 +00:00
|
|
|
|
it != bibfilesCache.end(); ++ it) {
|
2006-12-01 20:09:08 +00:00
|
|
|
|
FileName const f = *it;
|
2006-08-31 19:32:12 +00:00
|
|
|
|
try {
|
2006-12-01 20:09:08 +00:00
|
|
|
|
std::time_t lastw = fs::last_write_time(f.toFilesystemEncoding());
|
2006-08-31 19:32:12 +00:00
|
|
|
|
if (lastw != bibfileStatus[f]) {
|
|
|
|
|
changed = true;
|
|
|
|
|
bibfileStatus[f] = lastw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (fs::filesystem_error & fserr) {
|
2006-04-15 11:46:17 +00:00
|
|
|
|
changed = true;
|
2006-08-31 19:32:12 +00:00
|
|
|
|
lyxerr << "Couldn't find or read bibtex file "
|
|
|
|
|
<< f << endl;
|
|
|
|
|
lyxerr[Debug::DEBUG] << "Fs error: "
|
|
|
|
|
<< fserr.what() << endl;
|
2006-04-15 11:46:17 +00:00
|
|
|
|
}
|
2002-04-24 10:00:39 +00:00
|
|
|
|
}
|
2006-04-15 11:46:17 +00:00
|
|
|
|
|
|
|
|
|
// build the keylist only if the bibfiles have been changed
|
|
|
|
|
if (cached_keys.empty() || bibfileStatus.empty() || changed) {
|
|
|
|
|
typedef vector<std::pair<string, string> > InfoType;
|
|
|
|
|
InfoType bibkeys;
|
|
|
|
|
buffer.fillWithBibKeys(bibkeys);
|
|
|
|
|
|
|
|
|
|
InfoType::const_iterator bit = bibkeys.begin();
|
|
|
|
|
InfoType::const_iterator bend = bibkeys.end();
|
|
|
|
|
|
|
|
|
|
for (; bit != bend; ++bit)
|
|
|
|
|
infomap[bit->first] = bit->second;
|
|
|
|
|
|
|
|
|
|
cached_keys[&buffer] = infomap;
|
|
|
|
|
} else
|
|
|
|
|
// use the cached keys
|
|
|
|
|
infomap = cached_keys[&buffer];
|
|
|
|
|
|
2003-10-22 13:15:18 +00:00
|
|
|
|
if (infomap.empty())
|
|
|
|
|
return string();
|
2002-07-28 18:13:51 +00:00
|
|
|
|
|
2002-04-24 10:00:39 +00:00
|
|
|
|
// the natbib citation-styles
|
|
|
|
|
// CITET: author (year)
|
|
|
|
|
// CITEP: (author,year)
|
|
|
|
|
// CITEALT: author year
|
|
|
|
|
// CITEALP: author, year
|
|
|
|
|
// CITEAUTHOR: author
|
|
|
|
|
// CITEYEAR: year
|
|
|
|
|
// CITEYEARPAR: (year)
|
2004-03-07 14:33:17 +00:00
|
|
|
|
// jurabib supports these plus
|
|
|
|
|
// CITE: author/<before field>
|
2002-04-24 10:00:39 +00:00
|
|
|
|
|
2002-05-14 09:47:12 +00:00
|
|
|
|
// We don't currently use the full or forceUCase fields.
|
2004-05-14 15:27:13 +00:00
|
|
|
|
string cite_type = biblio::asValidLatexCommand(citeType, engine);
|
|
|
|
|
if (cite_type[0] == 'C')
|
|
|
|
|
cite_type = string(1, 'c') + cite_type.substr(1);
|
|
|
|
|
if (cite_type[cite_type.size() - 1] == '*')
|
|
|
|
|
cite_type = cite_type.substr(0, cite_type.size() - 1);
|
2002-07-28 18:13:51 +00:00
|
|
|
|
|
2002-04-24 10:00:39 +00:00
|
|
|
|
string before_str;
|
|
|
|
|
if (!before.empty()) {
|
|
|
|
|
// In CITET and CITEALT mode, the "before" string is
|
|
|
|
|
// attached to the label associated with each and every key.
|
|
|
|
|
// In CITEP, CITEALP and CITEYEARPAR mode, it is attached
|
|
|
|
|
// to the front of the whole only.
|
|
|
|
|
// In other modes, it is not used at all.
|
2002-05-14 09:47:12 +00:00
|
|
|
|
if (cite_type == "citet" ||
|
|
|
|
|
cite_type == "citealt" ||
|
|
|
|
|
cite_type == "citep" ||
|
2002-07-28 18:13:51 +00:00
|
|
|
|
cite_type == "citealp" ||
|
2002-05-14 09:47:12 +00:00
|
|
|
|
cite_type == "citeyearpar")
|
2002-04-24 10:00:39 +00:00
|
|
|
|
before_str = before + ' ';
|
2004-03-07 14:33:17 +00:00
|
|
|
|
// In CITE (jurabib), the "before" string is used to attach
|
2004-04-03 08:37:12 +00:00
|
|
|
|
// the annotator (of legal texts) to the author(s) of the
|
|
|
|
|
// first reference.
|
2004-03-07 14:33:17 +00:00
|
|
|
|
else if (cite_type == "cite")
|
|
|
|
|
before_str = '/' + before;
|
2002-04-24 10:00:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string after_str;
|
|
|
|
|
if (!after.empty()) {
|
|
|
|
|
// The "after" key is appended only to the end of the whole.
|
|
|
|
|
after_str = ", " + after;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// One day, these might be tunable (as they are in BibTeX).
|
|
|
|
|
char const op = '('; // opening parenthesis.
|
|
|
|
|
char const cp = ')'; // closing parenthesis.
|
2002-07-28 18:13:51 +00:00
|
|
|
|
// puctuation mark separating citation entries.
|
|
|
|
|
char const * const sep = ";";
|
2002-04-24 10:00:39 +00:00
|
|
|
|
|
2002-11-27 10:30:28 +00:00
|
|
|
|
string const op_str(' ' + string(1, op));
|
|
|
|
|
string const cp_str(string(1, cp) + ' ');
|
|
|
|
|
string const sep_str(string(sep) + ' ');
|
2000-07-19 08:37:26 +00:00
|
|
|
|
|
|
|
|
|
string label;
|
2002-04-24 10:00:39 +00:00
|
|
|
|
vector<string> keys = getVectorFromString(keyList);
|
|
|
|
|
vector<string>::const_iterator it = keys.begin();
|
|
|
|
|
vector<string>::const_iterator end = keys.end();
|
2002-07-28 18:13:51 +00:00
|
|
|
|
for (; it != end; ++it) {
|
2002-04-24 10:00:39 +00:00
|
|
|
|
// get the bibdata corresponding to the key
|
|
|
|
|
string const author(biblio::getAbbreviatedAuthor(infomap, *it));
|
|
|
|
|
string const year(biblio::getYear(infomap, *it));
|
|
|
|
|
|
|
|
|
|
// Something isn't right. Fail safely.
|
|
|
|
|
if (author.empty() || year.empty())
|
|
|
|
|
return string();
|
|
|
|
|
|
2004-03-07 14:33:17 +00:00
|
|
|
|
// authors1/<before>; ... ;
|
|
|
|
|
// authors_last, <after>
|
2004-05-13 20:44:35 +00:00
|
|
|
|
if (cite_type == "cite" && engine == biblio::ENGINE_JURABIB) {
|
2004-03-07 14:33:17 +00:00
|
|
|
|
if (it == keys.begin())
|
|
|
|
|
label += author + before_str + sep_str;
|
|
|
|
|
else
|
|
|
|
|
label += author + sep_str;
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2002-04-24 10:00:39 +00:00
|
|
|
|
// (authors1 (<before> year); ... ;
|
|
|
|
|
// authors_last (<before> year, <after>)
|
2004-03-07 14:33:17 +00:00
|
|
|
|
} else if (cite_type == "citet") {
|
2004-05-13 20:44:35 +00:00
|
|
|
|
switch (engine) {
|
|
|
|
|
case biblio::ENGINE_NATBIB_AUTHORYEAR:
|
|
|
|
|
label += author + op_str + before_str +
|
|
|
|
|
year + cp + sep_str;
|
|
|
|
|
break;
|
|
|
|
|
case biblio::ENGINE_NATBIB_NUMERICAL:
|
|
|
|
|
label += author + op_str + before_str +
|
|
|
|
|
'#' + *it + cp + sep_str;
|
|
|
|
|
break;
|
|
|
|
|
case biblio::ENGINE_JURABIB:
|
|
|
|
|
label += before_str + author + op_str +
|
|
|
|
|
year + cp + sep_str;
|
|
|
|
|
break;
|
|
|
|
|
case biblio::ENGINE_BASIC:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-04-24 10:00:39 +00:00
|
|
|
|
|
|
|
|
|
// author, year; author, year; ...
|
2002-05-14 09:47:12 +00:00
|
|
|
|
} else if (cite_type == "citep" ||
|
|
|
|
|
cite_type == "citealp") {
|
2004-05-13 20:44:35 +00:00
|
|
|
|
if (engine == biblio::ENGINE_NATBIB_NUMERICAL) {
|
2002-04-24 10:00:39 +00:00
|
|
|
|
label += *it + sep_str;
|
|
|
|
|
} else {
|
|
|
|
|
label += author + ", " + year + sep_str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// (authors1 <before> year;
|
|
|
|
|
// authors_last <before> year, <after>)
|
2002-05-14 09:47:12 +00:00
|
|
|
|
} else if (cite_type == "citealt") {
|
2004-05-13 20:44:35 +00:00
|
|
|
|
switch (engine) {
|
|
|
|
|
case biblio::ENGINE_NATBIB_AUTHORYEAR:
|
|
|
|
|
label += author + ' ' + before_str +
|
|
|
|
|
year + sep_str;
|
|
|
|
|
break;
|
|
|
|
|
case biblio::ENGINE_NATBIB_NUMERICAL:
|
|
|
|
|
label += author + ' ' + before_str +
|
|
|
|
|
'#' + *it + sep_str;
|
|
|
|
|
break;
|
|
|
|
|
case biblio::ENGINE_JURABIB:
|
|
|
|
|
label += before_str + author + ' ' +
|
|
|
|
|
year + sep_str;
|
|
|
|
|
break;
|
|
|
|
|
case biblio::ENGINE_BASIC:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2002-04-24 10:00:39 +00:00
|
|
|
|
|
|
|
|
|
// author; author; ...
|
2002-05-14 09:47:12 +00:00
|
|
|
|
} else if (cite_type == "citeauthor") {
|
2002-04-24 10:00:39 +00:00
|
|
|
|
label += author + sep_str;
|
|
|
|
|
|
|
|
|
|
// year; year; ...
|
2002-05-14 09:47:12 +00:00
|
|
|
|
} else if (cite_type == "citeyear" ||
|
|
|
|
|
cite_type == "citeyearpar") {
|
2002-04-24 10:00:39 +00:00
|
|
|
|
label += year + sep_str;
|
|
|
|
|
}
|
|
|
|
|
}
|
2002-07-28 22:50:13 +00:00
|
|
|
|
label = rtrim(rtrim(label), sep);
|
2002-04-24 10:00:39 +00:00
|
|
|
|
|
|
|
|
|
if (!after_str.empty()) {
|
2002-05-14 09:47:12 +00:00
|
|
|
|
if (cite_type == "citet") {
|
2002-04-24 10:00:39 +00:00
|
|
|
|
// insert "after" before last ')'
|
2002-07-28 18:13:51 +00:00
|
|
|
|
label.insert(label.size() - 1, after_str);
|
2002-04-24 10:00:39 +00:00
|
|
|
|
} else {
|
2004-05-13 20:44:35 +00:00
|
|
|
|
bool const add =
|
|
|
|
|
!(engine == biblio::ENGINE_NATBIB_NUMERICAL &&
|
|
|
|
|
(cite_type == "citeauthor" ||
|
|
|
|
|
cite_type == "citeyear"));
|
2002-04-24 10:00:39 +00:00
|
|
|
|
if (add)
|
|
|
|
|
label += after_str;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-14 09:47:12 +00:00
|
|
|
|
if (!before_str.empty() && (cite_type == "citep" ||
|
2002-07-28 18:13:51 +00:00
|
|
|
|
cite_type == "citealp" ||
|
2002-05-14 09:47:12 +00:00
|
|
|
|
cite_type == "citeyearpar")) {
|
2002-04-24 10:00:39 +00:00
|
|
|
|
label = before_str + label;
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-14 09:47:12 +00:00
|
|
|
|
if (cite_type == "citep" || cite_type == "citeyearpar")
|
2002-04-24 10:00:39 +00:00
|
|
|
|
label = string(1, op) + label + string(1, cp);
|
|
|
|
|
|
|
|
|
|
return label;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const getBasicLabel(string const & keyList, string const & after)
|
|
|
|
|
{
|
|
|
|
|
string keys(keyList);
|
|
|
|
|
string label;
|
|
|
|
|
|
2004-02-01 12:46:14 +00:00
|
|
|
|
if (contains(keys, ',')) {
|
2000-07-19 08:37:26 +00:00
|
|
|
|
// Final comma allows while loop to cover all keys
|
2002-11-27 10:30:28 +00:00
|
|
|
|
keys = ltrim(split(keys, label, ',')) + ',';
|
2004-02-01 12:46:14 +00:00
|
|
|
|
while (contains(keys, ',')) {
|
2000-07-19 08:37:26 +00:00
|
|
|
|
string key;
|
2002-07-28 22:50:13 +00:00
|
|
|
|
keys = ltrim(split(keys, key, ','));
|
2000-07-19 08:37:26 +00:00
|
|
|
|
label += ", " + key;
|
|
|
|
|
}
|
2002-04-24 10:00:39 +00:00
|
|
|
|
} else
|
2000-07-19 08:37:26 +00:00
|
|
|
|
label = keys;
|
2002-04-24 10:00:39 +00:00
|
|
|
|
|
|
|
|
|
if (!after.empty())
|
|
|
|
|
label += ", " + after;
|
2002-07-28 18:13:51 +00:00
|
|
|
|
|
2002-11-27 10:30:28 +00:00
|
|
|
|
return '[' + label + ']';
|
2002-04-24 10:00:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
|
|
|
2003-05-26 09:13:55 +00:00
|
|
|
|
InsetCitation::InsetCitation(InsetCommandParams const & p)
|
2003-12-11 15:23:15 +00:00
|
|
|
|
: InsetCommand(p, "citation")
|
2002-04-24 10:00:39 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
docstring const InsetCitation::generateLabel(Buffer const & buffer) const
|
2002-04-24 10:00:39 +00:00
|
|
|
|
{
|
2004-03-05 14:49:10 +00:00
|
|
|
|
string const before = getSecOptions();
|
2002-04-24 10:00:39 +00:00
|
|
|
|
string const after = getOptions();
|
|
|
|
|
|
|
|
|
|
string label;
|
2004-05-13 20:44:35 +00:00
|
|
|
|
biblio::CiteEngine const engine = buffer.params().cite_engine;
|
|
|
|
|
if (engine != biblio::ENGINE_BASIC) {
|
2004-05-14 15:27:13 +00:00
|
|
|
|
label = getNatbibLabel(buffer, getCmdName(), getContents(),
|
2004-05-13 20:44:35 +00:00
|
|
|
|
before, after, engine);
|
2000-06-07 08:53:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-04-24 10:00:39 +00:00
|
|
|
|
// Fallback to fail-safe
|
|
|
|
|
if (label.empty()) {
|
|
|
|
|
label = getBasicLabel(getContents(), after);
|
|
|
|
|
}
|
2000-07-19 08:37:26 +00:00
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-10-21 00:16:43 +00:00
|
|
|
|
return from_utf8(label);
|
2002-04-24 10:00:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
docstring const InsetCitation::getScreenLabel(Buffer const & buffer) const
|
2002-04-24 10:00:39 +00:00
|
|
|
|
{
|
2004-05-10 20:55:00 +00:00
|
|
|
|
biblio::CiteEngine const engine = biblio::getEngine(buffer);
|
|
|
|
|
if (cache.params == params() && cache.engine == engine)
|
2002-04-24 10:00:39 +00:00
|
|
|
|
return cache.screen_label;
|
|
|
|
|
|
|
|
|
|
// The label has changed, so we have to re-create it.
|
2004-03-05 14:49:10 +00:00
|
|
|
|
string const before = getSecOptions();
|
2002-04-24 10:00:39 +00:00
|
|
|
|
string const after = getOptions();
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
docstring const glabel = generateLabel(buffer);
|
2002-04-24 10:00:39 +00:00
|
|
|
|
|
|
|
|
|
unsigned int const maxLabelChars = 45;
|
|
|
|
|
|
2006-10-11 19:40:50 +00:00
|
|
|
|
docstring label = glabel;
|
2002-04-24 10:00:39 +00:00
|
|
|
|
if (label.size() > maxLabelChars) {
|
|
|
|
|
label.erase(maxLabelChars-3);
|
|
|
|
|
label += "...";
|
|
|
|
|
}
|
|
|
|
|
|
2004-05-10 20:55:00 +00:00
|
|
|
|
cache.engine = engine;
|
2002-04-24 10:00:39 +00:00
|
|
|
|
cache.params = params();
|
|
|
|
|
cache.generated_label = glabel;
|
|
|
|
|
cache.screen_label = label;
|
|
|
|
|
|
|
|
|
|
return label;
|
2000-06-07 08:53:40 +00:00
|
|
|
|
}
|
2000-07-14 07:52:03 +00:00
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetCitation::plaintext(Buffer const & buffer, odocstream & os,
|
2006-10-11 19:40:50 +00:00
|
|
|
|
OutputParams const &) const
|
2001-05-27 17:51:16 +00:00
|
|
|
|
{
|
2004-05-10 20:55:00 +00:00
|
|
|
|
if (cache.params == params() &&
|
|
|
|
|
cache.engine == biblio::getEngine(buffer))
|
2003-06-30 09:10:49 +00:00
|
|
|
|
os << cache.generated_label;
|
2002-04-24 10:00:39 +00:00
|
|
|
|
else
|
2003-06-30 09:10:49 +00:00
|
|
|
|
os << generateLabel(buffer);
|
2002-03-21 17:09:55 +00:00
|
|
|
|
return 0;
|
2001-05-27 17:51:16 +00:00
|
|
|
|
}
|
2001-07-19 14:12:37 +00:00
|
|
|
|
|
2002-04-24 10:00:39 +00:00
|
|
|
|
|
2004-10-21 22:39:20 +00:00
|
|
|
|
namespace {
|
2004-10-26 21:16:44 +00:00
|
|
|
|
|
2004-10-21 22:39:20 +00:00
|
|
|
|
string const cleanupWhitespace(string const & citelist)
|
|
|
|
|
{
|
|
|
|
|
string::const_iterator it = citelist.begin();
|
|
|
|
|
string::const_iterator end = citelist.end();
|
|
|
|
|
// Paranoia check: make sure that there is no whitespace in here
|
|
|
|
|
// -- at least not behind commas or at the beginning
|
|
|
|
|
string result;
|
|
|
|
|
char last = ',';
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
if (*it != ' ')
|
|
|
|
|
last = *it;
|
|
|
|
|
if (*it != ' ' || last != ',')
|
|
|
|
|
result += *it;
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// end anon namyspace
|
|
|
|
|
}
|
|
|
|
|
|
2006-10-19 21:00:33 +00:00
|
|
|
|
int InsetCitation::docbook(Buffer const &, odocstream & os, OutputParams const &) const
|
2004-10-21 22:39:20 +00:00
|
|
|
|
{
|
2006-10-19 21:00:33 +00:00
|
|
|
|
os << "<citation>"
|
2006-10-21 00:16:43 +00:00
|
|
|
|
<< from_ascii(cleanupWhitespace(getContents()))
|
2006-10-19 21:00:33 +00:00
|
|
|
|
<< "</citation>";
|
2004-10-21 22:39:20 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetCitation::textString(Buffer const & buf, odocstream & os,
|
2005-11-25 14:40:34 +00:00
|
|
|
|
OutputParams const & op) const
|
|
|
|
|
{
|
|
|
|
|
return plaintext(buf, os, op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-19 14:12:37 +00:00
|
|
|
|
// Have to overwrite the default InsetCommand method in order to check that
|
|
|
|
|
// the \cite command is valid. Eg, the user has natbib enabled, inputs some
|
|
|
|
|
// citations and then changes his mind, turning natbib support off. The output
|
|
|
|
|
// should revert to \cite[]{}
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetCitation::latex(Buffer const & buffer, odocstream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const &) const
|
2001-07-19 14:12:37 +00:00
|
|
|
|
{
|
2004-05-13 20:44:35 +00:00
|
|
|
|
biblio::CiteEngine const cite_engine = buffer.params().cite_engine;
|
2006-10-19 16:51:30 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-10-21 00:16:43 +00:00
|
|
|
|
docstring const cite_str = from_utf8(
|
2006-10-19 16:51:30 +00:00
|
|
|
|
biblio::asValidLatexCommand(getCmdName(), cite_engine));
|
2004-10-05 10:11:42 +00:00
|
|
|
|
|
2004-05-14 15:27:13 +00:00
|
|
|
|
os << "\\" << cite_str;
|
2004-10-05 10:11:42 +00:00
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
docstring const & before = getParam("before");
|
|
|
|
|
docstring const & after = getParam("after");
|
2004-05-13 20:44:35 +00:00
|
|
|
|
if (!before.empty() && cite_engine != biblio::ENGINE_BASIC)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '[' << before << "][" << after << ']';
|
2002-04-24 10:00:39 +00:00
|
|
|
|
else if (!after.empty())
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '[' << after << ']';
|
2004-03-05 14:49:10 +00:00
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
// FIXME UNICODE
|
2006-10-21 00:16:43 +00:00
|
|
|
|
os << '{' << from_utf8(cleanupWhitespace(getContents())) << '}';
|
2001-07-19 14:12:37 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCitation::validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
2004-05-13 20:44:35 +00:00
|
|
|
|
switch (features.bufferParams().cite_engine) {
|
|
|
|
|
case biblio::ENGINE_BASIC:
|
|
|
|
|
break;
|
|
|
|
|
case biblio::ENGINE_NATBIB_AUTHORYEAR:
|
|
|
|
|
case biblio::ENGINE_NATBIB_NUMERICAL:
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.require("natbib");
|
2004-05-13 20:44:35 +00:00
|
|
|
|
break;
|
|
|
|
|
case biblio::ENGINE_JURABIB:
|
2004-03-07 14:33:17 +00:00
|
|
|
|
features.require("jurabib");
|
2004-05-13 20:44:35 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2001-07-19 14:12:37 +00:00
|
|
|
|
}
|
2006-10-09 14:21:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetCitation::replaceContents(string const & from, string const & to)
|
|
|
|
|
{
|
|
|
|
|
if (tokenPos(getContents(), ',', from) != -1) {
|
|
|
|
|
vector<string> items = getVectorFromString(getContents());
|
|
|
|
|
replace(items.begin(), items.end(), from, to);
|
|
|
|
|
setContents(getStringFromVector(items));
|
|
|
|
|
}
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|