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 // set label for hyperref, see http://www.lyx.org/trac/ticket/6470
368 if (buffer().masterParams().pdfoptions().use_hyperref)
369 os << "\\phantomsection";
370 if (buffer().masterParams().documentClass().hasLaTeXLayout("chapter"))
371 os << "\\addcontentsline{toc}{chapter}{\\bibname}";
372 else if (buffer().masterParams().documentClass().hasLaTeXLayout("section"))
373 os << "\\addcontentsline{toc}{section}{\\refname}";
375 // The bibliography command
376 if (!db_out.empty() && !buffer().masterParams().useBibtopic()) {
377 docstring btprint = getParam("btprint");
378 if (btprint == "btPrintAll") {
379 os << "\\nocite{*}\n";
381 os << "\\bibliography{" << getStringFromVector(db_out) << "}\n";
383 if (encoding_switched){
385 switchEncoding(os.os(), buffer().params(),
386 runparams, *save_enc, true, true);
387 os << "\\egroup" << breakln;
388 runparams.encoding = save_enc;
394 docstring_list InsetBibtex::getBibFiles() const
396 return getVectorFromString(getParam("bibfiles"));
401 // methods for parsing bibtex files
403 typedef map<docstring, docstring> VarMap;
405 /// remove whitespace characters, optionally a single comma,
406 /// and further whitespace characters from the stream.
407 /// @return true if a comma was found, false otherwise
409 bool removeWSAndComma(ifdocstream & ifs) {
418 } while (ifs && isSpace(ch));
431 } while (ifs && isSpace(ch));
446 /// remove whitespace characters, read characer sequence
447 /// not containing whitespace characters or characters in
448 /// delimChars, and remove further whitespace characters.
450 /// @return true if a string of length > 0 could be read.
452 bool readTypeOrKey(docstring & val, ifdocstream & ifs,
453 docstring const & delimChars, docstring const & illegalChars,
466 } while (ifs && isSpace(ch));
472 while (ifs && !isSpace(ch) &&
473 delimChars.find(ch) == docstring::npos &&
474 illegalChars.find(ch) == docstring::npos)
476 if (chCase == makeLowerCase)
477 val += lowercase(ch);
483 if (illegalChars.find(ch) != docstring::npos) {
489 while (ifs && isSpace(ch)) {
497 return val.length() > 0;
500 /// read subsequent bibtex values that are delimited with a #-character.
501 /// Concatenate all parts and replace names with the associated string in
502 /// the variable strings.
503 /// @return true if reading was successfull (all single parts were delimited
505 bool readValue(docstring & val, ifdocstream & ifs, const VarMap & strings) {
518 } while (ifs && isSpace(ch));
523 // check for field type
524 if (isDigitASCII(ch)) {
526 // read integer value
530 } while (ifs && isDigitASCII(ch));
535 } else if (ch == '"' || ch == '{') {
537 char_type delim = ch == '"' ? '"': '}';
542 } while (ifs && isSpace(ch));
547 // We now have the first non-whitespace character
548 // We'll collapse adjacent whitespace.
549 bool lastWasWhiteSpace = false;
551 // inside this delimited text braces must match.
552 // Thus we can have a closing delimiter only
553 // when nestLevel == 0
556 while (ifs && (nestLevel > 0 || ch != delim)) {
558 lastWasWhiteSpace = true;
562 // We output the space only after we stop getting
563 // whitespace so as not to output any whitespace
564 // at the end of the value.
565 if (lastWasWhiteSpace) {
566 lastWasWhiteSpace = false;
572 // update nesting level
591 // FIXME Why is this here?
599 // reading a string name
602 while (ifs && !isSpace(ch) && ch != '#' && ch != ',' && ch != '}' && ch != ')') {
603 strName += lowercase(ch);
610 // replace the string with its assigned value or
611 // discard it if it's not assigned
612 if (strName.length()) {
613 VarMap::const_iterator pos = strings.find(strName);
614 if (pos != strings.end()) {
621 while (ifs && isSpace(ch)) {
628 // continue reading next value on concatenate with '#'
638 void InsetBibtex::collectBibKeys(InsetIterator const & /*di*/, FileNameList & checkedFiles) const
640 parseBibTeXFiles(checkedFiles);
644 void InsetBibtex::parseBibTeXFiles(FileNameList & checkedFiles) const
646 // This bibtex parser is a first step to parse bibtex files
649 // - it reads the whole bibtex entry and does a syntax check
650 // (matching delimiters, missing commas,...
651 // - it recovers from errors starting with the next @-character
652 // - it reads @string definitions and replaces them in the
654 // - it accepts more characters in keys or value names than
657 // Officially bibtex does only support ASCII, but in practice
658 // you can use any encoding as long as some elements like keys
659 // and names are pure ASCII. We support specifying an encoding,
660 // and we convert the file from that (default is buffer encoding).
661 // We don't restrict keys to ASCII in LyX, since our own
662 // InsetBibitem can generate non-ASCII keys, and nonstandard
663 // 8bit clean bibtex forks exist.
667 docstring_list const files = getBibFiles();
668 for (auto const & bf : files) {
669 FileName const bibfile = buffer().getBibfilePath(bf);
670 if (bibfile.empty()) {
671 LYXERR0("Unable to find path for " << bf << "!");
674 if (find(checkedFiles.begin(), checkedFiles.end(), bibfile) != checkedFiles.end())
675 // already checked this one. Skip.
678 // record that we check this.
679 checkedFiles.push_back(bibfile);
680 string encoding = buffer().masterParams().encoding().iconvName();
681 string ienc = buffer().masterParams().bibFileEncoding(to_utf8(bf));
682 if (ienc.empty() || ienc == "general")
683 ienc = to_ascii(params()["encoding"]);
685 if (!ienc.empty() && ienc != "auto-legacy-plain" && ienc != "auto-legacy" && encodings.fromLyXName(ienc))
686 encoding = encodings.fromLyXName(ienc)->iconvName();
687 ifdocstream ifs(bibfile.toFilesystemEncoding().c_str(),
688 ios_base::in, encoding);
703 if (!readTypeOrKey(entryType, ifs, from_ascii("{("), docstring(), makeLowerCase)) {
704 lyxerr << "BibTeX Parser: Error reading entry type." << std::endl;
709 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
713 if (entryType == from_ascii("comment")) {
714 ifs.ignore(numeric_limits<int>::max(), '\n');
720 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
724 if ((ch != '(') && (ch != '{')) {
725 lyxerr << "BibTeX Parser: Invalid entry delimiter." << std::endl;
731 if (entryType == from_ascii("string")) {
733 // read string and add it to the strings map
734 // (or replace it's old value)
738 if (!readTypeOrKey(name, ifs, from_ascii("="), from_ascii("#{}(),"), makeLowerCase)) {
739 lyxerr << "BibTeX Parser: Error reading string name." << std::endl;
744 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
748 // next char must be an equal sign
750 if (!ifs || ch != '=') {
751 lyxerr << "BibTeX Parser: No `=' after string name: " <<
752 name << "." << std::endl;
756 if (!readValue(value, ifs, strings)) {
757 lyxerr << "BibTeX Parser: Unable to read value for string: " <<
758 name << "." << std::endl;
762 strings[name] = value;
764 } else if (entryType == from_ascii("preamble")) {
766 // preamble definitions are discarded.
767 // can they be of any use in lyx?
770 if (!readValue(value, ifs, strings)) {
771 lyxerr << "BibTeX Parser: Unable to read preamble value." << std::endl;
777 // Citation entry. Try to read the key.
780 if (!readTypeOrKey(key, ifs, from_ascii(","), from_ascii("}"), keepCase)) {
781 lyxerr << "BibTeX Parser: Unable to read key for entry type:" <<
782 entryType << "." << std::endl;
787 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
791 /////////////////////////////////////////////
792 // now we have a key, so we will add an entry
793 // (even if it's empty, as bibtex does)
795 // we now read the field = value pairs.
796 // all items must be separated by a comma. If
797 // it is missing the scanning of this entry is
798 // stopped and the next is searched.
802 BibTeXInfo keyvalmap(key, entryType);
804 bool readNext = removeWSAndComma(ifs);
806 while (ifs && readNext) {
809 if (!readTypeOrKey(name, ifs, from_ascii("="),
810 from_ascii("{}(),"), makeLowerCase) || !ifs)
813 // next char must be an equal sign
814 // FIXME Whitespace??
817 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
821 lyxerr << "BibTeX Parser: Missing `=' after field name: " <<
822 name << ", for key: " << key << "." << std::endl;
828 if (!readValue(value, ifs, strings)) {
829 lyxerr << "BibTeX Parser: Unable to read value for field: " <<
830 name << ", for key: " << key << "." << std::endl;
834 keyvalmap[name] = value;
835 data += "\n\n" + value;
836 keylist.addFieldName(name);
837 readNext = removeWSAndComma(ifs);
841 keylist.addEntryType(entryType);
842 keyvalmap.setAllData(data);
843 keylist[key] = keyvalmap;
844 } //< else (citation entry)
846 } //< for loop over files
848 buffer().addBiblioInfo(keylist);
852 bool InsetBibtex::addDatabase(docstring const & db)
854 docstring bibfiles = getParam("bibfiles");
855 if (tokenPos(bibfiles, ',', db) != -1)
857 if (!bibfiles.empty())
859 setParam("bibfiles", bibfiles + db);
864 bool InsetBibtex::delDatabase(docstring const & db)
866 docstring bibfiles = getParam("bibfiles");
867 if (contains(bibfiles, db)) {
868 int const n = tokenPos(bibfiles, ',', db);
871 // this is not the first database
872 docstring tmp = ',' + bd;
873 setParam("bibfiles", subst(bibfiles, tmp, docstring()));
875 // this is the first (or only) database
876 setParam("bibfiles", split(bibfiles, bd, ','));
884 void InsetBibtex::validate(LaTeXFeatures & features) const
886 BufferParams const & mparams = features.buffer().masterParams();
887 if (mparams.useBibtopic())
888 features.require("bibtopic");
889 else if (!mparams.useBiblatex() && mparams.multibib == "child")
890 features.require("chapterbib");
892 // It'd be better to be able to get this from an InsetLayout, but at present
893 // InsetLayouts do not seem really to work for things that aren't InsetTexts.
894 if (features.runparams().flavor == OutputParams::HTML)
895 features.addCSSSnippet("div.bibtexentry { margin-left: 2em; text-indent: -2em; }\n"
896 "span.bibtexlabel:before{ content: \"[\"; }\n"
897 "span.bibtexlabel:after{ content: \"] \"; }");
901 void InsetBibtex::updateBuffer(ParIterator const &, UpdateType)
903 buffer().registerBibfiles(getBibFiles());
904 // record encoding of bib files for biblatex
905 string const enc = (params()["encoding"] == from_ascii("default")) ?
906 string() : to_ascii(params()["encoding"]);
907 bool invalidate = false;
908 if (buffer().params().bibEncoding() != enc) {
909 buffer().params().setBibEncoding(enc);
912 map<string, string> encs = getFileEncodings();
913 map<string, string>::const_iterator it = encs.begin();
914 for (; it != encs.end(); ++it) {
915 if (buffer().params().bibFileEncoding(it->first) != it->second) {
916 buffer().params().setBibFileEncoding(it->first, it->second);
921 buffer().invalidateBibinfoCache();
925 map<string, string> InsetBibtex::getFileEncodings() const
928 getVectorFromString(to_utf8(getParam("file_encodings")), "\t");
929 std::map<string, string> res;
930 for (string const & s: ps) {
932 string val = split(s, key, ' ');
939 docstring InsetBibtex::getRefLabel() const
941 if (buffer().masterParams().documentClass().hasLaTeXLayout("chapter"))
942 return buffer().B_("Bibliography");
943 return buffer().B_("References");
947 void InsetBibtex::addToToc(DocIterator const & cpit, bool output_active,
948 UpdateType, TocBackend & backend) const
950 if (!prefixIs(to_utf8(getParam("options")), "bibtotoc"))
953 docstring const str = getRefLabel();
954 TocBuilder & b = backend.builder("tableofcontents");
955 b.pushItem(cpit, str, output_active);
960 int InsetBibtex::plaintext(odocstringstream & os,
961 OutputParams const & op, size_t max_length) const
963 docstring const reflabel = getRefLabel();
965 // We could output more information here, e.g., what databases are included
966 // and information about options. But I don't necessarily see any reason to
967 // do this right now.
968 if (op.for_tooltip || op.for_toc || op.for_search) {
969 os << '[' << reflabel << ']' << '\n';
970 return PLAINTEXT_NEWLINE;
973 BiblioInfo bibinfo = buffer().masterBibInfo();
974 bibinfo.makeCitationLabels(buffer());
975 vector<docstring> const & cites = bibinfo.citedEntries();
977 size_t start_size = os.str().size();
979 refoutput += reflabel + "\n\n";
981 // Tell BiblioInfo our purpose
983 ci.context = CiteItem::Export;
985 // Now we loop over the entries
986 vector<docstring>::const_iterator vit = cites.begin();
987 vector<docstring>::const_iterator const ven = cites.end();
988 for (; vit != ven; ++vit) {
989 if (start_size + refoutput.size() >= max_length)
991 BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
992 if (biit == bibinfo.end())
994 BibTeXInfo const & entry = biit->second;
995 refoutput += "[" + entry.label() + "] ";
996 // FIXME Right now, we are calling BibInfo::getInfo on the key,
997 // which will give us all the cross-referenced info. But for every
998 // entry, so there's a lot of repitition. This should be fixed.
999 refoutput += bibinfo.getInfo(entry.key(), buffer(), ci) + "\n\n";
1002 return int(refoutput.size());
1007 // docstring InsetBibtex::entriesAsXHTML(vector<docstring> const & entries)
1008 // And then here just: entriesAsXHTML(buffer().masterBibInfo().citedEntries())
1009 docstring InsetBibtex::xhtml(XHTMLStream & xs, OutputParams const &) const
1011 BiblioInfo const & bibinfo = buffer().masterBibInfo();
1012 bool const all_entries = getParam("btprint") == "btPrintAll";
1013 vector<docstring> const & cites =
1014 all_entries ? bibinfo.getKeys() : bibinfo.citedEntries();
1016 docstring const reflabel = buffer().B_("References");
1018 // tell BiblioInfo our purpose
1020 ci.context = CiteItem::Export;
1022 ci.max_key_size = UINT_MAX;
1024 xs << html::StartTag("h2", "class='bibtex'")
1026 << html::EndTag("h2")
1027 << html::StartTag("div", "class='bibtex'");
1029 // Now we loop over the entries
1030 vector<docstring>::const_iterator vit = cites.begin();
1031 vector<docstring>::const_iterator const ven = cites.end();
1032 for (; vit != ven; ++vit) {
1033 BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
1034 if (biit == bibinfo.end())
1037 BibTeXInfo const & entry = biit->second;
1038 string const attr = "class='bibtexentry' id='LyXCite-"
1039 + to_utf8(html::cleanAttr(entry.key())) + "'";
1040 xs << html::StartTag("div", attr);
1042 // don't print labels if we're outputting all entries
1044 xs << html::StartTag("span", "class='bibtexlabel'")
1046 << html::EndTag("span");
1049 // FIXME Right now, we are calling BibInfo::getInfo on the key,
1050 // which will give us all the cross-referenced info. But for every
1051 // entry, so there's a lot of repitition. This should be fixed.
1052 xs << html::StartTag("span", "class='bibtexinfo'")
1053 << XHTMLStream::ESCAPE_AND
1054 << bibinfo.getInfo(entry.key(), buffer(), ci)
1055 << html::EndTag("span")
1056 << html::EndTag("div")
1059 xs << html::EndTag("div");
1064 void InsetBibtex::write(ostream & os) const
1066 params().Write(os, &buffer());
1070 string InsetBibtex::contextMenuName() const
1072 return "context-bibtex";