]> git.lyx.org Git - lyx.git/blobdiff - src/BufferParams.cpp
Fix glitch in drawing fractions
[lyx.git] / src / BufferParams.cpp
index e96067a9859db60e6aa215048296284677ee2905..2736c26977f78df08e9c7504803f5e13f674ce48 100644 (file)
@@ -847,6 +847,15 @@ string BufferParams::readToken(Lexer & lex, string const & token,
        } else if (token == "\\biblio_style") {
                lex.eatLine();
                biblio_style = lex.getString();
+       } else if (token == "\\biblio_options") {
+               lex.eatLine();
+               biblio_opts = trim(lex.getString());
+       } else if (token == "\\biblatex_bibstyle") {
+               lex.eatLine();
+               biblatex_bibstyle = trim(lex.getString());
+       } else if (token == "\\biblatex_citestyle") {
+               lex.eatLine();
+               biblatex_citestyle = trim(lex.getString());
        } else if (token == "\\use_bibtopic") {
                lex >> use_bibtopic;
        } else if (token == "\\use_indices") {
@@ -1214,9 +1223,18 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
                os << "basic";
        }
 
-       os << "\n\\cite_engine_type " << theCiteEnginesList.getTypeAsString(cite_engine_type_)
-          << "\n\\biblio_style " << biblio_style
-          << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
+       os << "\n\\cite_engine_type " << theCiteEnginesList.getTypeAsString(cite_engine_type_);
+
+       if (!biblio_style.empty())
+               os << "\n\\biblio_style " << biblio_style;
+       if (!biblio_opts.empty())
+               os << "\n\\biblio_options " << biblio_opts;
+       if (!biblatex_bibstyle.empty())
+               os << "\n\\biblatex_bibstyle " << biblatex_bibstyle;
+       if (!biblatex_citestyle.empty())
+               os << "\n\\biblatex_citestyle " << biblatex_citestyle;
+
+       os << "\n\\use_bibtopic " << convert<string>(use_bibtopic)
           << "\n\\use_indices " << convert<string>(use_indices)
           << "\n\\paperorientation " << string_orientation[orientation]
           << "\n\\suppress_date " << convert<string>(suppress_date)
@@ -2165,7 +2183,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
            && useNonTeXFonts)
                os << "\\usepackage{xunicode}\n";
 
-       // Polyglossia must be loaded last
+       // Polyglossia must be loaded last ...
        if (use_polyglossia) {
                // call the package
                os << "\\usepackage{polyglossia}\n";
@@ -2189,6 +2207,42 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
                }
        }
 
+       // ... but before biblatex (see #7065)
+       if (features.mustProvide("biblatex")) {
+               string delim = "";
+               string opts;
+               os << "\\usepackage";
+               if (!biblatex_bibstyle.empty()
+                   && (biblatex_bibstyle == biblatex_citestyle)) {
+                       opts = "style=" + biblatex_bibstyle;
+                       delim = ",";
+               } else {
+                       if (!biblatex_bibstyle.empty()) {
+                               opts = "bibstyle=" + biblatex_bibstyle;
+                               delim = ",";
+                       }
+                       if (!biblatex_citestyle.empty()) {
+                               opts += delim + "citestyle=" + biblatex_citestyle;
+                               delim = ",";
+                       }
+               }
+               if (bibtexCommand() == "bibtex8"
+                   || prefixIs(bibtexCommand(), "bibtex8 ")) {
+                       opts += delim + "backend=bibtex8";
+                       delim = ",";
+               } else if (bibtexCommand() == "bibtex"
+                          || prefixIs(bibtexCommand(), "bibtex ")) {
+                       opts += delim + "backend=bibtex";
+                       delim = ",";
+               }
+               if (!biblio_opts.empty())
+                       opts += delim + biblio_opts;
+               if (!opts.empty())
+                       os << "[" << opts << "]";
+               os << "{biblatex}\n";
+       }
+
+
        // Load custom language package here
        if (features.langPackage() == LaTeXFeatures::LANG_PACK_CUSTOM) {
                if (lang_package == "default")
@@ -3301,14 +3355,49 @@ vector<CitationStyle> BufferParams::citeStyles() const
 }
 
 
-string const BufferParams::bibtexCommand() const
+string const BufferParams::bibtexCommand() const
 {
+       // Return document-specific setting if available
        if (bibtex_command != "default")
                return bibtex_command;
-       else if (encoding().package() == Encoding::japanese)
-               return lyxrc.jbibtex_command;
-       else
+
+       // If we have "default" in document settings, consult the prefs
+       // 1. Japanese (uses a specific processor)
+       if (encoding().package() == Encoding::japanese) {
+               if (lyxrc.jbibtex_command != "automatic")
+                       // Return the specified program, if "automatic" is not set
+                       return lyxrc.jbibtex_command;
+               else if (!useBiblatex()) {
+                       // With classic BibTeX, return pbibtex, jbibtex, bibtex
+                       if (lyxrc.jbibtex_alternatives.find("pbibtex") != lyxrc.jbibtex_alternatives.end())
+                               return "pbibtex";
+                       if (lyxrc.jbibtex_alternatives.find("jbibtex") != lyxrc.jbibtex_alternatives.end())
+                               return "jbibtex";
+                       return "bibtex";
+               }
+       }
+       // 2. All other languages
+       else if (lyxrc.bibtex_command != "automatic")
+               // Return the specified program, if "automatic" is not set
                return lyxrc.bibtex_command;
+
+       // 3. Automatic: find the most suitable for the current cite framework
+       if (useBiblatex()) {
+               // For Biblatex, we prefer biber (also for Japanese)
+               // and fall back to bibtex8 and, as last resort, bibtex
+               if (lyxrc.bibtex_alternatives.find("biber") != lyxrc.bibtex_alternatives.end())
+                       return "biber";
+               else if (lyxrc.bibtex_alternatives.find("bibtex8") != lyxrc.bibtex_alternatives.end())
+                       return "bibtex8";
+       }
+       return "bibtex";
+}
+
+
+bool BufferParams::useBiblatex() const
+{
+       return theCiteEnginesList[citeEngine().list().front()]
+                       ->getCiteFramework() == "biblatex";
 }