*
* \author Alejandro Aguilar Sierra
* \author Richard Heck (BibTeX parser improvements)
+ * \author Jürgen Spitzmüller
*
* Full author contact details are available in file CREDITS.
*/
#include "BiblioInfo.h"
#include "Buffer.h"
#include "BufferParams.h"
+#include "CiteEnginesList.h"
#include "Cursor.h"
#include "DispatchResult.h"
#include "Encoding.h"
param_info_.add("btprint", ParamInfo::LATEX_OPTIONAL);
param_info_.add("bibfiles", ParamInfo::LATEX_REQUIRED);
param_info_.add("options", ParamInfo::LYX_INTERNAL);
+ param_info_.add("biblatexopts", ParamInfo::LATEX_OPTIONAL);
}
return param_info_;
}
int nr_databases = bibfilelist.size();
if (nr_databases > 1) {
- docstring message = bformat(_("The BibTeX inset includes %1$s databases.\n"
+ docstring const engine = usingBiblatex() ? _("Biblatex") : _("BibTeX");
+ docstring message = bformat(_("The %1$s[[BibTeX/Biblatex]] inset includes %2$s databases.\n"
"If you proceed, all of them will be opened."),
- convert<docstring>(nr_databases));
+ engine, convert<docstring>(nr_databases));
int const ret = Alert::prompt(_("Open Databases?"),
message, 0, 1, _("&Cancel"), _("&Proceed"));
}
+bool InsetBibtex::usingBiblatex() const
+{
+ return buffer().masterParams().useBiblatex();
+}
+
+
docstring InsetBibtex::screenLabel() const
{
- return _("BibTeX Generated Bibliography");
+ return usingBiblatex() ? _("Biblatex Generated Bibliography")
+ : _("BibTeX Generated Bibliography");
}
style = split(style, bibtotoc, char_type(','));
}
- tip += _("Style File:");
- tip += "<ul><li>" + (style.empty() ? _("none") : style) + "</li></ul>";
+ docstring const btprint = getParam("btprint");
+ if (!usingBiblatex()) {
+ tip += _("Style File:");
+ tip += "<ul><li>" + (style.empty() ? _("none") : style) + "</li></ul>";
- tip += _("Lists:") + " ";
- docstring btprint = getParam("btprint");
+ tip += _("Lists:") + " ";
if (btprint == "btPrintAll")
tip += _("all references");
else if (btprint == "btPrintNotCited")
tip += _("all uncited references");
else
tip += _("all cited references");
-
- if (toc) {
- tip += ", ";
- tip += _("included in TOC");
+ if (toc) {
+ tip += ", ";
+ tip += _("included in TOC");
+ }
+ } else {
+ tip += _("Lists:") + " ";
+ if (btprint == "bibbysection")
+ tip += _("all reference units");
+ else if (btprint == "btPrintAll")
+ tip += _("all references");
+ else
+ tip += _("all cited references");
+ if (toc) {
+ tip += ", ";
+ tip += _("included in TOC");
+ }
+ if (!getParam("biblatexopts").empty()) {
+ if (toc)
+ tip += "<br />";
+ tip += _("Options: ") + getParam("biblatexopts");
+ }
}
return tip;
}
-static string normalizeName(Buffer const & buffer,
- OutputParams const & runparams, string const & name, string const & ext)
-{
- string const fname = makeAbsPath(name, buffer.filePath()).absFileName();
- if (FileName::isAbsolute(name) || !FileName(fname + ext).isReadableFile())
- return name;
- if (!runparams.nice)
- return fname;
-
- // FIXME UNICODE
- return to_utf8(makeRelPath(from_utf8(fname),
- from_utf8(buffer.masterBuffer()->filePath())));
-}
-
-
void InsetBibtex::latex(otexstream & os, OutputParams const & runparams) const
{
- // the sequence of the commands:
+ // The sequence of the commands:
+ // With normal BibTeX:
// 1. \bibliographystyle{style}
// 2. \addcontentsline{...} - if option bibtotoc set
// 3. \bibliography{database}
- // and with bibtopic:
+ // With bibtopic:
// 1. \bibliographystyle{style}
// 2. \begin{btSect}{database}
// 3. \btPrint{Cited|NotCited|All}
// 4. \end{btSect}
+ // With Biblatex:
+ // \printbibliography[biblatexopts]
+ // or
+ // \bibbysection[biblatexopts] - if btprint is "bibbysection"
- // Database(s)
- // If we are processing the LaTeX file in a temp directory then
- // copy the .bib databases to this temp directory, mangling their
- // names in the process. Store this mangled name in the list of
- // all databases.
- // (We need to do all this because BibTeX *really*, *really*
- // can't handle "files with spaces" and Windows users tend to
- // use such filenames.)
- // Otherwise, store the (maybe absolute) path to the original,
- // unmangled database name.
- vector<docstring> bibfilelist = getVectorFromString(getParam("bibfiles"));
- vector<docstring>::const_iterator it = bibfilelist.begin();
- vector<docstring>::const_iterator en = bibfilelist.end();
- odocstringstream dbs;
- bool didone = false;
-
- // determine the export format
- string const tex_format = flavor2format(runparams.flavor);
-
- for (; it != en; ++it) {
- string utf8input = to_utf8(*it);
- string database =
- normalizeName(buffer(), runparams, utf8input, ".bib");
- FileName const try_in_file =
- makeAbsPath(database + ".bib", buffer().filePath());
- bool const not_from_texmf = try_in_file.isReadableFile();
-
- if (!runparams.inComment && !runparams.dryrun && !runparams.nice &&
- not_from_texmf) {
- // mangledFileName() needs the extension
- DocFileName const in_file = DocFileName(try_in_file);
- database = removeExtension(in_file.mangledFileName());
- FileName const out_file = makeAbsPath(database + ".bib",
- buffer().masterBuffer()->temppath());
- bool const success = in_file.copyTo(out_file);
- if (!success) {
- lyxerr << "Failed to copy '" << in_file
- << "' to '" << out_file << "'"
- << endl;
- }
- } else if (!runparams.inComment && runparams.nice && not_from_texmf) {
- runparams.exportdata->addExternalFile(tex_format, try_in_file, database + ".bib");
- if (!isValidLaTeXFileName(database)) {
- frontend::Alert::warning(_("Invalid filename"),
- _("The following filename will cause troubles "
- "when running the exported file through LaTeX: ") +
- from_utf8(database));
- }
- if (!isValidDVIFileName(database)) {
- frontend::Alert::warning(_("Problematic filename for DVI"),
- _("The following filename can cause troubles "
- "when running the exported file through LaTeX "
- "and opening the resulting DVI: ") +
- from_utf8(database), true);
- }
- }
-
- if (didone)
- dbs << ',';
- else
- didone = true;
- // FIXME UNICODE
- dbs << from_utf8(latex_path(database));
- }
- docstring const db_out = dbs.str();
-
- // Post this warning only once.
- static bool warned_about_spaces = false;
- if (!warned_about_spaces &&
- runparams.nice && db_out.find(' ') != docstring::npos) {
- warned_about_spaces = true;
- Alert::warning(_("Export Warning!"),
- _("There are spaces in the paths to your BibTeX databases.\n"
- "BibTeX will be unable to find them."));
- }
- // Style-Options
string style = to_utf8(getParam("options")); // maybe empty! and with bibtotoc
string bibtotoc;
if (prefixIs(style, "bibtotoc")) {
style = split(style, bibtotoc, ',');
}
- if (style == "default")
- style = buffer().params().defaultBiblioStyle();
-
- if (!style.empty() && !buffer().params().use_bibtopic) {
- string base = normalizeName(buffer(), runparams, style, ".bst");
- 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 charcaters
- // 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) {
- lyxerr << "Failed to copy '" << in_file
- << "' to '" << out_file << "'"
- << endl;
- }
- }
- // FIXME UNICODE
- os << "\\bibliographystyle{"
- << from_utf8(latex_path(normalizeName(buffer(), runparams, base, ".bst")))
- << "}\n";
- }
-
- // Post this warning 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."));
- }
-
- if (!db_out.empty() && buffer().params().use_bibtopic) {
- os << "\\begin{btSect}";
- if (!style.empty())
- os << "[" << style << "]";
- os << "{" << 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().params().use_bibtopic) {
- // set label for hyperref, see http://www.lyx.org/trac/ticket/6470
- if (buffer().params().pdfoptions().use_hyperref)
- os << "\\phantomsection";
- if (buffer().params().documentClass().hasLaTeXLayout("chapter"))
- os << "\\addcontentsline{toc}{chapter}{\\bibname}";
- else if (buffer().params().documentClass().hasLaTeXLayout("section"))
- os << "\\addcontentsline{toc}{section}{\\refname}";
- }
-
- if (!db_out.empty() && !buffer().params().use_bibtopic) {
+ if (usingBiblatex()) {
+ // Options
+ string opts = to_utf8(getParam("biblatexopts"));
+ // bibtotoc-Option
+ if (!bibtotoc.empty())
+ opts = opts.empty() ? "heading=bibintoc" : "heading=bibintoc," + opts;
+ // The bibliography command
docstring btprint = getParam("btprint");
- if (btprint == "btPrintAll") {
+ if (btprint == "btPrintAll")
os << "\\nocite{*}\n";
+ 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<docstring> const db_out =
+ buffer().prepareBibFilePaths(runparams, getBibFiles(), false);
+ // 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."));
+ }
+ // 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";
}
- os << "\\bibliography{" << db_out << "}\n";
}
}
support::FileNamePairList::const_iterator en = files.end();
for (; it != en; ++ it) {
ifdocstream ifs(it->second.toFilesystemEncoding().c_str(),
- ios_base::in, buffer().params().encoding().iconvName());
+ ios_base::in, buffer().masterParams().encoding().iconvName());
char_type ch;
VarMap strings;
void InsetBibtex::validate(LaTeXFeatures & features) const
{
- if (features.bufferParams().use_bibtopic)
+ if (features.buffer().masterParams().useBibtopic())
features.require("bibtopic");
// FIXME XHTML
// It'd be better to be able to get this from an InsetLayout, but at present
docstring refoutput;
refoutput += reflabel + "\n\n";
+ // Tell BiblioInfo our purpose
+ CiteItem ci;
+ ci.context = CiteItem::Export;
+
// Now we loop over the entries
vector<docstring>::const_iterator vit = cites.begin();
vector<docstring>::const_iterator const ven = cites.end();
// FIXME Right now, we are calling BibInfo::getInfo on the key,
// which will give us all the cross-referenced info. But for every
// entry, so there's a lot of repitition. This should be fixed.
- refoutput += bibinfo.getInfo(entry.key(), buffer(), false) + "\n\n";
+ refoutput += bibinfo.getInfo(entry.key(), buffer(), ci) + "\n\n";
}
os << refoutput;
return refoutput.size();
docstring const reflabel = buffer().B_("References");
+ // tell BiblioInfo our purpose
+ CiteItem ci;
+ ci.context = CiteItem::Export;
+ ci.richtext = true;
+ ci.max_key_size = UINT_MAX;
+
xs << html::StartTag("h2", "class='bibtex'")
<< reflabel
<< html::EndTag("h2")
// entry, so there's a lot of repitition. This should be fixed.
xs << html::StartTag("span", "class='bibtexinfo'")
<< XHTMLStream::ESCAPE_AND
- << bibinfo.getInfo(entry.key(), buffer(), true)
+ << bibinfo.getInfo(entry.key(), buffer(), ci)
<< html::EndTag("span")
<< html::EndTag("div")
<< html::CR();