]> git.lyx.org Git - lyx.git/blobdiff - src/BufferParams.cpp
Fix glitch in drawing fractions
[lyx.git] / src / BufferParams.cpp
index c48e1cfcca971fdcbcd4147a39666035f58b9584..2736c26977f78df08e9c7504803f5e13f674ce48 100644 (file)
@@ -23,6 +23,7 @@
 #include "Buffer.h"
 #include "buffer_funcs.h"
 #include "Bullet.h"
+#include "CiteEnginesList.h"
 #include "Color.h"
 #include "ColorSet.h"
 #include "Converter.h"
@@ -73,7 +74,7 @@ static char const * const string_paragraph_separation[] = {
 
 static char const * const string_quotes_style[] = {
        "english", "swedish", "german", "polish", "swiss", "danish", "plain",
-       "british", "swedishg", "french", "frenchin", "russian", ""
+       "british", "swedishg", "french", "frenchin", "russian", "cjk", "cjkangle", ""
 };
 
 
@@ -147,6 +148,8 @@ QuotesStyleTranslator const init_quotesstyletranslator()
        translator.addPair(string_quotes_style[9], InsetQuotesParams::FrenchQuotes);
        translator.addPair(string_quotes_style[10], InsetQuotesParams::FrenchINQuotes);
        translator.addPair(string_quotes_style[11], InsetQuotesParams::RussianQuotes);
+       translator.addPair(string_quotes_style[12], InsetQuotesParams::CJKQuotes);
+       translator.addPair(string_quotes_style[13], InsetQuotesParams::CJKAngleQuotes);
        return translator;
 }
 
@@ -270,27 +273,6 @@ PackageTranslator const & packagetranslator()
 }
 
 
-// Cite engine
-typedef Translator<string, CiteEngineType> CiteEngineTypeTranslator;
-
-
-CiteEngineTypeTranslator const init_citeenginetypetranslator()
-{
-       CiteEngineTypeTranslator translator("authoryear", ENGINE_TYPE_AUTHORYEAR);
-       translator.addPair("numerical", ENGINE_TYPE_NUMERICAL);
-       translator.addPair("default", ENGINE_TYPE_DEFAULT);
-       return translator;
-}
-
-
-CiteEngineTypeTranslator const & citeenginetypetranslator()
-{
-       static CiteEngineTypeTranslator const translator =
-               init_citeenginetypetranslator();
-       return translator;
-}
-
-
 // Spacing
 typedef Translator<string, Spacing::Space> SpaceTranslator;
 
@@ -861,10 +843,19 @@ string BufferParams::readToken(Lexer & lex, string const & token,
        } else if (token == "\\cite_engine_type") {
                string engine_type;
                lex >> engine_type;
-               cite_engine_type_ = citeenginetypetranslator().find(engine_type);
+               cite_engine_type_ = theCiteEnginesList.getType(engine_type);
        } 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") {
@@ -1232,9 +1223,18 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
                os << "basic";
        }
 
-       os << "\n\\cite_engine_type " << citeenginetypetranslator().find(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)
@@ -2183,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";
@@ -2207,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")
@@ -2331,6 +2367,7 @@ void BufferParams::makeDocumentClass(bool const clone)
 
        invalidateConverterCache();
        LayoutModuleList mods;
+       LayoutModuleList ces;
        LayoutModuleList::iterator it = layout_modules_.begin();
        LayoutModuleList::iterator en = layout_modules_.end();
        for (; it != en; ++it)
@@ -2339,9 +2376,9 @@ void BufferParams::makeDocumentClass(bool const clone)
        it = cite_engine_.begin();
        en = cite_engine_.end();
        for (; it != en; ++it)
-               mods.push_back(*it);
+               ces.push_back(*it);
 
-       doc_class_ = getDocumentClass(*baseClass(), mods, clone);
+       doc_class_ = getDocumentClass(*baseClass(), mods, ces, clone);
 
        TextClass::ReturnValues success = TextClass::OK;
        if (!forced_local_layout_.empty())
@@ -3257,7 +3294,8 @@ bool BufferParams::addCiteEngine(vector<string> const & engine)
 
 string const & BufferParams::defaultBiblioStyle() const
 {
-       return documentClass().defaultBiblioStyle();
+       map<string, string> bs = documentClass().defaultBiblioStyle();
+       return bs[theCiteEnginesList.getTypeAsString(citeEngineType())];
 }
 
 
@@ -3267,6 +3305,20 @@ bool const & BufferParams::fullAuthorList() const
 }
 
 
+string BufferParams::getCiteAlias(string const & s) const
+{
+       vector<string> commands =
+               documentClass().citeCommands(citeEngineType());
+       // If it is a real command, don't treat it as an alias
+       if (find(commands.begin(), commands.end(), s) != commands.end())
+               return string();
+       map<string,string> aliases = documentClass().citeCommandAliases();
+       if (aliases.find(s) != aliases.end())
+               return aliases[s];
+       return string();
+}
+
+
 void BufferParams::setCiteEngine(string const & engine)
 {
        clearCiteEngine();
@@ -3287,7 +3339,7 @@ vector<string> BufferParams::citeCommands() const
        vector<string> commands =
                documentClass().citeCommands(citeEngineType());
        if (commands.empty())
-               commands.push_back(default_style.cmd);
+               commands.push_back(default_style.name);
        return commands;
 }
 
@@ -3302,6 +3354,53 @@ vector<CitationStyle> BufferParams::citeStyles() const
        return styles;
 }
 
+
+string const BufferParams::bibtexCommand() const
+{
+       // Return document-specific setting if available
+       if (bibtex_command != "default")
+               return bibtex_command;
+
+       // 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";
+}
+
+
 void BufferParams::invalidateConverterCache() const
 {
        pimpl_->isExportCacheValid = false;