2002-04-24 10:00:39 +00:00
|
|
|
/**
|
2007-04-25 16:11:45 +00:00
|
|
|
* \file InsetCitation.cpp
|
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
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Herbert Voß
|
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
|
|
|
|
2007-04-25 16:11:45 +00:00
|
|
|
#include "InsetCitation.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2010-10-31 00:31:57 +00:00
|
|
|
#include "BiblioInfo.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
2008-03-10 15:01:57 +00:00
|
|
|
#include "buffer_funcs.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "BufferParams.h"
|
2009-03-25 12:23:43 +00:00
|
|
|
#include "BufferView.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DispatchResult.h"
|
2011-05-07 23:02:53 +00:00
|
|
|
#include "FuncCode.h"
|
|
|
|
#include "FuncRequest.h"
|
2001-07-19 14:12:37 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2009-11-30 22:59:18 +00:00
|
|
|
#include "output_xhtml.h"
|
2008-03-04 17:47:47 +00:00
|
|
|
#include "ParIterator.h"
|
|
|
|
#include "TocBackend.h"
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2007-11-28 22:12:03 +00:00
|
|
|
#include "support/docstream.h"
|
2008-04-19 15:52:35 +00:00
|
|
|
#include "support/FileNameList.h"
|
2008-03-04 17:47:47 +00:00
|
|
|
#include "support/gettext.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/lstrings.h"
|
2000-07-15 23:51:46 +00:00
|
|
|
|
2006-10-09 14:21:11 +00:00
|
|
|
#include <algorithm>
|
2014-05-23 14:59:12 +00:00
|
|
|
#include <climits>
|
2006-10-09 14:21:11 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-12-12 18:57:56 +00:00
|
|
|
using namespace lyx::support;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
2010-01-09 22:30:56 +00:00
|
|
|
ParamInfo InsetCitation::param_info_;
|
|
|
|
|
|
|
|
|
|
|
|
InsetCitation::InsetCitation(Buffer * buf, InsetCommandParams const & p)
|
2010-10-29 00:46:21 +00:00
|
|
|
: InsetCommand(buf, p)
|
2013-01-12 00:04:07 +00:00
|
|
|
{
|
|
|
|
buffer().removeBiblioTempFiles();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetCitation::~InsetCitation()
|
|
|
|
{
|
|
|
|
if (isBufferLoaded())
|
|
|
|
buffer().removeBiblioTempFiles();
|
|
|
|
}
|
2010-01-09 22:30:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
ParamInfo const & InsetCitation::findInfo(string const & /* cmdName */)
|
|
|
|
{
|
|
|
|
// standard cite does only take one argument if jurabib is
|
|
|
|
// not used, but jurabib extends this to two arguments, so
|
|
|
|
// we have to allow both here. InsetCitation takes care that
|
|
|
|
// LaTeX output is nevertheless correct.
|
|
|
|
if (param_info_.empty()) {
|
|
|
|
param_info_.add("after", ParamInfo::LATEX_OPTIONAL);
|
|
|
|
param_info_.add("before", ParamInfo::LATEX_OPTIONAL);
|
|
|
|
param_info_.add("key", ParamInfo::LATEX_REQUIRED);
|
|
|
|
}
|
|
|
|
return param_info_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-04-24 10:00:39 +00:00
|
|
|
namespace {
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
vector<string> const init_possible_cite_commands()
|
|
|
|
{
|
2007-09-11 22:31:24 +00:00
|
|
|
char const * const possible[] = {
|
2007-12-20 15:46:14 +00:00
|
|
|
"cite", "nocite", "citet", "citep", "citealt", "citealp",
|
2007-08-20 16:30:02 +00:00
|
|
|
"citeauthor", "citeyear", "citeyearpar",
|
|
|
|
"citet*", "citep*", "citealt*", "citealp*", "citeauthor*",
|
|
|
|
"Citet", "Citep", "Citealt", "Citealp", "Citeauthor",
|
|
|
|
"Citet*", "Citep*", "Citealt*", "Citealp*", "Citeauthor*",
|
|
|
|
"fullcite",
|
|
|
|
"footcite", "footcitet", "footcitep", "footcitealt",
|
|
|
|
"footcitealp", "footciteauthor", "footciteyear", "footciteyearpar",
|
|
|
|
"citefield", "citetitle", "cite*"
|
|
|
|
};
|
2007-09-11 22:31:24 +00:00
|
|
|
size_t const size_possible = sizeof(possible) / sizeof(possible[0]);
|
2007-08-20 16:30:02 +00:00
|
|
|
|
2007-09-11 22:31:24 +00:00
|
|
|
return vector<string>(possible, possible + size_possible);
|
2007-08-20 16:30:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-15 00:02:41 +00:00
|
|
|
vector<string> const & possibleCiteCommands()
|
2007-08-20 16:30:02 +00:00
|
|
|
{
|
2007-09-11 22:31:24 +00:00
|
|
|
static vector<string> const possible = init_possible_cite_commands();
|
|
|
|
return possible;
|
2007-08-20 16:30:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-09 22:30:56 +00:00
|
|
|
} // anon namespace
|
|
|
|
|
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
// FIXME: use the citeCommands provided by the TextClass
|
|
|
|
// instead of possibleCiteCommands defined in this file.
|
2010-01-09 22:30:56 +00:00
|
|
|
bool InsetCitation::isCompatibleCommand(string const & cmd)
|
|
|
|
{
|
|
|
|
vector<string> const & possibles = possibleCiteCommands();
|
|
|
|
vector<string>::const_iterator const end = possibles.end();
|
|
|
|
return find(possibles.begin(), end, cmd) != end;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-07 23:02:53 +00:00
|
|
|
void InsetCitation::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|
|
|
{
|
2013-01-12 00:04:07 +00:00
|
|
|
if (cmd.action() == LFUN_INSET_MODIFY) {
|
|
|
|
buffer().removeBiblioTempFiles();
|
2011-05-07 23:02:53 +00:00
|
|
|
cache.recalculate = true;
|
2013-01-12 00:04:07 +00:00
|
|
|
}
|
2011-05-07 23:02:53 +00:00
|
|
|
InsetCommand::doDispatch(cur, cmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-05 08:37:34 +00:00
|
|
|
bool InsetCitation::addKey(string const & key)
|
|
|
|
{
|
|
|
|
docstring const ukey = from_utf8(key);
|
|
|
|
docstring const & curkeys = getParam("key");
|
|
|
|
if (curkeys.empty()) {
|
|
|
|
setParam("key", ukey);
|
|
|
|
cache.recalculate = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<docstring> keys = getVectorFromString(curkeys);
|
|
|
|
vector<docstring>::const_iterator it = keys.begin();
|
|
|
|
vector<docstring>::const_iterator en = keys.end();
|
|
|
|
for (; it != en; ++it) {
|
|
|
|
if (*it == ukey) {
|
|
|
|
LYXERR0("Key " << key << " already present.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
keys.push_back(ukey);
|
|
|
|
setParam("key", getStringFromVector(keys));
|
|
|
|
cache.recalculate = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-09 22:30:56 +00:00
|
|
|
docstring InsetCitation::toolTip(BufferView const & bv, int, int) const
|
|
|
|
{
|
|
|
|
Buffer const & buf = bv.buffer();
|
|
|
|
// Only after the buffer is loaded from file...
|
|
|
|
if (!buf.isFullyLoaded())
|
|
|
|
return docstring();
|
|
|
|
|
|
|
|
BiblioInfo const & bi = buf.masterBibInfo();
|
|
|
|
if (bi.empty())
|
|
|
|
return _("No bibliography defined!");
|
|
|
|
|
|
|
|
docstring const & key = getParam("key");
|
|
|
|
if (key.empty())
|
|
|
|
return _("No citations selected!");
|
|
|
|
|
|
|
|
vector<docstring> keys = getVectorFromString(key);
|
|
|
|
vector<docstring>::const_iterator it = keys.begin();
|
|
|
|
vector<docstring>::const_iterator en = keys.end();
|
|
|
|
docstring tip;
|
|
|
|
for (; it != en; ++it) {
|
2010-03-29 18:37:25 +00:00
|
|
|
docstring const key_info = bi.getInfo(*it, buffer());
|
2010-01-09 22:30:56 +00:00
|
|
|
if (key_info.empty())
|
|
|
|
continue;
|
|
|
|
if (!tip.empty())
|
|
|
|
tip += "\n";
|
|
|
|
tip += wrap(key_info, -4);
|
|
|
|
}
|
|
|
|
return tip;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
2011-12-03 22:15:11 +00:00
|
|
|
|
2007-08-20 16:30:02 +00:00
|
|
|
|
2015-02-24 09:17:45 +00:00
|
|
|
CitationStyle asValidLatexCommand(string const & input, vector<CitationStyle> const & valid_styles)
|
2007-08-20 16:30:02 +00:00
|
|
|
{
|
2012-03-01 00:41:30 +00:00
|
|
|
CitationStyle cs = valid_styles[0];
|
|
|
|
cs.forceUpperCase = false;
|
|
|
|
cs.fullAuthorList = false;
|
2007-10-25 04:13:56 +00:00
|
|
|
if (!InsetCitation::isCompatibleCommand(input))
|
2012-03-01 00:41:30 +00:00
|
|
|
return cs;
|
2007-09-20 06:22:07 +00:00
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
string normalized_input = input;
|
|
|
|
string::size_type const n = input.size() - 1;
|
|
|
|
if (input[0] == 'C')
|
|
|
|
normalized_input[0] = 'c';
|
|
|
|
if (input[n] == '*')
|
|
|
|
normalized_input = normalized_input.substr(0, n);
|
2007-09-20 06:22:07 +00:00
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
vector<CitationStyle>::const_iterator it = valid_styles.begin();
|
|
|
|
vector<CitationStyle>::const_iterator end = valid_styles.end();
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
CitationStyle this_cs = *it;
|
|
|
|
if (this_cs.cmd == normalized_input) {
|
|
|
|
cs = *it;
|
2007-09-20 06:22:07 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-08-20 16:30:02 +00:00
|
|
|
}
|
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
cs.forceUpperCase &= input[0] == 'C';
|
|
|
|
cs.fullAuthorList &= input[n] == '*';
|
|
|
|
|
|
|
|
return cs;
|
2007-08-20 16:30:02 +00:00
|
|
|
}
|
|
|
|
|
2010-01-11 16:11:55 +00:00
|
|
|
|
2011-12-03 22:15:11 +00:00
|
|
|
inline docstring wrapCitation(docstring const & key,
|
2010-01-11 16:11:55 +00:00
|
|
|
docstring const & content, bool for_xhtml)
|
|
|
|
{
|
|
|
|
if (!for_xhtml)
|
|
|
|
return content;
|
|
|
|
// we have to do the escaping here, because we will ultimately
|
|
|
|
// write this as a raw string, so as not to escape the tags.
|
2013-03-27 19:46:32 +00:00
|
|
|
return "<a href='#LyXCite-" + html::cleanAttr(key) + "'>" +
|
2010-11-24 15:27:36 +00:00
|
|
|
html::htmlize(content, XHTMLStream::ESCAPE_ALL) + "</a>";
|
2010-01-11 16:11:55 +00:00
|
|
|
}
|
|
|
|
|
2010-01-09 22:30:56 +00:00
|
|
|
} // anonymous namespace
|
2010-01-09 22:30:12 +00:00
|
|
|
|
2010-01-11 16:11:55 +00:00
|
|
|
docstring InsetCitation::generateLabel(bool for_xhtml) const
|
2010-01-09 22:30:12 +00:00
|
|
|
{
|
|
|
|
docstring label;
|
2010-01-11 16:11:55 +00:00
|
|
|
label = complexLabel(for_xhtml);
|
2010-01-09 22:30:12 +00:00
|
|
|
|
|
|
|
// Fallback to fail-safe
|
|
|
|
if (label.empty())
|
2010-01-11 16:11:55 +00:00
|
|
|
label = basicLabel(for_xhtml);
|
2010-01-09 22:30:12 +00:00
|
|
|
|
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-11 16:11:55 +00:00
|
|
|
docstring InsetCitation::complexLabel(bool for_xhtml) const
|
2000-06-07 08:53:40 +00:00
|
|
|
{
|
2010-01-09 22:30:12 +00:00
|
|
|
Buffer const & buf = buffer();
|
2003-10-22 13:15:18 +00:00
|
|
|
// Only start the process off after the buffer is loaded from file.
|
2010-01-09 22:30:12 +00:00
|
|
|
if (!buf.isFullyLoaded())
|
2006-12-17 10:52:04 +00:00
|
|
|
return docstring();
|
2003-10-22 13:15:18 +00:00
|
|
|
|
2010-01-09 22:30:12 +00:00
|
|
|
BiblioInfo const & biblist = buf.masterBibInfo();
|
2007-08-20 16:30:02 +00:00
|
|
|
if (biblist.empty())
|
2006-12-17 10:52:04 +00:00
|
|
|
return docstring();
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
docstring const & key = getParam("key");
|
|
|
|
if (key.empty())
|
|
|
|
return _("No citations selected!");
|
|
|
|
|
2002-05-14 09:47:12 +00:00
|
|
|
// We don't currently use the full or forceUCase fields.
|
2012-03-01 00:41:30 +00:00
|
|
|
string cite_type = getCmdName();
|
2004-05-14 15:27:13 +00:00
|
|
|
if (cite_type[0] == 'C')
|
2010-01-08 14:38:31 +00:00
|
|
|
// If we were going to use them, this would mean ForceUCase
|
2004-05-14 15:27:13 +00:00
|
|
|
cite_type = string(1, 'c') + cite_type.substr(1);
|
|
|
|
if (cite_type[cite_type.size() - 1] == '*')
|
2010-01-08 14:38:31 +00:00
|
|
|
// and this would mean FULL
|
2004-05-14 15:27:13 +00:00
|
|
|
cite_type = cite_type.substr(0, cite_type.size() - 1);
|
2002-07-28 18:13:51 +00:00
|
|
|
|
2010-01-09 22:30:12 +00:00
|
|
|
docstring const & before = getParam("before");
|
|
|
|
docstring const & after = getParam("after");
|
2000-07-19 08:37:26 +00:00
|
|
|
|
2012-03-01 00:41:30 +00:00
|
|
|
// FIXME: allow to add cite macros
|
|
|
|
/*
|
|
|
|
buffer().params().documentClass().addCiteMacro("!textbefore", to_utf8(before));
|
|
|
|
buffer().params().documentClass().addCiteMacro("!textafter", to_utf8(after));
|
|
|
|
*/
|
2006-12-17 10:52:04 +00:00
|
|
|
docstring label;
|
2014-05-23 14:59:12 +00:00
|
|
|
vector<docstring> keys = getVectorFromString(key);
|
|
|
|
label = biblist.getLabel(keys, buffer(), cite_type, for_xhtml, UINT_MAX, before, after);
|
2002-04-24 10:00:39 +00:00
|
|
|
return label;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-11 16:11:55 +00:00
|
|
|
docstring InsetCitation::basicLabel(bool for_xhtml) const
|
2002-04-24 10:00:39 +00:00
|
|
|
{
|
2010-01-09 22:30:12 +00:00
|
|
|
docstring keys = getParam("key");
|
2006-12-17 10:52:04 +00:00
|
|
|
docstring label;
|
2002-04-24 10:00:39 +00:00
|
|
|
|
2010-01-21 19:58:21 +00:00
|
|
|
docstring key;
|
|
|
|
do {
|
|
|
|
// if there is no comma, then everything goes into key
|
|
|
|
// and keys will be empty.
|
|
|
|
keys = trim(split(keys, key, ','));
|
|
|
|
key = trim(key);
|
|
|
|
if (!label.empty())
|
|
|
|
label += ", ";
|
|
|
|
label += wrapCitation(key, key, for_xhtml);
|
|
|
|
} while (!keys.empty());
|
2002-04-24 10:00:39 +00:00
|
|
|
|
2010-01-09 22:30:12 +00:00
|
|
|
docstring const & after = getParam("after");
|
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
|
|
|
}
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring InsetCitation::screenLabel() const
|
2008-03-04 17:47:47 +00:00
|
|
|
{
|
|
|
|
return cache.screen_label;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-03 22:13:45 +00:00
|
|
|
void InsetCitation::updateBuffer(ParIterator const &, UpdateType)
|
2002-04-24 10:00:39 +00:00
|
|
|
{
|
2011-05-07 23:02:53 +00:00
|
|
|
if (!cache.recalculate && buffer().citeLabelsValid())
|
2008-03-04 17:47:47 +00:00
|
|
|
return;
|
2011-05-07 23:02:53 +00:00
|
|
|
// The label may have changed, so we have to re-create it.
|
2008-02-27 20:43:16 +00:00
|
|
|
docstring const glabel = generateLabel();
|
2011-05-07 23:02:53 +00:00
|
|
|
cache.recalculate = false;
|
2002-04-24 10:00:39 +00:00
|
|
|
cache.generated_label = glabel;
|
2015-10-04 18:38:47 +00:00
|
|
|
unsigned int const maxLabelChars = 45;
|
|
|
|
cache.screen_label = glabel.substr(0, maxLabelChars);
|
|
|
|
support::truncateWithEllipsis(cache.screen_label, maxLabelChars);
|
2008-03-04 17:47:47 +00:00
|
|
|
}
|
2002-04-24 10:00:39 +00:00
|
|
|
|
2008-03-04 17:47:47 +00:00
|
|
|
|
2015-09-27 06:05:00 +00:00
|
|
|
void InsetCitation::addToToc(DocIterator const & cpit, bool output_active,
|
|
|
|
UpdateType) const
|
2008-03-04 17:47:47 +00:00
|
|
|
{
|
2010-07-30 15:50:42 +00:00
|
|
|
// NOTE
|
2014-08-22 15:17:36 +00:00
|
|
|
// BiblioInfo::collectCitedEntries() uses the TOC to collect the citations
|
|
|
|
// from the document. It is used indirectly, via BiblioInfo::makeCitationLables,
|
|
|
|
// by both XHTML and plaintext output. So, if we change what goes into the TOC,
|
|
|
|
// then we will also need to change that routine.
|
2010-07-30 15:50:42 +00:00
|
|
|
docstring const tocitem = getParam("key");
|
2015-09-01 16:08:35 +00:00
|
|
|
shared_ptr<Toc> toc = buffer().tocBackend().toc("citation");
|
|
|
|
toc->push_back(TocItem(cpit, 0, tocitem, output_active));
|
2000-06-07 08:53:40 +00:00
|
|
|
}
|
2000-07-14 07:52:03 +00:00
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2013-03-08 19:52:18 +00:00
|
|
|
int InsetCitation::plaintext(odocstringstream & os,
|
|
|
|
OutputParams const &, size_t) const
|
2001-05-27 17:51:16 +00:00
|
|
|
{
|
2013-02-02 18:23:21 +00:00
|
|
|
string const & cmd = getCmdName();
|
|
|
|
if (cmd == "nocite")
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
docstring const label = generateLabel(false);
|
|
|
|
os << label;
|
|
|
|
return label.size();
|
2001-05-27 17:51:16 +00:00
|
|
|
}
|
2001-07-19 14:12:37 +00:00
|
|
|
|
2002-04-24 10:00:39 +00:00
|
|
|
|
2007-09-11 22:31:24 +00:00
|
|
|
static docstring const cleanupWhitespace(docstring const & citelist)
|
2004-10-21 22:39:20 +00:00
|
|
|
{
|
2006-12-17 10:52:04 +00:00
|
|
|
docstring::const_iterator it = citelist.begin();
|
|
|
|
docstring::const_iterator end = citelist.end();
|
2004-10-21 22:39:20 +00:00
|
|
|
// Paranoia check: make sure that there is no whitespace in here
|
|
|
|
// -- at least not behind commas or at the beginning
|
2006-12-17 10:52:04 +00:00
|
|
|
docstring result;
|
|
|
|
char_type last = ',';
|
2004-10-21 22:39:20 +00:00
|
|
|
for (; it != end; ++it) {
|
|
|
|
if (*it != ' ')
|
|
|
|
last = *it;
|
|
|
|
if (*it != ' ' || last != ',')
|
|
|
|
result += *it;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetCitation::docbook(odocstream & os, OutputParams const &) const
|
2004-10-21 22:39:20 +00:00
|
|
|
{
|
2007-11-28 22:12:03 +00:00
|
|
|
os << from_ascii("<citation>")
|
2007-05-28 22:27:45 +00:00
|
|
|
<< cleanupWhitespace(getParam("key"))
|
2007-11-28 22:12:03 +00:00
|
|
|
<< from_ascii("</citation>");
|
2004-10-21 22:39:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-30 22:59:18 +00:00
|
|
|
docstring InsetCitation::xhtml(XHTMLStream & xs, OutputParams const &) const
|
2009-06-11 21:04:15 +00:00
|
|
|
{
|
2010-01-08 18:49:32 +00:00
|
|
|
string const & cmd = getCmdName();
|
|
|
|
if (cmd == "nocite")
|
|
|
|
return docstring();
|
|
|
|
|
2010-01-11 16:11:55 +00:00
|
|
|
// have to output this raw, because generateLabel() will include tags
|
2010-11-24 15:27:36 +00:00
|
|
|
xs << XHTMLStream::ESCAPE_NONE << generateLabel(true);
|
2009-06-11 21:04:15 +00:00
|
|
|
|
2009-06-12 17:23:17 +00:00
|
|
|
return docstring();
|
2009-06-11 21:04:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-15 01:34:04 +00:00
|
|
|
void InsetCitation::toString(odocstream & os) const
|
2005-11-25 14:40:34 +00:00
|
|
|
{
|
2013-03-08 19:52:18 +00:00
|
|
|
odocstringstream ods;
|
|
|
|
plaintext(ods, OutputParams(0));
|
|
|
|
os << ods.str();
|
2005-11-25 14:40:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-04 18:38:47 +00:00
|
|
|
void InsetCitation::forOutliner(docstring & os, size_t const, bool const) const
|
2010-12-20 21:55:09 +00:00
|
|
|
{
|
|
|
|
os += screenLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
2012-03-01 00:41:30 +00:00
|
|
|
// should revert to the default citation command as provided by the citation
|
|
|
|
// engine, e.g. \cite[]{} for the basic engine.
|
2011-02-10 20:02:48 +00:00
|
|
|
void InsetCitation::latex(otexstream & os, OutputParams const & runparams) const
|
2001-07-19 14:12:37 +00:00
|
|
|
{
|
2012-03-01 00:41:30 +00:00
|
|
|
vector<CitationStyle> citation_styles = buffer().params().citeStyles();
|
|
|
|
CitationStyle cs = asValidLatexCommand(getCmdName(), citation_styles);
|
2010-02-12 16:08:30 +00:00
|
|
|
BiblioInfo const & bi = buffer().masterBibInfo();
|
2006-10-19 16:51:30 +00:00
|
|
|
// FIXME UNICODE
|
2012-03-01 00:41:30 +00:00
|
|
|
docstring const cite_str = from_utf8(citationStyleToString(cs));
|
2004-10-05 10:11:42 +00:00
|
|
|
|
2014-03-22 11:25:25 +00:00
|
|
|
if (runparams.inulemcmd > 0)
|
2009-05-07 10:57:52 +00:00
|
|
|
os << "\\mbox{";
|
|
|
|
|
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");
|
2012-03-01 00:41:30 +00:00
|
|
|
if (!before.empty() && cs.textBefore)
|
2002-11-27 10:30:28 +00:00
|
|
|
os << '[' << before << "][" << after << ']';
|
2012-03-01 00:41:30 +00:00
|
|
|
else if (!after.empty() && cs.textAfter)
|
2002-11-27 10:30:28 +00:00
|
|
|
os << '[' << after << ']';
|
2004-03-05 14:49:10 +00:00
|
|
|
|
2010-02-12 16:08:30 +00:00
|
|
|
if (!bi.isBibtex(getParam("key")))
|
|
|
|
// escape chars with bibitems
|
|
|
|
os << '{' << escape(cleanupWhitespace(getParam("key"))) << '}';
|
|
|
|
else
|
|
|
|
os << '{' << cleanupWhitespace(getParam("key")) << '}';
|
2001-07-19 14:12:37 +00:00
|
|
|
|
2009-05-07 10:57:52 +00:00
|
|
|
if (runparams.inulemcmd)
|
|
|
|
os << "}";
|
2001-07-19 14:12:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-29 14:48:55 +00:00
|
|
|
string InsetCitation::contextMenuName() const
|
2008-04-28 15:21:55 +00:00
|
|
|
{
|
2011-10-29 14:48:55 +00:00
|
|
|
return "context-citation";
|
2008-04-28 15:21:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|