+ if (btprint == "bibbysection" && !buffer().masterParams().multibib.empty())
+ os << "\\bibbysection";
+ else
+ os << "\\printbibliography";
+ if (!opts.empty())
+ os << "[" << opts << "]";
+ os << "\n";
+ } else {// using BibTeX
+ // Database(s)
+ vector<pair<docstring, string>> const dbs =
+ buffer().prepareBibFilePaths(runparams, getBibFiles(), false);
+ vector<docstring> db_out;
+ for (pair<docstring, string> const & db : dbs)
+ db_out.push_back(db.first);
+ // Style options
+ if (style == "default")
+ style = buffer().masterParams().defaultBiblioStyle();
+ if (!style.empty() && !buffer().masterParams().useBibtopic()) {
+ string base = buffer().masterBuffer()->prepareFileNameForLaTeX(style, ".bst", runparams.nice);
+ FileName const try_in_file =
+ makeAbsPath(base + ".bst", buffer().filePath());
+ bool const not_from_texmf = try_in_file.isReadableFile();
+ // If this style does not come from texmf and we are not
+ // exporting to .tex copy it to the tmp directory.
+ // This prevents problems with spaces and 8bit characters
+ // in the file name.
+ if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
+ not_from_texmf) {
+ // use new style name
+ DocFileName const in_file = DocFileName(try_in_file);
+ base = removeExtension(in_file.mangledFileName());
+ FileName const out_file = makeAbsPath(base + ".bst",
+ buffer().masterBuffer()->temppath());
+ bool const success = in_file.copyTo(out_file);
+ if (!success) {
+ LYXERR0("Failed to copy '" << in_file
+ << "' to '" << out_file << "'");
+ }
+ }
+ // FIXME UNICODE
+ os << "\\bibliographystyle{"
+ << from_utf8(latex_path(buffer().prepareFileNameForLaTeX(base, ".bst", runparams.nice)))
+ << "}\n";
+ }
+ // Warn about spaces in bst path. Warn only once.
+ static bool warned_about_bst_spaces = false;
+ if (!warned_about_bst_spaces && runparams.nice && contains(style, ' ')) {
+ warned_about_bst_spaces = true;
+ Alert::warning(_("Export Warning!"),
+ _("There are spaces in the path to your BibTeX style file.\n"
+ "BibTeX will be unable to find it."));
+ }
+ // Encoding
+ bool encoding_switched = false;
+ Encoding const * const save_enc = runparams.encoding;
+ docstring const encoding = getParam("encoding");
+ if (!encoding.empty() && encoding != from_ascii("default")) {
+ Encoding const * const enc = encodings.fromLyXName(to_ascii(encoding));
+ if (enc != runparams.encoding) {
+ os << "\\bgroup";
+ switchEncoding(os.os(), buffer().params(), runparams, *enc, true);
+ runparams.encoding = enc;
+ encoding_switched = true;
+ }
+ }
+ // Handle the bibtopic case
+ if (!db_out.empty() && buffer().masterParams().useBibtopic()) {
+ os << "\\begin{btSect}";
+ if (!style.empty())
+ os << "[" << style << "]";
+ os << "{" << getStringFromVector(db_out) << "}\n";
+ docstring btprint = getParam("btprint");
+ if (btprint.empty())
+ // default
+ btprint = from_ascii("btPrintCited");
+ os << "\\" << btprint << "\n"
+ << "\\end{btSect}\n";
+ }
+ // bibtotoc option
+ if (!bibtotoc.empty() && !buffer().masterParams().useBibtopic()) {
+ // set label for hyperref, see http://www.lyx.org/trac/ticket/6470
+ if (buffer().masterParams().pdfoptions().use_hyperref)
+ os << "\\phantomsection";
+ if (buffer().masterParams().documentClass().hasLaTeXLayout("chapter"))
+ os << "\\addcontentsline{toc}{chapter}{\\bibname}";
+ else if (buffer().masterParams().documentClass().hasLaTeXLayout("section"))
+ os << "\\addcontentsline{toc}{section}{\\refname}";
+ }
+ // The bibliography command
+ if (!db_out.empty() && !buffer().masterParams().useBibtopic()) {
+ docstring btprint = getParam("btprint");
+ if (btprint == "btPrintAll") {
+ os << "\\nocite{*}\n";
+ }
+ os << "\\bibliography{" << getStringFromVector(db_out) << "}\n";
+ }
+ if (encoding_switched){
+ // Switch back
+ switchEncoding(os.os(), buffer().params(),
+ runparams, *save_enc, true, true);
+ os << "\\egroup" << breakln;
+ runparams.encoding = save_enc;