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()) {
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() const
137 vector<docstring> bibfilelist = getVectorFromString(getParam("bibfiles"));
139 if (bibfilelist.empty())
142 size_t nr_databases = bibfilelist.size();
143 if (nr_databases > 1) {
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 FileName const bibfile = buffer().getBibfilePath(*it);
159 theFormats().edit(buffer(), bibfile,
160 theFormats().getFormatFromFile(bibfile));
165 bool InsetBibtex::usingBiblatex() const
167 return buffer().masterParams().useBiblatex();
171 docstring InsetBibtex::screenLabel() const
173 return usingBiblatex() ? _("Biblatex Generated Bibliography")
174 : _("BibTeX Generated Bibliography");
178 docstring InsetBibtex::toolTip(BufferView const & /*bv*/, int /*x*/, int /*y*/) const
180 docstring tip = _("Databases:");
181 vector<docstring> bibfilelist = getVectorFromString(getParam("bibfiles"));
184 if (bibfilelist.empty())
185 tip += "<li>" + _("none") + "</li>";
187 for (docstring const & bibfile : bibfilelist)
188 tip += "<li>" + bibfile + "</li>";
193 docstring style = getParam("options"); // maybe empty! and with bibtotoc
194 docstring bibtotoc = from_ascii("bibtotoc");
195 if (prefixIs(style, bibtotoc)) {
197 if (contains(style, char_type(',')))
198 style = split(style, bibtotoc, char_type(','));
201 docstring const btprint = getParam("btprint");
202 if (!usingBiblatex()) {
203 tip += _("Style File:");
204 tip += "<ul><li>" + (style.empty() ? _("none") : style) + "</li></ul>";
206 tip += _("Lists:") + " ";
207 if (btprint == "btPrintAll")
208 tip += _("all references");
209 else if (btprint == "btPrintNotCited")
210 tip += _("all uncited references");
212 tip += _("all cited references");
215 tip += _("included in TOC");
217 if (!buffer().parent()
218 && buffer().params().multibib == "child") {
220 tip += _("Note: This bibliography is not output, since bibliographies in the master file "
221 "are not allowed with the setting 'Multiple bibliographies per child document'");
224 tip += _("Lists:") + " ";
225 if (btprint == "bibbysection")
226 tip += _("all reference units");
227 else if (btprint == "btPrintAll")
228 tip += _("all references");
230 tip += _("all cited references");
233 tip += _("included in TOC");
235 if (!getParam("biblatexopts").empty()) {
237 tip += _("Options: ") + getParam("biblatexopts");
245 void InsetBibtex::latex(otexstream & os, OutputParams const & runparams) const
247 // The sequence of the commands:
248 // With normal BibTeX:
249 // 1. \bibliographystyle{style}
250 // 2. \addcontentsline{...} - if option bibtotoc set
251 // 3. \bibliography{database}
253 // 1. \bibliographystyle{style}
254 // 2. \begin{btSect}{database}
255 // 3. \btPrint{Cited|NotCited|All}
258 // \printbibliography[biblatexopts]
260 // \bibbysection[biblatexopts] - if btprint is "bibbysection"
262 // chapterbib does not allow bibliographies in the master
263 if (!usingBiblatex() && !runparams.is_child
264 && buffer().params().multibib == "child")
267 string style = to_utf8(getParam("options")); // maybe empty! and with bibtotoc
269 if (prefixIs(style, "bibtotoc")) {
270 bibtotoc = "bibtotoc";
271 if (contains(style, ','))
272 style = split(style, bibtotoc, ',');
275 if (usingBiblatex()) {
277 string opts = to_utf8(getParam("biblatexopts"));
279 if (!bibtotoc.empty())
280 opts = opts.empty() ? "heading=bibintoc" : "heading=bibintoc," + opts;
281 // The bibliography command
282 docstring btprint = getParam("btprint");
283 if (btprint == "btPrintAll")
284 os << "\\nocite{*}\n";
285 if (btprint == "bibbysection" && !buffer().masterParams().multibib.empty())
286 os << "\\bibbysection";
288 os << "\\printbibliography";
290 os << "[" << opts << "]";
292 } else {// using BibTeX
294 vector<pair<docstring, string>> const dbs =
295 buffer().prepareBibFilePaths(runparams, getBibFiles(), false);
296 vector<docstring> db_out;
297 for (pair<docstring, string> const & db : dbs)
298 db_out.push_back(db.first);
300 if (style == "default")
301 style = buffer().masterParams().defaultBiblioStyle();
302 if (!style.empty() && !buffer().masterParams().useBibtopic()) {
303 string base = buffer().masterBuffer()->prepareFileNameForLaTeX(style, ".bst", runparams.nice);
304 FileName const try_in_file =
305 makeAbsPath(base + ".bst", buffer().filePath());
306 bool const not_from_texmf = try_in_file.isReadableFile();
307 // If this style does not come from texmf and we are not
308 // exporting to .tex copy it to the tmp directory.
309 // This prevents problems with spaces and 8bit characters
311 if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
313 // use new style name
314 DocFileName const in_file = DocFileName(try_in_file);
315 base = removeExtension(in_file.mangledFileName());
316 FileName const out_file = makeAbsPath(base + ".bst",
317 buffer().masterBuffer()->temppath());
318 bool const success = in_file.copyTo(out_file);
320 LYXERR0("Failed to copy '" << in_file
321 << "' to '" << out_file << "'");
325 os << "\\bibliographystyle{"
326 << from_utf8(latex_path(buffer().prepareFileNameForLaTeX(base, ".bst", runparams.nice)))
329 // Warn about spaces in bst path. Warn only once.
330 static bool warned_about_bst_spaces = false;
331 if (!warned_about_bst_spaces && runparams.nice && contains(style, ' ')) {
332 warned_about_bst_spaces = true;
333 Alert::warning(_("Export Warning!"),
334 _("There are spaces in the path to your BibTeX style file.\n"
335 "BibTeX will be unable to find it."));
338 bool encoding_switched = false;
339 Encoding const * const save_enc = runparams.encoding;
340 docstring const encoding = getParam("encoding");
341 if (!encoding.empty() && encoding != from_ascii("default")) {
342 Encoding const * const enc = encodings.fromLyXName(to_ascii(encoding));
343 if (enc != runparams.encoding) {
345 switchEncoding(os.os(), buffer().params(), runparams, *enc, true);
346 runparams.encoding = enc;
347 encoding_switched = true;
350 // Handle the bibtopic case
351 if (!db_out.empty() && buffer().masterParams().useBibtopic()) {
352 os << "\\begin{btSect}";
354 os << "[" << style << "]";
355 os << "{" << getStringFromVector(db_out) << "}\n";
356 docstring btprint = getParam("btprint");
359 btprint = from_ascii("btPrintCited");
360 os << "\\" << btprint << "\n"
361 << "\\end{btSect}\n";
364 if (!bibtotoc.empty() && !buffer().masterParams().useBibtopic()) {
365 // set label for hyperref, see http://www.lyx.org/trac/ticket/6470
366 if (buffer().masterParams().pdfoptions().use_hyperref)
367 os << "\\phantomsection";
368 if (buffer().masterParams().documentClass().hasLaTeXLayout("chapter"))
369 os << "\\addcontentsline{toc}{chapter}{\\bibname}";
370 else if (buffer().masterParams().documentClass().hasLaTeXLayout("section"))
371 os << "\\addcontentsline{toc}{section}{\\refname}";
373 // The bibliography command
374 if (!db_out.empty() && !buffer().masterParams().useBibtopic()) {
375 docstring btprint = getParam("btprint");
376 if (btprint == "btPrintAll") {
377 os << "\\nocite{*}\n";
379 os << "\\bibliography{" << getStringFromVector(db_out) << "}\n";
381 if (encoding_switched){
383 switchEncoding(os.os(), buffer().params(),
384 runparams, *save_enc, true, true);
385 os << "\\egroup" << breakln;
386 runparams.encoding = save_enc;
392 docstring_list InsetBibtex::getBibFiles() const
394 return getVectorFromString(getParam("bibfiles"));
399 // methods for parsing bibtex files
401 typedef map<docstring, docstring> VarMap;
403 /// remove whitespace characters, optionally a single comma,
404 /// and further whitespace characters from the stream.
405 /// @return true if a comma was found, false otherwise
407 bool removeWSAndComma(ifdocstream & ifs) {
416 } while (ifs && isSpace(ch));
429 } while (ifs && isSpace(ch));
444 /// remove whitespace characters, read characer sequence
445 /// not containing whitespace characters or characters in
446 /// delimChars, and remove further whitespace characters.
448 /// @return true if a string of length > 0 could be read.
450 bool readTypeOrKey(docstring & val, ifdocstream & ifs,
451 docstring const & delimChars, docstring const & illegalChars,
464 } while (ifs && isSpace(ch));
470 while (ifs && !isSpace(ch) &&
471 delimChars.find(ch) == docstring::npos &&
472 illegalChars.find(ch) == docstring::npos)
474 if (chCase == makeLowerCase)
475 val += lowercase(ch);
481 if (illegalChars.find(ch) != docstring::npos) {
487 while (ifs && isSpace(ch)) {
495 return val.length() > 0;
498 /// read subsequent bibtex values that are delimited with a #-character.
499 /// Concatenate all parts and replace names with the associated string in
500 /// the variable strings.
501 /// @return true if reading was successfull (all single parts were delimited
503 bool readValue(docstring & val, ifdocstream & ifs, const VarMap & strings) {
516 } while (ifs && isSpace(ch));
521 // check for field type
522 if (isDigitASCII(ch)) {
524 // read integer value
528 } while (ifs && isDigitASCII(ch));
533 } else if (ch == '"' || ch == '{') {
535 char_type delim = ch == '"' ? '"': '}';
540 } while (ifs && isSpace(ch));
545 // We now have the first non-whitespace character
546 // We'll collapse adjacent whitespace.
547 bool lastWasWhiteSpace = false;
549 // inside this delimited text braces must match.
550 // Thus we can have a closing delimiter only
551 // when nestLevel == 0
554 while (ifs && (nestLevel > 0 || ch != delim)) {
556 lastWasWhiteSpace = true;
560 // We output the space only after we stop getting
561 // whitespace so as not to output any whitespace
562 // at the end of the value.
563 if (lastWasWhiteSpace) {
564 lastWasWhiteSpace = false;
570 // update nesting level
589 // FIXME Why is this here?
597 // reading a string name
600 while (ifs && !isSpace(ch) && ch != '#' && ch != ',' && ch != '}' && ch != ')') {
601 strName += lowercase(ch);
608 // replace the string with its assigned value or
609 // discard it if it's not assigned
610 if (strName.length()) {
611 VarMap::const_iterator pos = strings.find(strName);
612 if (pos != strings.end()) {
619 while (ifs && isSpace(ch)) {
626 // continue reading next value on concatenate with '#'
636 void InsetBibtex::collectBibKeys(InsetIterator const & /*di*/, FileNameList & checkedFiles) const
638 parseBibTeXFiles(checkedFiles);
642 void InsetBibtex::parseBibTeXFiles(FileNameList & checkedFiles) const
644 // This bibtex parser is a first step to parse bibtex files
647 // - it reads the whole bibtex entry and does a syntax check
648 // (matching delimiters, missing commas,...
649 // - it recovers from errors starting with the next @-character
650 // - it reads @string definitions and replaces them in the
652 // - it accepts more characters in keys or value names than
655 // Officially bibtex does only support ASCII, but in practice
656 // you can use any encoding as long as some elements like keys
657 // and names are pure ASCII. We support specifying an encoding,
658 // and we convert the file from that (default is buffer encoding).
659 // We don't restrict keys to ASCII in LyX, since our own
660 // InsetBibitem can generate non-ASCII keys, and nonstandard
661 // 8bit clean bibtex forks exist.
665 docstring_list const files = getBibFiles();
666 for (auto const & bf : files) {
667 FileName const bibfile = buffer().getBibfilePath(bf);
668 if (bibfile.empty()) {
669 LYXERR0("Unable to find path for " << bf << "!");
672 if (find(checkedFiles.begin(), checkedFiles.end(), bibfile) != checkedFiles.end())
673 // already checked this one. Skip.
676 // record that we check this.
677 checkedFiles.push_back(bibfile);
678 string encoding = buffer().masterParams().encoding().iconvName();
679 string ienc = buffer().masterParams().bibFileEncoding(to_utf8(bf));
680 if (ienc.empty() || ienc == "general")
681 ienc = to_ascii(params()["encoding"]);
683 if (!ienc.empty() && ienc != "default" && ienc != "auto" && encodings.fromLyXName(ienc))
684 encoding = encodings.fromLyXName(ienc)->iconvName();
685 ifdocstream ifs(bibfile.toFilesystemEncoding().c_str(),
686 ios_base::in, encoding);
701 if (!readTypeOrKey(entryType, ifs, from_ascii("{("), docstring(), makeLowerCase)) {
702 lyxerr << "BibTeX Parser: Error reading entry type." << std::endl;
707 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
711 if (entryType == from_ascii("comment")) {
712 ifs.ignore(numeric_limits<int>::max(), '\n');
718 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
722 if ((ch != '(') && (ch != '{')) {
723 lyxerr << "BibTeX Parser: Invalid entry delimiter." << std::endl;
729 if (entryType == from_ascii("string")) {
731 // read string and add it to the strings map
732 // (or replace it's old value)
736 if (!readTypeOrKey(name, ifs, from_ascii("="), from_ascii("#{}(),"), makeLowerCase)) {
737 lyxerr << "BibTeX Parser: Error reading string name." << std::endl;
742 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
746 // next char must be an equal sign
748 if (!ifs || ch != '=') {
749 lyxerr << "BibTeX Parser: No `=' after string name: " <<
750 name << "." << std::endl;
754 if (!readValue(value, ifs, strings)) {
755 lyxerr << "BibTeX Parser: Unable to read value for string: " <<
756 name << "." << std::endl;
760 strings[name] = value;
762 } else if (entryType == from_ascii("preamble")) {
764 // preamble definitions are discarded.
765 // can they be of any use in lyx?
768 if (!readValue(value, ifs, strings)) {
769 lyxerr << "BibTeX Parser: Unable to read preamble value." << std::endl;
775 // Citation entry. Try to read the key.
778 if (!readTypeOrKey(key, ifs, from_ascii(","), from_ascii("}"), keepCase)) {
779 lyxerr << "BibTeX Parser: Unable to read key for entry type:" <<
780 entryType << "." << std::endl;
785 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
789 /////////////////////////////////////////////
790 // now we have a key, so we will add an entry
791 // (even if it's empty, as bibtex does)
793 // we now read the field = value pairs.
794 // all items must be separated by a comma. If
795 // it is missing the scanning of this entry is
796 // stopped and the next is searched.
800 BibTeXInfo keyvalmap(key, entryType);
802 bool readNext = removeWSAndComma(ifs);
804 while (ifs && readNext) {
807 if (!readTypeOrKey(name, ifs, from_ascii("="),
808 from_ascii("{}(),"), makeLowerCase) || !ifs)
811 // next char must be an equal sign
812 // FIXME Whitespace??
815 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
819 lyxerr << "BibTeX Parser: Missing `=' after field name: " <<
820 name << ", for key: " << key << "." << std::endl;
826 if (!readValue(value, ifs, strings)) {
827 lyxerr << "BibTeX Parser: Unable to read value for field: " <<
828 name << ", for key: " << key << "." << std::endl;
832 keyvalmap[name] = value;
833 data += "\n\n" + value;
834 keylist.addFieldName(name);
835 readNext = removeWSAndComma(ifs);
839 keylist.addEntryType(entryType);
840 keyvalmap.setAllData(data);
841 keylist[key] = keyvalmap;
842 } //< else (citation entry)
844 } //< for loop over files
846 buffer().addBiblioInfo(keylist);
850 bool InsetBibtex::addDatabase(docstring const & db)
852 docstring bibfiles = getParam("bibfiles");
853 if (tokenPos(bibfiles, ',', db) != -1)
855 if (!bibfiles.empty())
857 setParam("bibfiles", bibfiles + db);
862 bool InsetBibtex::delDatabase(docstring const & db)
864 docstring bibfiles = getParam("bibfiles");
865 if (contains(bibfiles, db)) {
866 int const n = tokenPos(bibfiles, ',', db);
869 // this is not the first database
870 docstring tmp = ',' + bd;
871 setParam("bibfiles", subst(bibfiles, tmp, docstring()));
873 // this is the first (or only) database
874 setParam("bibfiles", split(bibfiles, bd, ','));
882 void InsetBibtex::validate(LaTeXFeatures & features) const
884 BufferParams const & mparams = features.buffer().masterParams();
885 if (mparams.useBibtopic())
886 features.require("bibtopic");
887 else if (!mparams.useBiblatex() && mparams.multibib == "child")
888 features.require("chapterbib");
890 // It'd be better to be able to get this from an InsetLayout, but at present
891 // InsetLayouts do not seem really to work for things that aren't InsetTexts.
892 if (features.runparams().flavor == OutputParams::HTML)
893 features.addCSSSnippet("div.bibtexentry { margin-left: 2em; text-indent: -2em; }\n"
894 "span.bibtexlabel:before{ content: \"[\"; }\n"
895 "span.bibtexlabel:after{ content: \"] \"; }");
899 void InsetBibtex::updateBuffer(ParIterator const &, UpdateType)
901 buffer().registerBibfiles(getBibFiles());
902 // record encoding of bib files for biblatex
903 string const enc = (params()["encoding"] == from_ascii("default")) ?
904 string() : to_ascii(params()["encoding"]);
905 bool invalidate = false;
906 if (buffer().params().bibEncoding() != enc) {
907 buffer().params().setBibEncoding(enc);
910 map<string, string> encs = getFileEncodings();
911 map<string, string>::const_iterator it = encs.begin();
912 for (; it != encs.end(); ++it) {
913 if (buffer().params().bibFileEncoding(it->first) != it->second) {
914 buffer().params().setBibFileEncoding(it->first, it->second);
919 buffer().invalidateBibinfoCache();
923 map<string, string> InsetBibtex::getFileEncodings() const
926 getVectorFromString(to_utf8(getParam("file_encodings")), "\t");
927 std::map<string, string> res;
928 for (string const & s: ps) {
930 string val = split(s, key, ' ');
937 docstring InsetBibtex::getRefLabel() const
939 if (buffer().masterParams().documentClass().hasLaTeXLayout("chapter"))
940 return buffer().B_("Bibliography");
941 return buffer().B_("References");
945 void InsetBibtex::addToToc(DocIterator const & cpit, bool output_active,
946 UpdateType, TocBackend & backend) const
948 if (!prefixIs(to_utf8(getParam("options")), "bibtotoc"))
951 docstring const str = getRefLabel();
952 TocBuilder & b = backend.builder("tableofcontents");
953 b.pushItem(cpit, str, output_active);
958 int InsetBibtex::plaintext(odocstringstream & os,
959 OutputParams const & op, size_t max_length) const
961 docstring const reflabel = getRefLabel();
963 // We could output more information here, e.g., what databases are included
964 // and information about options. But I don't necessarily see any reason to
965 // do this right now.
966 if (op.for_tooltip || op.for_toc || op.for_search) {
967 os << '[' << reflabel << ']' << '\n';
968 return PLAINTEXT_NEWLINE;
971 BiblioInfo bibinfo = buffer().masterBibInfo();
972 bibinfo.makeCitationLabels(buffer());
973 vector<docstring> const & cites = bibinfo.citedEntries();
975 size_t start_size = os.str().size();
977 refoutput += reflabel + "\n\n";
979 // Tell BiblioInfo our purpose
981 ci.context = CiteItem::Export;
983 // Now we loop over the entries
984 vector<docstring>::const_iterator vit = cites.begin();
985 vector<docstring>::const_iterator const ven = cites.end();
986 for (; vit != ven; ++vit) {
987 if (start_size + refoutput.size() >= max_length)
989 BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
990 if (biit == bibinfo.end())
992 BibTeXInfo const & entry = biit->second;
993 refoutput += "[" + entry.label() + "] ";
994 // FIXME Right now, we are calling BibInfo::getInfo on the key,
995 // which will give us all the cross-referenced info. But for every
996 // entry, so there's a lot of repitition. This should be fixed.
997 refoutput += bibinfo.getInfo(entry.key(), buffer(), ci) + "\n\n";
1000 return int(refoutput.size());
1005 // docstring InsetBibtex::entriesAsXHTML(vector<docstring> const & entries)
1006 // And then here just: entriesAsXHTML(buffer().masterBibInfo().citedEntries())
1007 docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
1009 BiblioInfo const & bibinfo = buffer().masterBibInfo();
1010 bool const all_entries = getParam("btprint") == "btPrintAll";
1011 vector<docstring> const & cites =
1012 all_entries ? bibinfo.getKeys() : bibinfo.citedEntries();
1014 docstring const reflabel = buffer().B_("References");
1016 // tell BiblioInfo our purpose
1018 ci.context = CiteItem::Export;
1020 ci.max_key_size = UINT_MAX;
1022 xs << html::StartTag("h2", "class='bibtex'")
1024 << html::EndTag("h2")
1025 << html::StartTag("div", "class='bibtex'");
1027 // Now we loop over the entries
1028 vector<docstring>::const_iterator vit = cites.begin();
1029 vector<docstring>::const_iterator const ven = cites.end();
1030 for (; vit != ven; ++vit) {
1031 BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
1032 if (biit == bibinfo.end())
1035 BibTeXInfo const & entry = biit->second;
1036 string const attr = "class='bibtexentry' id='LyXCite-"
1037 + to_utf8(html::cleanAttr(entry.key())) + "'";
1038 xs << html::StartTag("div", attr);
1040 // don't print labels if we're outputting all entries
1042 xs << html::StartTag("span", "class='bibtexlabel'")
1044 << html::EndTag("span");
1047 // FIXME Right now, we are calling BibInfo::getInfo on the key,
1048 // which will give us all the cross-referenced info. But for every
1049 // entry, so there's a lot of repitition. This should be fixed.
1050 xs << html::StartTag("span", "class='bibtexinfo'")
1051 << XHTMLStream::ESCAPE_AND
1052 << bibinfo.getInfo(entry.key(), buffer(), ci)
1053 << html::EndTag("span")
1054 << html::EndTag("div")
1057 xs << html::EndTag("div");
1062 void InsetBibtex::write(ostream & os) const
1064 params().Write(os, &buffer());
1068 string InsetBibtex::contextMenuName() const
1070 return "context-bibtex";