2 * \file InsetBibtex.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
7 * \author Richard Heck (BibTeX parser improvements)
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
15 #include "InsetBibtex.h"
17 #include "BiblioInfo.h"
19 #include "BufferParams.h"
20 #include "CiteEnginesList.h"
22 #include "DispatchResult.h"
26 #include "FuncRequest.h"
27 #include "FuncStatus.h"
28 #include "LaTeXFeatures.h"
29 #include "output_latex.h"
30 #include "output_xhtml.h"
31 #include "OutputParams.h"
32 #include "PDFOptions.h"
33 #include "texstream.h"
34 #include "TextClass.h"
35 #include "TocBackend.h"
37 #include "frontends/alert.h"
39 #include "support/convert.h"
40 #include "support/debug.h"
41 #include "support/docstream.h"
42 #include "support/docstring_list.h"
43 #include "support/ExceptionMessage.h"
44 #include "support/FileNameList.h"
45 #include "support/filetools.h"
46 #include "support/gettext.h"
47 #include "support/lstrings.h"
48 #include "support/os.h"
49 #include "support/PathChanger.h"
50 #include "support/textutils.h"
55 using namespace lyx::support;
59 namespace Alert = frontend::Alert;
60 namespace os = support::os;
63 InsetBibtex::InsetBibtex(Buffer * buf, InsetCommandParams const & p)
64 : InsetCommand(buf, p)
68 ParamInfo const & InsetBibtex::findInfo(string const & /* cmdName */)
70 static ParamInfo param_info_;
71 if (param_info_.empty()) {
72 param_info_.add("btprint", ParamInfo::LATEX_OPTIONAL);
73 param_info_.add("bibfiles", ParamInfo::LATEX_REQUIRED);
74 param_info_.add("options", ParamInfo::LYX_INTERNAL);
75 param_info_.add("encoding", ParamInfo::LYX_INTERNAL);
76 param_info_.add("file_encodings", ParamInfo::LYX_INTERNAL);
77 param_info_.add("biblatexopts", ParamInfo::LATEX_OPTIONAL);
83 void InsetBibtex::doDispatch(Cursor & cur, FuncRequest & cmd)
85 switch (cmd.action()) {
88 editDatabases(cmd.argument());
91 case LFUN_INSET_MODIFY: {
92 InsetCommandParams p(BIBTEX_CODE);
94 if (!InsetCommand::string2params(to_utf8(cmd.argument()), p)) {
98 } catch (ExceptionMessage const & message) {
99 if (message.type_ == WarningException) {
100 Alert::warning(message.title_, message.details_);
101 cur.noScreenUpdate();
109 cur.buffer()->clearBibFileCache();
110 cur.forceBufferUpdate();
115 InsetCommand::doDispatch(cur, cmd);
121 bool InsetBibtex::getStatus(Cursor & cur, FuncRequest const & cmd,
122 FuncStatus & flag) const
124 switch (cmd.action()) {
125 case LFUN_INSET_EDIT:
126 flag.setEnabled(true);
130 return InsetCommand::getStatus(cur, cmd, flag);
135 void InsetBibtex::editDatabases(docstring const & db) const
137 vector<docstring> bibfilelist = getVectorFromString(getParam("bibfiles"));
139 if (bibfilelist.empty())
142 size_t nr_databases = bibfilelist.size();
143 if (nr_databases > 1 && db.empty()) {
144 docstring const engine = usingBiblatex() ? _("Biblatex") : _("BibTeX");
145 docstring message = bformat(_("The %1$s[[BibTeX/Biblatex]] inset includes %2$s databases.\n"
146 "If you proceed, all of them will be opened."),
147 engine, convert<docstring>(nr_databases));
148 int const ret = Alert::prompt(_("Open Databases?"),
149 message, 0, 1, _("&Cancel"), _("&Proceed"));
155 vector<docstring>::const_iterator it = bibfilelist.begin();
156 vector<docstring>::const_iterator en = bibfilelist.end();
157 for (; it != en; ++it) {
158 if (!db.empty() && db != *it)
160 FileName const bibfile = buffer().getBibfilePath(*it);
161 theFormats().edit(buffer(), bibfile,
162 theFormats().getFormatFromFile(bibfile));
167 bool InsetBibtex::usingBiblatex() const
169 return buffer().masterParams().useBiblatex();
173 docstring InsetBibtex::screenLabel() const
175 return usingBiblatex() ? _("Biblatex Generated Bibliography")
176 : _("BibTeX Generated Bibliography");
180 docstring InsetBibtex::toolTip(BufferView const & /*bv*/, int /*x*/, int /*y*/) const
182 docstring tip = _("Databases:");
183 vector<docstring> bibfilelist = getVectorFromString(getParam("bibfiles"));
186 if (bibfilelist.empty())
187 tip += "<li>" + _("none") + "</li>";
189 for (docstring const & bibfile : bibfilelist)
190 tip += "<li>" + bibfile + "</li>";
195 docstring style = getParam("options"); // maybe empty! and with bibtotoc
196 docstring bibtotoc = from_ascii("bibtotoc");
197 if (prefixIs(style, bibtotoc)) {
199 if (contains(style, char_type(',')))
200 style = split(style, bibtotoc, char_type(','));
203 docstring const btprint = getParam("btprint");
204 if (!usingBiblatex()) {
205 tip += _("Style File:");
206 tip += "<ul><li>" + (style.empty() ? _("none") : style) + "</li></ul>";
208 tip += _("Lists:") + " ";
209 if (btprint == "btPrintAll")
210 tip += _("all references");
211 else if (btprint == "btPrintNotCited")
212 tip += _("all uncited references");
214 tip += _("all cited references");
217 tip += _("included in TOC");
219 if (!buffer().parent()
220 && buffer().params().multibib == "child") {
222 tip += _("Note: This bibliography is not output, since bibliographies in the master file "
223 "are not allowed with the setting 'Multiple bibliographies per child document'");
226 tip += _("Lists:") + " ";
227 if (btprint == "bibbysection")
228 tip += _("all reference units");
229 else if (btprint == "btPrintAll")
230 tip += _("all references");
232 tip += _("all cited references");
235 tip += _("included in TOC");
237 if (!getParam("biblatexopts").empty()) {
239 tip += _("Options: ") + getParam("biblatexopts");
247 void InsetBibtex::latex(otexstream & os, OutputParams const & runparams) const
249 // The sequence of the commands:
250 // With normal BibTeX:
251 // 1. \bibliographystyle{style}
252 // 2. \addcontentsline{...} - if option bibtotoc set
253 // 3. \bibliography{database}
255 // 1. \bibliographystyle{style}
256 // 2. \begin{btSect}{database}
257 // 3. \btPrint{Cited|NotCited|All}
260 // \printbibliography[biblatexopts]
262 // \bibbysection[biblatexopts] - if btprint is "bibbysection"
264 // chapterbib does not allow bibliographies in the master
265 if (!usingBiblatex() && !runparams.is_child
266 && buffer().params().multibib == "child")
269 if (runparams.inDeletedInset) {
270 // We cannot strike-out bibligraphies,
271 // so we just output a note.
273 << buffer().B_("[BIBLIOGRAPHY DELETED!]")
278 string style = to_utf8(getParam("options")); // maybe empty! and with bibtotoc
280 if (prefixIs(style, "bibtotoc")) {
281 bibtotoc = "bibtotoc";
282 if (contains(style, ','))
283 style = split(style, bibtotoc, ',');
286 if (usingBiblatex()) {
288 string opts = to_utf8(getParam("biblatexopts"));
290 if (!bibtotoc.empty())
291 opts = opts.empty() ? "heading=bibintoc" : "heading=bibintoc," + opts;
292 // The bibliography command
293 docstring btprint = getParam("btprint");
294 if (btprint == "btPrintAll")
295 os << "\\nocite{*}\n";
296 if (btprint == "bibbysection" && !buffer().masterParams().multibib.empty())
297 os << "\\bibbysection";
299 os << "\\printbibliography";
301 os << "[" << opts << "]";
303 } else {// using BibTeX
305 vector<pair<docstring, string>> const dbs =
306 buffer().prepareBibFilePaths(runparams, getBibFiles(), false);
307 vector<docstring> db_out;
308 for (pair<docstring, string> const & db : dbs)
309 db_out.push_back(db.first);
311 if (style == "default")
312 style = buffer().masterParams().defaultBiblioStyle();
313 if (!style.empty() && !buffer().masterParams().useBibtopic()) {
314 string base = buffer().masterBuffer()->prepareFileNameForLaTeX(style, ".bst", runparams.nice);
315 FileName const try_in_file =
316 makeAbsPath(base + ".bst", buffer().filePath());
317 bool const not_from_texmf = try_in_file.isReadableFile();
318 // If this style does not come from texmf and we are not
319 // exporting to .tex copy it to the tmp directory.
320 // This prevents problems with spaces and 8bit characters
322 if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
324 // use new style name
325 DocFileName const in_file = DocFileName(try_in_file);
326 base = removeExtension(in_file.mangledFileName());
327 FileName const out_file = makeAbsPath(base + ".bst",
328 buffer().masterBuffer()->temppath());
329 bool const success = in_file.copyTo(out_file);
331 LYXERR0("Failed to copy '" << in_file
332 << "' to '" << out_file << "'");
336 os << "\\bibliographystyle{"
337 << from_utf8(latex_path(buffer().prepareFileNameForLaTeX(base, ".bst", runparams.nice)))
340 // Warn about spaces in bst path. Warn only once.
341 static bool warned_about_bst_spaces = false;
342 if (!warned_about_bst_spaces && runparams.nice && contains(style, ' ')) {
343 warned_about_bst_spaces = true;
344 Alert::warning(_("Export Warning!"),
345 _("There are spaces in the path to your BibTeX style file.\n"
346 "BibTeX will be unable to find it."));
349 bool encoding_switched = false;
350 Encoding const * const save_enc = runparams.encoding;
351 docstring const encoding = getParam("encoding");
352 if (!encoding.empty() && encoding != from_ascii("default")) {
353 Encoding const * const enc = encodings.fromLyXName(to_ascii(encoding));
354 if (enc != runparams.encoding) {
356 switchEncoding(os.os(), buffer().params(), runparams, *enc, true);
357 runparams.encoding = enc;
358 encoding_switched = true;
361 // Handle the bibtopic case
362 if (!db_out.empty() && buffer().masterParams().useBibtopic()) {
363 os << "\\begin{btSect}";
365 os << "[" << style << "]";
366 os << "{" << getStringFromVector(db_out) << "}\n";
367 docstring btprint = getParam("btprint");
370 btprint = from_ascii("btPrintCited");
371 os << "\\" << btprint << "\n"
372 << "\\end{btSect}\n";
375 if (!bibtotoc.empty() && !buffer().masterParams().useBibtopic()
376 && !buffer().masterParams().documentClass().bibInToc()) {
377 // set label for hyperref, see http://www.lyx.org/trac/ticket/6470
378 if (buffer().masterParams().pdfoptions().use_hyperref)
379 os << "\\phantomsection";
380 if (buffer().masterParams().documentClass().hasLaTeXLayout("chapter"))
381 os << "\\addcontentsline{toc}{chapter}{\\bibname}";
382 else if (buffer().masterParams().documentClass().hasLaTeXLayout("section"))
383 os << "\\addcontentsline{toc}{section}{\\refname}";
385 // The bibliography command
386 if (!db_out.empty() && !buffer().masterParams().useBibtopic()) {
387 docstring btprint = getParam("btprint");
388 if (btprint == "btPrintAll") {
389 os << "\\nocite{*}\n";
391 os << "\\bibliography{" << getStringFromVector(db_out) << "}\n";
393 if (encoding_switched){
395 switchEncoding(os.os(), buffer().params(),
396 runparams, *save_enc, true, true);
397 os << "\\egroup" << breakln;
398 runparams.encoding = save_enc;
404 docstring_list InsetBibtex::getBibFiles() const
406 return getVectorFromString(getParam("bibfiles"));
411 // methods for parsing bibtex files
413 typedef map<docstring, docstring> VarMap;
415 /// remove whitespace characters, optionally a single comma,
416 /// and further whitespace characters from the stream.
417 /// @return true if a comma was found, false otherwise
419 bool removeWSAndComma(ifdocstream & ifs) {
428 } while (ifs && isSpace(ch));
441 } while (ifs && isSpace(ch));
456 /// remove whitespace characters, read characer sequence
457 /// not containing whitespace characters or characters in
458 /// delimChars, and remove further whitespace characters.
460 /// @return true if a string of length > 0 could be read.
462 bool readTypeOrKey(docstring & val, ifdocstream & ifs,
463 docstring const & delimChars, docstring const & illegalChars,
476 } while (ifs && isSpace(ch));
482 while (ifs && !isSpace(ch) &&
483 delimChars.find(ch) == docstring::npos &&
484 illegalChars.find(ch) == docstring::npos)
486 if (chCase == makeLowerCase)
487 val += lowercase(ch);
493 if (illegalChars.find(ch) != docstring::npos) {
499 while (ifs && isSpace(ch)) {
507 return val.length() > 0;
510 /// read subsequent bibtex values that are delimited with a #-character.
511 /// Concatenate all parts and replace names with the associated string in
512 /// the variable strings.
513 /// @return true if reading was successfull (all single parts were delimited
515 bool readValue(docstring & val, ifdocstream & ifs, const VarMap & strings) {
528 } while (ifs && isSpace(ch));
533 // check for field type
534 if (isDigitASCII(ch)) {
536 // read integer value
540 } while (ifs && isDigitASCII(ch));
545 } else if (ch == '"' || ch == '{') {
547 char_type delim = ch == '"' ? '"': '}';
552 } while (ifs && isSpace(ch));
557 // We now have the first non-whitespace character
558 // We'll collapse adjacent whitespace.
559 bool lastWasWhiteSpace = false;
561 // inside this delimited text braces must match.
562 // Thus we can have a closing delimiter only
563 // when nestLevel == 0
566 while (ifs && (nestLevel > 0 || ch != delim)) {
568 lastWasWhiteSpace = true;
572 // We output the space only after we stop getting
573 // whitespace so as not to output any whitespace
574 // at the end of the value.
575 if (lastWasWhiteSpace) {
576 lastWasWhiteSpace = false;
582 // update nesting level
601 // FIXME Why is this here?
609 // reading a string name
612 while (ifs && !isSpace(ch) && ch != '#' && ch != ',' && ch != '}' && ch != ')') {
613 strName += lowercase(ch);
620 // replace the string with its assigned value or
621 // discard it if it's not assigned
622 if (strName.length()) {
623 VarMap::const_iterator pos = strings.find(strName);
624 if (pos != strings.end()) {
631 while (ifs && isSpace(ch)) {
638 // continue reading next value on concatenate with '#'
648 void InsetBibtex::collectBibKeys(InsetIterator const & /*di*/, FileNameList & checkedFiles) const
650 parseBibTeXFiles(checkedFiles);
654 void InsetBibtex::parseBibTeXFiles(FileNameList & checkedFiles) const
656 // This bibtex parser is a first step to parse bibtex files
659 // - it reads the whole bibtex entry and does a syntax check
660 // (matching delimiters, missing commas,...
661 // - it recovers from errors starting with the next @-character
662 // - it reads @string definitions and replaces them in the
664 // - it accepts more characters in keys or value names than
667 // Officially bibtex does only support ASCII, but in practice
668 // you can use any encoding as long as some elements like keys
669 // and names are pure ASCII. We support specifying an encoding,
670 // and we convert the file from that (default is buffer encoding).
671 // We don't restrict keys to ASCII in LyX, since our own
672 // InsetBibitem can generate non-ASCII keys, and nonstandard
673 // 8bit clean bibtex forks exist.
677 docstring_list const files = getBibFiles();
678 for (auto const & bf : files) {
679 FileName const bibfile = buffer().getBibfilePath(bf);
680 if (bibfile.empty()) {
681 LYXERR0("Unable to find path for " << bf << "!");
684 if (find(checkedFiles.begin(), checkedFiles.end(), bibfile) != checkedFiles.end())
685 // already checked this one. Skip.
688 // record that we check this.
689 checkedFiles.push_back(bibfile);
690 string encoding = buffer().masterParams().encoding().iconvName();
691 string ienc = buffer().masterParams().bibFileEncoding(to_utf8(bf));
692 if (ienc.empty() || ienc == "general")
693 ienc = to_ascii(params()["encoding"]);
695 if (!ienc.empty() && ienc != "auto-legacy-plain" && ienc != "auto-legacy" && encodings.fromLyXName(ienc))
696 encoding = encodings.fromLyXName(ienc)->iconvName();
697 ifdocstream ifs(bibfile.toFilesystemEncoding().c_str(),
698 ios_base::in, encoding);
713 if (!readTypeOrKey(entryType, ifs, from_ascii("{("), docstring(), makeLowerCase)) {
714 lyxerr << "BibTeX Parser: Error reading entry type." << std::endl;
719 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
723 if (entryType == from_ascii("comment")) {
724 ifs.ignore(numeric_limits<int>::max(), '\n');
730 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
734 if ((ch != '(') && (ch != '{')) {
735 lyxerr << "BibTeX Parser: Invalid entry delimiter." << std::endl;
741 if (entryType == from_ascii("string")) {
743 // read string and add it to the strings map
744 // (or replace it's old value)
748 if (!readTypeOrKey(name, ifs, from_ascii("="), from_ascii("#{}(),"), makeLowerCase)) {
749 lyxerr << "BibTeX Parser: Error reading string name." << std::endl;
754 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
758 // next char must be an equal sign
760 if (!ifs || ch != '=') {
761 lyxerr << "BibTeX Parser: No `=' after string name: " <<
762 name << "." << std::endl;
766 if (!readValue(value, ifs, strings)) {
767 lyxerr << "BibTeX Parser: Unable to read value for string: " <<
768 name << "." << std::endl;
772 strings[name] = value;
774 } else if (entryType == from_ascii("preamble")) {
776 // preamble definitions are discarded.
777 // can they be of any use in lyx?
780 if (!readValue(value, ifs, strings)) {
781 lyxerr << "BibTeX Parser: Unable to read preamble value." << std::endl;
787 // Citation entry. Try to read the key.
790 if (!readTypeOrKey(key, ifs, from_ascii(","), from_ascii("}"), keepCase)) {
791 lyxerr << "BibTeX Parser: Unable to read key for entry type:" <<
792 entryType << "." << std::endl;
797 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
801 /////////////////////////////////////////////
802 // now we have a key, so we will add an entry
803 // (even if it's empty, as bibtex does)
805 // we now read the field = value pairs.
806 // all items must be separated by a comma. If
807 // it is missing the scanning of this entry is
808 // stopped and the next is searched.
812 BibTeXInfo keyvalmap(key, entryType);
814 bool readNext = removeWSAndComma(ifs);
816 while (ifs && readNext) {
819 if (!readTypeOrKey(name, ifs, from_ascii("="),
820 from_ascii("{}(),"), makeLowerCase) || !ifs)
823 // next char must be an equal sign
824 // FIXME Whitespace??
827 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
831 lyxerr << "BibTeX Parser: Missing `=' after field name: " <<
832 name << ", for key: " << key << "." << std::endl;
838 if (!readValue(value, ifs, strings)) {
839 lyxerr << "BibTeX Parser: Unable to read value for field: " <<
840 name << ", for key: " << key << "." << std::endl;
844 keyvalmap[name] = value;
845 data += "\n\n" + value;
846 keylist.addFieldName(name);
847 readNext = removeWSAndComma(ifs);
851 keylist.addEntryType(entryType);
852 keyvalmap.setAllData(data);
853 keylist[key] = keyvalmap;
854 } //< else (citation entry)
856 } //< for loop over files
858 buffer().addBiblioInfo(keylist);
862 bool InsetBibtex::addDatabase(docstring const & db)
864 docstring bibfiles = getParam("bibfiles");
865 if (tokenPos(bibfiles, ',', db) != -1)
867 if (!bibfiles.empty())
869 setParam("bibfiles", bibfiles + db);
874 bool InsetBibtex::delDatabase(docstring const & db)
876 docstring bibfiles = getParam("bibfiles");
877 if (contains(bibfiles, db)) {
878 int const n = tokenPos(bibfiles, ',', db);
881 // this is not the first database
882 docstring tmp = ',' + bd;
883 setParam("bibfiles", subst(bibfiles, tmp, docstring()));
885 // this is the first (or only) database
886 setParam("bibfiles", split(bibfiles, bd, ','));
894 void InsetBibtex::validate(LaTeXFeatures & features) const
896 BufferParams const & mparams = features.buffer().masterParams();
897 if (mparams.useBibtopic())
898 features.require("bibtopic");
899 else if (!mparams.useBiblatex() && mparams.multibib == "child")
900 features.require("chapterbib");
902 // It'd be better to be able to get this from an InsetLayout, but at present
903 // InsetLayouts do not seem really to work for things that aren't InsetTexts.
904 if (features.runparams().flavor == OutputParams::HTML)
905 features.addCSSSnippet("div.bibtexentry { margin-left: 2em; text-indent: -2em; }\n"
906 "span.bibtexlabel:before{ content: \"[\"; }\n"
907 "span.bibtexlabel:after{ content: \"] \"; }");
911 void InsetBibtex::updateBuffer(ParIterator const &, UpdateType, bool const /*deleted*/)
913 buffer().registerBibfiles(getBibFiles());
914 // record encoding of bib files for biblatex
915 string const enc = (params()["encoding"] == from_ascii("default")) ?
916 string() : to_ascii(params()["encoding"]);
917 bool invalidate = false;
918 if (buffer().params().bibEncoding() != enc) {
919 buffer().params().setBibEncoding(enc);
922 map<string, string> encs = getFileEncodings();
923 map<string, string>::const_iterator it = encs.begin();
924 for (; it != encs.end(); ++it) {
925 if (buffer().params().bibFileEncoding(it->first) != it->second) {
926 buffer().params().setBibFileEncoding(it->first, it->second);
931 buffer().invalidateBibinfoCache();
935 map<string, string> InsetBibtex::getFileEncodings() const
938 getVectorFromString(to_utf8(getParam("file_encodings")), "\t");
939 std::map<string, string> res;
940 for (string const & s: ps) {
942 string val = split(s, key, ' ');
949 docstring InsetBibtex::getRefLabel() const
951 if (buffer().masterParams().documentClass().hasLaTeXLayout("chapter"))
952 return buffer().B_("Bibliography");
953 return buffer().B_("References");
957 void InsetBibtex::addToToc(DocIterator const & cpit, bool output_active,
958 UpdateType, TocBackend & backend) const
960 if (!prefixIs(to_utf8(getParam("options")), "bibtotoc"))
963 docstring const str = getRefLabel();
964 shared_ptr<Toc> toc = backend.toc("tableofcontents");
965 // Assign to appropriate level
966 int const item_depth =
967 (buffer().masterParams().documentClass().hasLaTeXLayout("chapter"))
969 toc->push_back(TocItem(cpit, item_depth, str, output_active));
973 int InsetBibtex::plaintext(odocstringstream & os,
974 OutputParams const & op, size_t max_length) const
976 docstring const reflabel = getRefLabel();
978 // We could output more information here, e.g., what databases are included
979 // and information about options. But I don't necessarily see any reason to
980 // do this right now.
981 if (op.for_tooltip || op.for_toc || op.for_search) {
982 os << '[' << reflabel << ']' << '\n';
983 return PLAINTEXT_NEWLINE;
986 BiblioInfo bibinfo = buffer().masterBibInfo();
987 bibinfo.makeCitationLabels(buffer());
988 vector<docstring> const & cites = bibinfo.citedEntries();
990 size_t start_size = os.str().size();
992 refoutput += reflabel + "\n\n";
994 // Tell BiblioInfo our purpose
996 ci.context = CiteItem::Export;
998 // Now we loop over the entries
999 vector<docstring>::const_iterator vit = cites.begin();
1000 vector<docstring>::const_iterator const ven = cites.end();
1001 for (; vit != ven; ++vit) {
1002 if (start_size + refoutput.size() >= max_length)
1004 BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
1005 if (biit == bibinfo.end())
1007 BibTeXInfo const & entry = biit->second;
1008 refoutput += "[" + entry.label() + "] ";
1009 // FIXME Right now, we are calling BibInfo::getInfo on the key,
1010 // which will give us all the cross-referenced info. But for every
1011 // entry, so there's a lot of repitition. This should be fixed.
1012 refoutput += bibinfo.getInfo(entry.key(), buffer(), ci) + "\n\n";
1015 return int(refoutput.size());
1020 // docstring InsetBibtex::entriesAsXHTML(vector<docstring> const & entries)
1021 // And then here just: entriesAsXHTML(buffer().masterBibInfo().citedEntries())
1022 docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
1024 BiblioInfo const & bibinfo = buffer().masterBibInfo();
1025 bool const all_entries = getParam("btprint") == "btPrintAll";
1026 vector<docstring> const & cites =
1027 all_entries ? bibinfo.getKeys() : bibinfo.citedEntries();
1029 docstring const reflabel = buffer().B_("References");
1031 // tell BiblioInfo our purpose
1033 ci.context = CiteItem::Export;
1035 ci.max_key_size = UINT_MAX;
1037 xs << html::StartTag("h2", "class='bibtex'")
1039 << html::EndTag("h2")
1040 << html::StartTag("div", "class='bibtex'");
1042 // Now we loop over the entries
1043 vector<docstring>::const_iterator vit = cites.begin();
1044 vector<docstring>::const_iterator const ven = cites.end();
1045 for (; vit != ven; ++vit) {
1046 BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
1047 if (biit == bibinfo.end())
1050 BibTeXInfo const & entry = biit->second;
1051 string const attr = "class='bibtexentry' id='LyXCite-"
1052 + to_utf8(html::cleanAttr(entry.key())) + "'";
1053 xs << html::StartTag("div", attr);
1055 // don't print labels if we're outputting all entries
1057 xs << html::StartTag("span", "class='bibtexlabel'")
1059 << html::EndTag("span");
1062 // FIXME Right now, we are calling BibInfo::getInfo on the key,
1063 // which will give us all the cross-referenced info. But for every
1064 // entry, so there's a lot of repitition. This should be fixed.
1065 xs << html::StartTag("span", "class='bibtexinfo'")
1066 << XHTMLStream::ESCAPE_AND
1067 << bibinfo.getInfo(entry.key(), buffer(), ci)
1068 << html::EndTag("span")
1069 << html::EndTag("div")
1072 xs << html::EndTag("div");
1077 void InsetBibtex::write(ostream & os) const
1079 params().Write(os, &buffer());
1083 string InsetBibtex::contextMenuName() const
1085 return "context-bibtex";