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"
32 #include "OutputParams.h"
33 #include "PDFOptions.h"
34 #include "texstream.h"
35 #include "TextClass.h"
36 #include "TocBackend.h"
38 #include "frontends/alert.h"
40 #include "support/convert.h"
41 #include "support/debug.h"
42 #include "support/docstream.h"
43 #include "support/docstring_list.h"
44 #include "support/ExceptionMessage.h"
45 #include "support/FileNameList.h"
46 #include "support/filetools.h"
47 #include "support/gettext.h"
48 #include "support/lstrings.h"
49 #include "support/os.h"
50 #include "support/PathChanger.h"
51 #include "support/textutils.h"
56 using namespace lyx::support;
60 namespace Alert = frontend::Alert;
61 namespace os = support::os;
64 InsetBibtex::InsetBibtex(Buffer * buf, InsetCommandParams const & p)
65 : InsetCommand(buf, p)
69 ParamInfo const & InsetBibtex::findInfo(string const & /* cmdName */)
71 static ParamInfo param_info_;
72 if (param_info_.empty()) {
73 param_info_.add("btprint", ParamInfo::LATEX_OPTIONAL);
74 param_info_.add("bibfiles", ParamInfo::LATEX_REQUIRED);
75 param_info_.add("options", ParamInfo::LYX_INTERNAL);
76 param_info_.add("encoding", ParamInfo::LYX_INTERNAL);
77 param_info_.add("file_encodings", ParamInfo::LYX_INTERNAL);
78 param_info_.add("biblatexopts", ParamInfo::LATEX_OPTIONAL);
84 void InsetBibtex::doDispatch(Cursor & cur, FuncRequest & cmd)
86 switch (cmd.action()) {
89 editDatabases(cmd.argument());
92 case LFUN_INSET_MODIFY: {
93 InsetCommandParams p(BIBTEX_CODE);
95 if (!InsetCommand::string2params(to_utf8(cmd.argument()), p)) {
99 } catch (ExceptionMessage const & message) {
100 if (message.type_ == WarningException) {
101 Alert::warning(message.title_, message.details_);
102 cur.noScreenUpdate();
110 cur.buffer()->clearBibFileCache();
111 cur.forceBufferUpdate();
116 InsetCommand::doDispatch(cur, cmd);
122 bool InsetBibtex::getStatus(Cursor & cur, FuncRequest const & cmd,
123 FuncStatus & flag) const
125 switch (cmd.action()) {
126 case LFUN_INSET_EDIT:
127 flag.setEnabled(true);
131 return InsetCommand::getStatus(cur, cmd, flag);
136 void InsetBibtex::editDatabases(docstring const & db) const
138 vector<docstring> bibfilelist = getVectorFromString(getParam("bibfiles"));
140 if (bibfilelist.empty())
143 size_t nr_databases = bibfilelist.size();
144 if (nr_databases > 1 && db.empty()) {
145 docstring const engine = usingBiblatex() ? _("Biblatex") : _("BibTeX");
146 docstring message = bformat(_("The %1$s[[BibTeX/Biblatex]] inset includes %2$s databases.\n"
147 "If you proceed, all of them will be opened."),
148 engine, convert<docstring>(nr_databases));
149 int const ret = Alert::prompt(_("Open Databases?"),
150 message, 0, 1, _("&Cancel"), _("&Proceed"));
156 vector<docstring>::const_iterator it = bibfilelist.begin();
157 vector<docstring>::const_iterator en = bibfilelist.end();
158 for (; it != en; ++it) {
159 if (!db.empty() && db != *it)
161 FileName const bibfile = buffer().getBibfilePath(*it);
162 theFormats().edit(buffer(), bibfile,
163 theFormats().getFormatFromFile(bibfile));
168 bool InsetBibtex::usingBiblatex() const
170 return buffer().masterParams().useBiblatex();
174 docstring InsetBibtex::screenLabel() const
176 return usingBiblatex() ? _("Biblatex Generated Bibliography")
177 : _("BibTeX Generated Bibliography");
181 docstring InsetBibtex::toolTip(BufferView const & /*bv*/, int /*x*/, int /*y*/) const
183 docstring tip = _("Databases:");
184 vector<docstring> bibfilelist = getVectorFromString(getParam("bibfiles"));
187 if (bibfilelist.empty())
188 tip += "<li>" + _("none") + "</li>";
190 for (docstring const & bibfile : bibfilelist)
191 tip += "<li>" + bibfile + "</li>";
196 docstring style = getParam("options"); // maybe empty! and with bibtotoc
197 docstring bibtotoc = from_ascii("bibtotoc");
198 if (prefixIs(style, bibtotoc)) {
200 if (contains(style, char_type(',')))
201 style = split(style, bibtotoc, char_type(','));
204 docstring const btprint = getParam("btprint");
205 if (!usingBiblatex()) {
206 tip += _("Style File:");
207 tip += "<ul><li>" + (style.empty() ? _("none") : style) + "</li></ul>";
209 tip += _("Lists:") + " ";
210 if (btprint == "btPrintAll")
211 tip += _("all references");
212 else if (btprint == "btPrintNotCited")
213 tip += _("all uncited references");
215 tip += _("all cited references");
218 tip += _("included in TOC");
220 if (!buffer().parent()
221 && buffer().params().multibib == "child") {
223 tip += _("Note: This bibliography is not output, since bibliographies in the master file "
224 "are not allowed with the setting 'Multiple bibliographies per child document'");
227 tip += _("Lists:") + " ";
228 if (btprint == "bibbysection")
229 tip += _("all reference units");
230 else if (btprint == "btPrintAll")
231 tip += _("all references");
233 tip += _("all cited references");
236 tip += _("included in TOC");
238 if (!getParam("biblatexopts").empty()) {
240 tip += _("Options: ") + getParam("biblatexopts");
248 void InsetBibtex::latex(otexstream & os, OutputParams const & runparams) const
250 // The sequence of the commands:
251 // With normal BibTeX:
252 // 1. \bibliographystyle{style}
253 // 2. \addcontentsline{...} - if option bibtotoc set
254 // 3. \bibliography{database}
256 // 1. \bibliographystyle{style}
257 // 2. \begin{btSect}{database}
258 // 3. \btPrint{Cited|NotCited|All}
261 // \printbibliography[biblatexopts]
263 // \bibbysection[biblatexopts] - if btprint is "bibbysection"
265 // chapterbib does not allow bibliographies in the master
266 if (!usingBiblatex() && !runparams.is_child
267 && buffer().params().multibib == "child")
270 if (runparams.inDeletedInset) {
271 // We cannot strike-out bibligraphies,
272 // so we just output a note.
274 << buffer().B_("[BIBLIOGRAPHY DELETED!]")
279 string style = to_utf8(getParam("options")); // maybe empty! and with bibtotoc
281 if (prefixIs(style, "bibtotoc")) {
282 bibtotoc = "bibtotoc";
283 if (contains(style, ','))
284 style = split(style, bibtotoc, ',');
287 if (usingBiblatex()) {
289 string opts = to_utf8(getParam("biblatexopts"));
291 if (!bibtotoc.empty())
292 opts = opts.empty() ? "heading=bibintoc" : "heading=bibintoc," + opts;
293 // The bibliography command
294 docstring btprint = getParam("btprint");
295 if (btprint == "btPrintAll")
296 os << "\\nocite{*}\n";
297 if (btprint == "bibbysection" && !buffer().masterParams().multibib.empty())
298 os << "\\bibbysection";
300 os << "\\printbibliography";
302 os << "[" << opts << "]";
304 } else {// using BibTeX
306 vector<pair<docstring, string>> const dbs =
307 buffer().prepareBibFilePaths(runparams, getBibFiles(), false);
308 vector<docstring> db_out;
309 for (pair<docstring, string> const & db : dbs)
310 db_out.push_back(db.first);
312 if (style == "default")
313 style = buffer().masterParams().defaultBiblioStyle();
314 if (!style.empty() && !buffer().masterParams().useBibtopic()) {
315 string base = buffer().masterBuffer()->prepareFileNameForLaTeX(style, ".bst", runparams.nice);
316 FileName const try_in_file =
317 makeAbsPath(base + ".bst", buffer().filePath());
318 bool const not_from_texmf = try_in_file.isReadableFile();
319 // If this style does not come from texmf and we are not
320 // exporting to .tex copy it to the tmp directory.
321 // This prevents problems with spaces and 8bit characters
323 if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
325 // use new style name
326 DocFileName const in_file = DocFileName(try_in_file);
327 base = removeExtension(in_file.mangledFileName());
328 FileName const out_file = makeAbsPath(base + ".bst",
329 buffer().masterBuffer()->temppath());
330 bool const success = in_file.copyTo(out_file);
332 LYXERR0("Failed to copy '" << in_file
333 << "' to '" << out_file << "'");
337 os << "\\bibliographystyle{"
338 << from_utf8(latex_path(buffer().prepareFileNameForLaTeX(base, ".bst", runparams.nice)))
341 // Warn about spaces in bst path. Warn only once.
342 static bool warned_about_bst_spaces = false;
343 if (!warned_about_bst_spaces && runparams.nice && contains(style, ' ')) {
344 warned_about_bst_spaces = true;
345 Alert::warning(_("Export Warning!"),
346 _("There are spaces in the path to your BibTeX style file.\n"
347 "BibTeX will be unable to find it."));
350 bool encoding_switched = false;
351 Encoding const * const save_enc = runparams.encoding;
352 docstring const encoding = getParam("encoding");
353 if (!encoding.empty() && encoding != from_ascii("default")) {
354 Encoding const * const enc = encodings.fromLyXName(to_ascii(encoding));
355 if (enc != runparams.encoding) {
357 switchEncoding(os.os(), buffer().params(), runparams, *enc, true);
358 runparams.encoding = enc;
359 encoding_switched = true;
362 // Handle the bibtopic case
363 if (!db_out.empty() && buffer().masterParams().useBibtopic()) {
364 os << "\\begin{btSect}";
366 os << "[" << style << "]";
367 os << "{" << getStringFromVector(db_out) << "}\n";
368 docstring btprint = getParam("btprint");
371 btprint = from_ascii("btPrintCited");
372 os << "\\" << btprint << "\n"
373 << "\\end{btSect}\n";
376 if (!bibtotoc.empty() && !buffer().masterParams().useBibtopic()
377 && !buffer().masterParams().documentClass().bibInToc()) {
378 // set label for hyperref, see http://www.lyx.org/trac/ticket/6470
379 if (buffer().masterParams().pdfoptions().use_hyperref)
380 os << "\\phantomsection";
381 if (buffer().masterParams().documentClass().hasLaTeXLayout("chapter"))
382 os << "\\addcontentsline{toc}{chapter}{\\bibname}";
383 else if (buffer().masterParams().documentClass().hasLaTeXLayout("section"))
384 os << "\\addcontentsline{toc}{section}{\\refname}";
386 // The bibliography command
387 if (!db_out.empty() && !buffer().masterParams().useBibtopic()) {
388 docstring btprint = getParam("btprint");
389 if (btprint == "btPrintAll") {
390 os << "\\nocite{*}\n";
392 os << "\\bibliography{" << getStringFromVector(db_out) << "}\n";
394 if (encoding_switched){
396 switchEncoding(os.os(), buffer().params(),
397 runparams, *save_enc, true, true);
398 os << "\\egroup" << breakln;
399 runparams.encoding = save_enc;
405 docstring_list InsetBibtex::getBibFiles() const
407 return getVectorFromString(getParam("bibfiles"));
412 // methods for parsing bibtex files
414 typedef map<docstring, docstring> VarMap;
416 /// remove whitespace characters, optionally a single comma,
417 /// and further whitespace characters from the stream.
418 /// @return true if a comma was found, false otherwise
420 bool removeWSAndComma(ifdocstream & ifs) {
429 } while (ifs && isSpace(ch));
442 } while (ifs && isSpace(ch));
457 /// remove whitespace characters, read characer sequence
458 /// not containing whitespace characters or characters in
459 /// delimChars, and remove further whitespace characters.
461 /// @return true if a string of length > 0 could be read.
463 bool readTypeOrKey(docstring & val, ifdocstream & ifs,
464 docstring const & delimChars, docstring const & illegalChars,
477 } while (ifs && isSpace(ch));
483 while (ifs && !isSpace(ch) &&
484 delimChars.find(ch) == docstring::npos &&
485 illegalChars.find(ch) == docstring::npos)
487 if (chCase == makeLowerCase)
488 val += lowercase(ch);
494 if (illegalChars.find(ch) != docstring::npos) {
500 while (ifs && isSpace(ch)) {
508 return val.length() > 0;
511 /// read subsequent bibtex values that are delimited with a #-character.
512 /// Concatenate all parts and replace names with the associated string in
513 /// the variable strings.
514 /// @return true if reading was successfull (all single parts were delimited
516 bool readValue(docstring & val, ifdocstream & ifs, const VarMap & strings) {
529 } while (ifs && isSpace(ch));
534 // check for field type
535 if (isDigitASCII(ch)) {
537 // read integer value
541 } while (ifs && isDigitASCII(ch));
546 } else if (ch == '"' || ch == '{') {
548 char_type delim = ch == '"' ? '"': '}';
553 } while (ifs && isSpace(ch));
558 // We now have the first non-whitespace character
559 // We'll collapse adjacent whitespace.
560 bool lastWasWhiteSpace = false;
562 // inside this delimited text braces must match.
563 // Thus we can have a closing delimiter only
564 // when nestLevel == 0
567 while (ifs && (nestLevel > 0 || ch != delim)) {
569 lastWasWhiteSpace = true;
573 // We output the space only after we stop getting
574 // whitespace so as not to output any whitespace
575 // at the end of the value.
576 if (lastWasWhiteSpace) {
577 lastWasWhiteSpace = false;
583 // update nesting level
602 // FIXME Why is this here?
610 // reading a string name
613 while (ifs && !isSpace(ch) && ch != '#' && ch != ',' && ch != '}' && ch != ')') {
614 strName += lowercase(ch);
621 // replace the string with its assigned value or
622 // discard it if it's not assigned
623 if (strName.length()) {
624 VarMap::const_iterator pos = strings.find(strName);
625 if (pos != strings.end()) {
632 while (ifs && isSpace(ch)) {
639 // continue reading next value on concatenate with '#'
649 void InsetBibtex::collectBibKeys(InsetIterator const & /*di*/, FileNameList & checkedFiles) const
651 parseBibTeXFiles(checkedFiles);
655 void InsetBibtex::parseBibTeXFiles(FileNameList & checkedFiles) const
657 // This bibtex parser is a first step to parse bibtex files
660 // - it reads the whole bibtex entry and does a syntax check
661 // (matching delimiters, missing commas,...
662 // - it recovers from errors starting with the next @-character
663 // - it reads @string definitions and replaces them in the
665 // - it accepts more characters in keys or value names than
668 // Officially bibtex does only support ASCII, but in practice
669 // you can use any encoding as long as some elements like keys
670 // and names are pure ASCII. We support specifying an encoding,
671 // and we convert the file from that (default is buffer encoding).
672 // We don't restrict keys to ASCII in LyX, since our own
673 // InsetBibitem can generate non-ASCII keys, and nonstandard
674 // 8bit clean bibtex forks exist.
678 docstring_list const files = getBibFiles();
679 for (auto const & bf : files) {
680 FileName const bibfile = buffer().getBibfilePath(bf);
681 if (bibfile.empty()) {
682 LYXERR0("Unable to find path for " << bf << "!");
685 if (find(checkedFiles.begin(), checkedFiles.end(), bibfile) != checkedFiles.end())
686 // already checked this one. Skip.
689 // record that we check this.
690 checkedFiles.push_back(bibfile);
691 string encoding = buffer().masterParams().encoding().iconvName();
692 string ienc = buffer().masterParams().bibFileEncoding(to_utf8(bf));
693 if (ienc.empty() || ienc == "general")
694 ienc = to_ascii(params()["encoding"]);
696 if (!ienc.empty() && ienc != "auto-legacy-plain" && ienc != "auto-legacy" && encodings.fromLyXName(ienc))
697 encoding = encodings.fromLyXName(ienc)->iconvName();
698 ifdocstream ifs(bibfile.toFilesystemEncoding().c_str(),
699 ios_base::in, encoding);
714 if (!readTypeOrKey(entryType, ifs, from_ascii("{("), docstring(), makeLowerCase)) {
715 lyxerr << "BibTeX Parser: Error reading entry type." << std::endl;
720 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
724 if (entryType == from_ascii("comment")) {
725 ifs.ignore(numeric_limits<int>::max(), '\n');
731 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
735 if ((ch != '(') && (ch != '{')) {
736 lyxerr << "BibTeX Parser: Invalid entry delimiter." << std::endl;
742 if (entryType == from_ascii("string")) {
744 // read string and add it to the strings map
745 // (or replace it's old value)
749 if (!readTypeOrKey(name, ifs, from_ascii("="), from_ascii("#{}(),"), makeLowerCase)) {
750 lyxerr << "BibTeX Parser: Error reading string name." << std::endl;
755 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
759 // next char must be an equal sign
761 if (!ifs || ch != '=') {
762 lyxerr << "BibTeX Parser: No `=' after string name: " <<
763 name << "." << std::endl;
767 if (!readValue(value, ifs, strings)) {
768 lyxerr << "BibTeX Parser: Unable to read value for string: " <<
769 name << "." << std::endl;
773 strings[name] = value;
775 } else if (entryType == from_ascii("preamble")) {
777 // preamble definitions are discarded.
778 // can they be of any use in lyx?
781 if (!readValue(value, ifs, strings)) {
782 lyxerr << "BibTeX Parser: Unable to read preamble value." << std::endl;
788 // Citation entry. Try to read the key.
791 if (!readTypeOrKey(key, ifs, from_ascii(","), from_ascii("}"), keepCase)) {
792 lyxerr << "BibTeX Parser: Unable to read key for entry type:" <<
793 entryType << "." << std::endl;
798 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
802 /////////////////////////////////////////////
803 // now we have a key, so we will add an entry
804 // (even if it's empty, as bibtex does)
806 // we now read the field = value pairs.
807 // all items must be separated by a comma. If
808 // it is missing the scanning of this entry is
809 // stopped and the next is searched.
813 BibTeXInfo keyvalmap(key, entryType);
815 bool readNext = removeWSAndComma(ifs);
817 while (ifs && readNext) {
820 if (!readTypeOrKey(name, ifs, from_ascii("="),
821 from_ascii("{}(),"), makeLowerCase) || !ifs)
824 // next char must be an equal sign
825 // FIXME Whitespace??
828 lyxerr << "BibTeX Parser: Unexpected end of file." << std::endl;
832 lyxerr << "BibTeX Parser: Missing `=' after field name: " <<
833 name << ", for key: " << key << "." << std::endl;
839 if (!readValue(value, ifs, strings)) {
840 lyxerr << "BibTeX Parser: Unable to read value for field: " <<
841 name << ", for key: " << key << "." << std::endl;
845 keyvalmap[name] = value;
846 data += "\n\n" + value;
847 keylist.addFieldName(name);
848 readNext = removeWSAndComma(ifs);
852 keylist.addEntryType(entryType);
853 keyvalmap.setAllData(data);
854 keylist[key] = keyvalmap;
855 } //< else (citation entry)
857 } //< for loop over files
859 buffer().addBiblioInfo(keylist);
863 bool InsetBibtex::addDatabase(docstring const & db)
865 docstring bibfiles = getParam("bibfiles");
866 if (tokenPos(bibfiles, ',', db) != -1)
868 if (!bibfiles.empty())
870 setParam("bibfiles", bibfiles + db);
875 bool InsetBibtex::delDatabase(docstring const & db)
877 docstring bibfiles = getParam("bibfiles");
878 if (contains(bibfiles, db)) {
879 int const n = tokenPos(bibfiles, ',', db);
882 // this is not the first database
883 docstring tmp = ',' + bd;
884 setParam("bibfiles", subst(bibfiles, tmp, docstring()));
886 // this is the first (or only) database
887 setParam("bibfiles", split(bibfiles, bd, ','));
895 void InsetBibtex::validate(LaTeXFeatures & features) const
897 BufferParams const & mparams = features.buffer().masterParams();
898 if (mparams.useBibtopic())
899 features.require("bibtopic");
900 else if (!mparams.useBiblatex() && mparams.multibib == "child")
901 features.require("chapterbib");
903 // It'd be better to be able to get this from an InsetLayout, but at present
904 // InsetLayouts do not seem really to work for things that aren't InsetTexts.
905 if (features.runparams().flavor == OutputParams::HTML)
906 features.addCSSSnippet("div.bibtexentry { margin-left: 2em; text-indent: -2em; }\n"
907 "span.bibtexlabel:before{ content: \"[\"; }\n"
908 "span.bibtexlabel:after{ content: \"] \"; }");
912 void InsetBibtex::updateBuffer(ParIterator const &, UpdateType, bool const /*deleted*/)
914 buffer().registerBibfiles(getBibFiles());
915 // record encoding of bib files for biblatex
916 string const enc = (params()["encoding"] == from_ascii("default")) ?
917 string() : to_ascii(params()["encoding"]);
918 bool invalidate = false;
919 if (buffer().params().bibEncoding() != enc) {
920 buffer().params().setBibEncoding(enc);
923 map<string, string> encs = getFileEncodings();
924 map<string, string>::const_iterator it = encs.begin();
925 for (; it != encs.end(); ++it) {
926 if (buffer().params().bibFileEncoding(it->first) != it->second) {
927 buffer().params().setBibFileEncoding(it->first, it->second);
932 buffer().invalidateBibinfoCache();
936 map<string, string> InsetBibtex::getFileEncodings() const
939 getVectorFromString(to_utf8(getParam("file_encodings")), "\t");
940 std::map<string, string> res;
941 for (string const & s: ps) {
943 string val = split(s, key, ' ');
950 docstring InsetBibtex::getRefLabel() const
952 if (buffer().masterParams().documentClass().hasLaTeXLayout("chapter"))
953 return buffer().B_("Bibliography");
954 return buffer().B_("References");
958 void InsetBibtex::addToToc(DocIterator const & cpit, bool output_active,
959 UpdateType, TocBackend & backend) const
961 if (!prefixIs(to_utf8(getParam("options")), "bibtotoc"))
964 docstring const str = getRefLabel();
965 shared_ptr<Toc> toc = backend.toc("tableofcontents");
966 // Assign to appropriate level
967 int const item_depth =
968 (buffer().masterParams().documentClass().hasLaTeXLayout("chapter"))
970 toc->push_back(TocItem(cpit, item_depth, str, output_active));
974 int InsetBibtex::plaintext(odocstringstream & os,
975 OutputParams const & op, size_t max_length) const
977 docstring const reflabel = getRefLabel();
979 // We could output more information here, e.g., what databases are included
980 // and information about options. But I don't necessarily see any reason to
981 // do this right now.
982 if (op.for_tooltip || op.for_toc || op.for_search) {
983 os << '[' << reflabel << ']' << '\n';
984 return PLAINTEXT_NEWLINE;
987 BiblioInfo bibinfo = buffer().masterBibInfo();
988 bibinfo.makeCitationLabels(buffer());
989 vector<docstring> const & cites = bibinfo.citedEntries();
991 size_t start_size = os.str().size();
993 refoutput += reflabel + "\n\n";
995 // Tell BiblioInfo our purpose
997 ci.context = CiteItem::Export;
999 // Now we loop over the entries
1000 vector<docstring>::const_iterator vit = cites.begin();
1001 vector<docstring>::const_iterator const ven = cites.end();
1002 for (; vit != ven; ++vit) {
1003 if (start_size + refoutput.size() >= max_length)
1005 BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
1006 if (biit == bibinfo.end())
1008 BibTeXInfo const & entry = biit->second;
1009 refoutput += "[" + entry.label() + "] ";
1010 // FIXME Right now, we are calling BibInfo::getInfo on the key,
1011 // which will give us all the cross-referenced info. But for every
1012 // entry, so there's a lot of repetition. This should be fixed.
1013 refoutput += bibinfo.getInfo(entry.key(), buffer(), ci) + "\n\n";
1016 return int(refoutput.size());
1021 // docstring InsetBibtex::entriesAsXHTML(vector<docstring> const & entries)
1022 // And then here just: entriesAsXHTML(buffer().masterBibInfo().citedEntries())
1023 docstring InsetBibtex::xhtml(XMLStream & xs, OutputParams const &) const
1025 BiblioInfo const & bibinfo = buffer().masterBibInfo();
1026 bool const all_entries = getParam("btprint") == "btPrintAll";
1027 vector<docstring> const & cites =
1028 all_entries ? bibinfo.getKeys() : bibinfo.citedEntries();
1030 docstring const reflabel = buffer().B_("References");
1032 // tell BiblioInfo our purpose
1034 ci.context = CiteItem::Export;
1036 ci.max_key_size = UINT_MAX;
1038 xs << xml::StartTag("h2", "class='bibtex'")
1040 << xml::EndTag("h2")
1041 << xml::StartTag("div", "class='bibtex'");
1043 // Now we loop over the entries
1044 vector<docstring>::const_iterator vit = cites.begin();
1045 vector<docstring>::const_iterator const ven = cites.end();
1046 for (; vit != ven; ++vit) {
1047 BiblioInfo::const_iterator const biit = bibinfo.find(*vit);
1048 if (biit == bibinfo.end())
1051 BibTeXInfo const & entry = biit->second;
1052 string const attr = "class='bibtexentry' id='LyXCite-"
1053 + to_utf8(xml::cleanAttr(entry.key())) + "'";
1054 xs << xml::StartTag("div", attr);
1056 // don't print labels if we're outputting all entries
1058 xs << xml::StartTag("span", "class='bibtexlabel'")
1060 << xml::EndTag("span");
1063 // FIXME Right now, we are calling BibInfo::getInfo on the key,
1064 // which will give us all the cross-referenced info. But for every
1065 // entry, so there's a lot of repitition. This should be fixed.
1066 xs << xml::StartTag("span", "class='bibtexinfo'")
1067 << XMLStream::ESCAPE_AND
1068 << bibinfo.getInfo(entry.key(), buffer(), ci)
1069 << xml::EndTag("span")
1070 << xml::EndTag("div")
1073 xs << xml::EndTag("div");
1078 void InsetBibtex::write(ostream & os) const
1080 params().Write(os, &buffer());
1084 string InsetBibtex::contextMenuName() const
1086 return "context-bibtex";