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 string style = to_utf8(getParam("options")); // maybe empty! and with bibtotoc
271 if (prefixIs(style, "bibtotoc")) {
272 bibtotoc = "bibtotoc";
273 if (contains(style, ','))
274 style = split(style, bibtotoc, ',');
277 if (usingBiblatex()) {
279 string opts = to_utf8(getParam("biblatexopts"));
281 if (!bibtotoc.empty())
282 opts = opts.empty() ? "heading=bibintoc" : "heading=bibintoc," + opts;
283 // The bibliography command
284 docstring btprint = getParam("btprint");
285 if (btprint == "btPrintAll")
286 os << "\\nocite{*}\n";
287 if (btprint == "bibbysection" && !buffer().masterParams().multibib.empty())
288 os << "\\bibbysection";
290 os << "\\printbibliography";
292 os << "[" << opts << "]";
294 } else {// using BibTeX
296 vector<pair<docstring, string>> const dbs =
297 buffer().prepareBibFilePaths(runparams, getBibFiles(), false);
298 vector<docstring> db_out;
299 for (pair<docstring, string> const & db : dbs)
300 db_out.push_back(db.first);
302 if (style == "default")
303 style = buffer().masterParams().defaultBiblioStyle();
304 if (!style.empty() && !buffer().masterParams().useBibtopic()) {
305 string base = buffer().masterBuffer()->prepareFileNameForLaTeX(style, ".bst", runparams.nice);
306 FileName const try_in_file =
307 makeAbsPath(base + ".bst", buffer().filePath());
308 bool const not_from_texmf = try_in_file.isReadableFile();
309 // If this style does not come from texmf and we are not
310 // exporting to .tex copy it to the tmp directory.
311 // This prevents problems with spaces and 8bit characters
313 if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
315 // use new style name
316 DocFileName const in_file = DocFileName(try_in_file);
317 base = removeExtension(in_file.mangledFileName());
318 FileName const out_file = makeAbsPath(base + ".bst",
319 buffer().masterBuffer()->temppath());
320 bool const success = in_file.copyTo(out_file);
322 LYXERR0("Failed to copy '" << in_file
323 << "' to '" << out_file << "'");
327 os << "\\bibliographystyle{"
328 << from_utf8(latex_path(buffer().prepareFileNameForLaTeX(base, ".bst", runparams.nice)))
331 // Warn about spaces in bst path. Warn only once.
332 static bool warned_about_bst_spaces = false;
333 if (!warned_about_bst_spaces && runparams.nice && contains(style, ' ')) {
334 warned_about_bst_spaces = true;
335 Alert::warning(_("Export Warning!"),
336 _("There are spaces in the path to your BibTeX style file.\n"
337 "BibTeX will be unable to find it."));
340 bool encoding_switched = false;
341 Encoding const * const save_enc = runparams.encoding;
342 docstring const encoding = getParam("encoding");
343 if (!encoding.empty() && encoding != from_ascii("default")) {
344 Encoding const * const enc = encodings.fromLyXName(to_ascii(encoding));
345 if (enc != runparams.encoding) {
347 switchEncoding(os.os(), buffer().params(), runparams, *enc, true);
348 runparams.encoding = enc;
349 encoding_switched = true;
352 // Handle the bibtopic case
353 if (!db_out.empty() && buffer().masterParams().useBibtopic()) {
354 os << "\\begin{btSect}";
356 os << "[" << style << "]";
357 os << "{" << getStringFromVector(db_out) << "}\n";
358 docstring btprint = getParam("btprint");
361 btprint = from_ascii("btPrintCited");
362 os << "\\" << btprint << "\n"
363 << "\\end{btSect}\n";
366 if (!bibtotoc.empty() && !buffer().masterParams().useBibtopic()
367 && !buffer().masterParams().documentClass().bibInToc()) {
368 // set label for hyperref, see http://www.lyx.org/trac/ticket/6470
369 if (buffer().masterParams().pdfoptions().use_hyperref)
370 os << "\\phantomsection";
371 if (buffer().masterParams().documentClass().hasLaTeXLayout("chapter"))
372 os << "\\addcontentsline{toc}{chapter}{\\bibname}";
373 else if (buffer().masterParams().documentClass().hasLaTeXLayout("section"))
374 os << "\\addcontentsline{toc}{section}{\\refname}";
376 // The bibliography command
377 if (!db_out.empty() && !buffer().masterParams().useBibtopic()) {
378 docstring btprint = getParam("btprint");
379 if (btprint == "btPrintAll") {
380 os << "\\nocite{*}\n";
382 os << "\\bibliography{" << getStringFromVector(db_out) << "}\n";
384 if (encoding_switched){
386 switchEncoding(os.os(), buffer().params(),
387 runparams, *save_enc, true, true);
388 os << "\\egroup" << breakln;
389 runparams.encoding = save_enc;
395 docstring_list InsetBibtex::getBibFiles() const
397 return getVectorFromString(getParam("bibfiles"));
402 // methods for parsing bibtex files
404 typedef map<docstring, docstring> VarMap;
406 /// remove whitespace characters, optionally a single comma,
407 /// and further whitespace characters from the stream.
408 /// @return true if a comma was found, false otherwise
410 bool removeWSAndComma(ifdocstream & ifs) {
419 } while (ifs && isSpace(ch));
432 } while (ifs && isSpace(ch));
447 /// remove whitespace characters, read characer sequence
448 /// not containing whitespace characters or characters in
449 /// delimChars, and remove further whitespace characters.
451 /// @return true if a string of length > 0 could be read.
453 bool readTypeOrKey(docstring & val, ifdocstream & ifs,
454 docstring const & delimChars, docstring const & illegalChars,
467 } while (ifs && isSpace(ch));
473 while (ifs && !isSpace(ch) &&
474 delimChars.find(ch) == docstring::npos &&
475 illegalChars.find(ch) == docstring::npos)
477 if (chCase == makeLowerCase)
478 val += lowercase(ch);
484 if (illegalChars.find(ch) != docstring::npos) {
490 while (ifs && isSpace(ch)) {
498 return val.length() > 0;
501 /// read subsequent bibtex values that are delimited with a #-character.
502 /// Concatenate all parts and replace names with the associated string in
503 /// the variable strings.
504 /// @return true if reading was successfull (all single parts were delimited
506 bool readValue(docstring & val, ifdocstream & ifs, const VarMap & strings) {
519 } while (ifs && isSpace(ch));
524 // check for field type
525 if (isDigitASCII(ch)) {
527 // read integer value
531 } while (ifs && isDigitASCII(ch));
536 } else if (ch == '"' || ch == '{') {
538 char_type delim = ch == '"' ? '"': '}';
543 } while (ifs && isSpace(ch));
548 // We now have the first non-whitespace character
549 // We'll collapse adjacent whitespace.
550 bool lastWasWhiteSpace = false;
552 // inside this delimited text braces must match.
553 // Thus we can have a closing delimiter only
554 // when nestLevel == 0
557 while (ifs && (nestLevel > 0 || ch != delim)) {
559 lastWasWhiteSpace = true;
563 // We output the space only after we stop getting
564 // whitespace so as not to output any whitespace
565 // at the end of the value.
566 if (lastWasWhiteSpace) {
567 lastWasWhiteSpace = false;
573 // update nesting level
592 // FIXME Why is this here?
600 // reading a string name
603 while (ifs && !isSpace(ch) && ch != '#' && ch != ',' && ch != '}' && ch != ')') {
604 strName += lowercase(ch);
611 // replace the string with its assigned value or
612 // discard it if it's not assigned
613 if (strName.length()) {
614 VarMap::const_iterator pos = strings.find(strName);
615 if (pos != strings.end()) {
622 while (ifs && isSpace(ch)) {
629 // continue reading next value on concatenate with '#'
639 void InsetBibtex::collectBibKeys(InsetIterator const & /*di*/, FileNameList & checkedFiles) const
641 parseBibTeXFiles(checkedFiles);
645 void InsetBibtex::parseBibTeXFiles(FileNameList & checkedFiles) const
647 // This bibtex parser is a first step to parse bibtex files
650 // - it reads the whole bibtex entry and does a syntax check
651 // (matching delimiters, missing commas,...
652 // - it recovers from errors starting with the next @-character
653 // - it reads @string definitions and replaces them in the
655 // - it accepts more characters in keys or value names than
658 // Officially bibtex does only support ASCII, but in practice
659 // you can use any encoding as long as some elements like keys
660 // and names are pure ASCII. We support specifying an encoding,
661 // and we convert the file from that (default is buffer encoding).
662 // We don't restrict keys to ASCII in LyX, since our own
663 // InsetBibitem can generate non-ASCII keys, and nonstandard
664 // 8bit clean bibtex forks exist.
668 docstring_list const files = getBibFiles();
669 for (auto const & bf : files) {
670 FileName const bibfile = buffer().getBibfilePath(bf);
671 if (bibfile.empty()) {
672 LYXERR0("Unable to find path for " << bf << "!");
675 if (find(checkedFiles.begin(), checkedFiles.end(), bibfile) != checkedFiles.end())
676 // already checked this one. Skip.
679 // record that we check this.
680 checkedFiles.push_back(bibfile);
681 string encoding = buffer().masterParams().encoding().iconvName();
682 string ienc = buffer().masterParams().bibFileEncoding(to_utf8(bf));
683 if (ienc.empty() || ienc == "general")
684 ienc = to_ascii(params()["encoding"]);
686 if (!ienc.empty() && ienc != "auto-legacy-plain" && ienc != "auto-legacy" && encodings.fromLyXName(ienc))
687 encoding = encodings.fromLyXName(ienc)->iconvName();
688 ifdocstream ifs(bibfile.toFilesystemEncoding().c_str(),
689 ios_base::in, encoding);
704 if (!readTypeOrKey(entryType, ifs, from_ascii("{("), docstring(), makeLowerCase)) {
705 lyxerr << "BibTeX Parser: Error reading entry type." << std::endl;
710 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
714 if (entryType == from_ascii("comment")) {
715 ifs.ignore(numeric_limits<int>::max(), '\n');
721 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
725 if ((ch != '(') && (ch != '{')) {
726 lyxerr << "BibTeX Parser: Invalid entry delimiter." << std::endl;
732 if (entryType == from_ascii("string")) {
734 // read string and add it to the strings map
735 // (or replace it's old value)
739 if (!readTypeOrKey(name, ifs, from_ascii("="), from_ascii("#{}(),"), makeLowerCase)) {
740 lyxerr << "BibTeX Parser: Error reading string name." << std::endl;
745 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
749 // next char must be an equal sign
751 if (!ifs || ch != '=') {
752 lyxerr << "BibTeX Parser: No `=' after string name: " <<
753 name << "." << std::endl;
757 if (!readValue(value, ifs, strings)) {
758 lyxerr << "BibTeX Parser: Unable to read value for string: " <<
759 name << "." << std::endl;
763 strings[name] = value;
765 } else if (entryType == from_ascii("preamble")) {
767 // preamble definitions are discarded.
768 // can they be of any use in lyx?
771 if (!readValue(value, ifs, strings)) {
772 lyxerr << "BibTeX Parser: Unable to read preamble value." << std::endl;
778 // Citation entry. Try to read the key.
781 if (!readTypeOrKey(key, ifs, from_ascii(","), from_ascii("}"), keepCase)) {
782 lyxerr << "BibTeX Parser: Unable to read key for entry type:" <<
783 entryType << "." << std::endl;
788 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
792 /////////////////////////////////////////////
793 // now we have a key, so we will add an entry
794 // (even if it's empty, as bibtex does)
796 // we now read the field = value pairs.
797 // all items must be separated by a comma. If
798 // it is missing the scanning of this entry is
799 // stopped and the next is searched.
803 BibTeXInfo keyvalmap(key, entryType);
805 bool readNext = removeWSAndComma(ifs);
807 while (ifs && readNext) {
810 if (!readTypeOrKey(name, ifs, from_ascii("="),
811 from_ascii("{}(),"), makeLowerCase) || !ifs)
814 // next char must be an equal sign
815 // FIXME Whitespace??
818 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
822 lyxerr << "BibTeX Parser: Missing `=' after field name: " <<
823 name << ", for key: " << key << "." << std::endl;
829 if (!readValue(value, ifs, strings)) {
830 lyxerr << "BibTeX Parser: Unable to read value for field: " <<
831 name << ", for key: " << key << "." << std::endl;
835 keyvalmap[name] = value;
836 data += "\n\n" + value;
837 keylist.addFieldName(name);
838 readNext = removeWSAndComma(ifs);
842 keylist.addEntryType(entryType);
843 keyvalmap.setAllData(data);
844 keylist[key] = keyvalmap;
845 } //< else (citation entry)
847 } //< for loop over files
849 buffer().addBiblioInfo(keylist);
853 bool InsetBibtex::addDatabase(docstring const & db)
855 docstring bibfiles = getParam("bibfiles");
856 if (tokenPos(bibfiles, ',', db) != -1)
858 if (!bibfiles.empty())
860 setParam("bibfiles", bibfiles + db);
865 bool InsetBibtex::delDatabase(docstring const & db)
867 docstring bibfiles = getParam("bibfiles");
868 if (contains(bibfiles, db)) {
869 int const n = tokenPos(bibfiles, ',', db);
872 // this is not the first database
873 docstring tmp = ',' + bd;
874 setParam("bibfiles", subst(bibfiles, tmp, docstring()));
876 // this is the first (or only) database
877 setParam("bibfiles", split(bibfiles, bd, ','));
885 void InsetBibtex::validate(LaTeXFeatures & features) const
887 BufferParams const & mparams = features.buffer().masterParams();
888 if (mparams.useBibtopic())
889 features.require("bibtopic");
890 else if (!mparams.useBiblatex() && mparams.multibib == "child")
891 features.require("chapterbib");
893 // It'd be better to be able to get this from an InsetLayout, but at present
894 // InsetLayouts do not seem really to work for things that aren't InsetTexts.
895 if (features.runparams().flavor == OutputParams::HTML)
896 features.addCSSSnippet("div.bibtexentry { margin-left: 2em; text-indent: -2em; }\n"
897 "span.bibtexlabel:before{ content: \"[\"; }\n"
898 "span.bibtexlabel:after{ content: \"] \"; }");
902 void InsetBibtex::updateBuffer(ParIterator const &, UpdateType)
904 buffer().registerBibfiles(getBibFiles());
905 // record encoding of bib files for biblatex
906 string const enc = (params()["encoding"] == from_ascii("default")) ?
907 string() : to_ascii(params()["encoding"]);
908 bool invalidate = false;
909 if (buffer().params().bibEncoding() != enc) {
910 buffer().params().setBibEncoding(enc);
913 map<string, string> encs = getFileEncodings();
914 map<string, string>::const_iterator it = encs.begin();
915 for (; it != encs.end(); ++it) {
916 if (buffer().params().bibFileEncoding(it->first) != it->second) {
917 buffer().params().setBibFileEncoding(it->first, it->second);
922 buffer().invalidateBibinfoCache();
926 map<string, string> InsetBibtex::getFileEncodings() const
929 getVectorFromString(to_utf8(getParam("file_encodings")), "\t");
930 std::map<string, string> res;
931 for (string const & s: ps) {
933 string val = split(s, key, ' ');
940 docstring InsetBibtex::getRefLabel() const
942 if (buffer().masterParams().documentClass().hasLaTeXLayout("chapter"))
943 return buffer().B_("Bibliography");
944 return buffer().B_("References");
948 void InsetBibtex::addToToc(DocIterator const & cpit, bool output_active,
949 UpdateType, TocBackend & backend) const
951 if (!prefixIs(to_utf8(getParam("options")), "bibtotoc"))
954 docstring const str = getRefLabel();
955 TocBuilder & b = backend.builder("tableofcontents");
956 b.pushItem(cpit, str, output_active);
961 int InsetBibtex::plaintext(odocstringstream & os,
962 OutputParams const & op, size_t max_length) const
964 docstring const reflabel = getRefLabel();
966 // We could output more information here, e.g., what databases are included
967 // and information about options. But I don't necessarily see any reason to
968 // do this right now.
969 if (op.for_tooltip || op.for_toc || op.for_search) {
970 os << '[' << reflabel << ']' << '\n';
971 return PLAINTEXT_NEWLINE;
974 BiblioInfo bibinfo = buffer().masterBibInfo();
975 bibinfo.makeCitationLabels(buffer());
976 vector<docstring> const & cites = bibinfo.citedEntries();
978 size_t start_size = os.str().size();
980 refoutput += reflabel + "\n\n";
982 // Tell BiblioInfo our purpose
984 ci.context = CiteItem::Export;
986 // Now we loop over the entries
987 vector<docstring>::const_iterator vit = cites.begin();
988 vector<docstring>::const_iterator const ven = cites.end();
989 for (; vit != ven; ++vit) {
990 if (start_size + refoutput.size() >= max_length)
992 BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
993 if (biit == bibinfo.end())
995 BibTeXInfo const & entry = biit->second;
996 refoutput += "[" + entry.label() + "] ";
997 // FIXME Right now, we are calling BibInfo::getInfo on the key,
998 // which will give us all the cross-referenced info. But for every
999 // entry, so there's a lot of repitition. This should be fixed.
1000 refoutput += bibinfo.getInfo(entry.key(), buffer(), ci) + "\n\n";
1003 return int(refoutput.size());
1008 // docstring InsetBibtex::entriesAsXHTML(vector<docstring> const & entries)
1009 // And then here just: entriesAsXHTML(buffer().masterBibInfo().citedEntries())
1010 docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
1012 BiblioInfo const & bibinfo = buffer().masterBibInfo();
1013 bool const all_entries = getParam("btprint") == "btPrintAll";
1014 vector<docstring> const & cites =
1015 all_entries ? bibinfo.getKeys() : bibinfo.citedEntries();
1017 docstring const reflabel = buffer().B_("References");
1019 // tell BiblioInfo our purpose
1021 ci.context = CiteItem::Export;
1023 ci.max_key_size = UINT_MAX;
1025 xs << html::StartTag("h2", "class='bibtex'")
1027 << html::EndTag("h2")
1028 << html::StartTag("div", "class='bibtex'");
1030 // Now we loop over the entries
1031 vector<docstring>::const_iterator vit = cites.begin();
1032 vector<docstring>::const_iterator const ven = cites.end();
1033 for (; vit != ven; ++vit) {
1034 BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
1035 if (biit == bibinfo.end())
1038 BibTeXInfo const & entry = biit->second;
1039 string const attr = "class='bibtexentry' id='LyXCite-"
1040 + to_utf8(html::cleanAttr(entry.key())) + "'";
1041 xs << html::StartTag("div", attr);
1043 // don't print labels if we're outputting all entries
1045 xs << html::StartTag("span", "class='bibtexlabel'")
1047 << html::EndTag("span");
1050 // FIXME Right now, we are calling BibInfo::getInfo on the key,
1051 // which will give us all the cross-referenced info. But for every
1052 // entry, so there's a lot of repitition. This should be fixed.
1053 xs << html::StartTag("span", "class='bibtexinfo'")
1054 << XHTMLStream::ESCAPE_AND
1055 << bibinfo.getInfo(entry.key(), buffer(), ci)
1056 << html::EndTag("span")
1057 << html::EndTag("div")
1060 xs << html::EndTag("div");
1065 void InsetBibtex::write(ostream & os) const
1067 params().Write(os, &buffer());
1071 string InsetBibtex::contextMenuName() const
1073 return "context-bibtex";