]> git.lyx.org Git - features.git/blobdiff - src/bufferparams.C
change "support/std_sstream.h" to <sstream>
[features.git] / src / bufferparams.C
index bbe6c3009040e5240e794095983ad899343db9c6..448edc75dc9ea4ae960fb3a706d767532134e414 100644 (file)
 #include "gettext.h"
 #include "language.h"
 #include "LaTeXFeatures.h"
-#include "latexrunparams.h"
+#include "LColor.h"
 #include "lyxlex.h"
 #include "lyxrc.h"
 #include "lyxtextclasslist.h"
+#include "outputparams.h"
 #include "tex-strings.h"
 #include "Spacing.h"
 #include "texrow.h"
@@ -40,7 +41,7 @@
 
 #include <boost/array.hpp>
 
-#include "support/std_sstream.h"
+#include <sstream>
 
 namespace support = lyx::support;
 using lyx::support::bformat;
@@ -48,12 +49,14 @@ using lyx::support::rtrim;
 using lyx::support::tokenPos;
 
 using std::endl;
-
+using std::string;
 using std::istringstream;
 using std::ostream;
 using std::ostringstream;
 using std::pair;
 
+namespace biblio = lyx::biblio;
+
 
 struct BufferParams::Impl
 {
@@ -112,8 +115,8 @@ BufferParams::BufferParams()
        orientation = ORIENTATION_PORTRAIT;
        use_geometry = false;
        use_amsmath = AMS_AUTO;
-       use_natbib = false;
-       use_numerical_citations = false;
+       cite_engine = biblio::ENGINE_BASIC;
+       use_bibtopic = false;
        tracking_changes = false;
        secnumdepth = 3;
        tocdepth = 3;
@@ -314,12 +317,21 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
                lex.nextToken();
                use_amsmath = static_cast<AMS>(
                        lex.getInteger());
-       } else if (token == "\\use_natbib") {
+       } else if (token == "\\cite_engine") {
                lex.nextToken();
-               use_natbib = lex.getInteger();
-       } else if (token == "\\use_numerical_citations") {
+               string const engine = lex.getString();
+
+               cite_engine = biblio::ENGINE_BASIC;
+               if (engine == "natbib_numerical")
+                       cite_engine = biblio::ENGINE_NATBIB_NUMERICAL;
+               else if (engine == "natbib_authoryear")
+                       cite_engine = biblio::ENGINE_NATBIB_AUTHORYEAR;
+               else if (engine == "jurabib")
+                       cite_engine = biblio::ENGINE_JURABIB;
+
+       } else if (token == "\\use_bibtopic") {
                lex.nextToken();
-               use_numerical_citations = lex.getInteger();
+               use_bibtopic = lex.getInteger();
        } else if (token == "\\tracking_changes") {
                lex.nextToken();
                tracking_changes = lex.getInteger();
@@ -332,20 +344,23 @@ string const BufferParams::readToken(LyXLex & lex, string const & token)
                        string const tok = lex.getString();
                        if (tok == "\\end_branch")
                                break;
+                       Branch * branch_ptr = branchlist().find(branch);
                        if (tok == "\\selected") {
                                lex.nextToken();
-                               branchlist().setSelected(branch, lex.getInteger());
+                               if (branch_ptr)
+                                       branch_ptr->setSelected(lex.getInteger());
                        }
                        // not yet operational
                        if (tok == "\\color") {
                                lex.nextToken();
                                string color = lex.getString();
-                               branchlist().setColor(branch, color);
+                               if (branch_ptr)
+                                       branch_ptr->setColor(color);
                                // Update also the LColor table:
                                if (color == "none")
                                        color = lcolor.getX11Name(LColor::background);
-                               lcolor.fill(static_cast<LColor::color>(lcolor.size()),
-                                               branch, color);
+                               lcolor.setColor(branch, color);
+
                        }
                }
        } else if (token == "\\author") {
@@ -528,12 +543,27 @@ void BufferParams::writeFile(ostream & os) const
 
        spacing().writeFile(os);
 
+       string cite_engine_str = "basic";
+       switch (cite_engine) {
+       case biblio::ENGINE_BASIC:
+               break;
+       case biblio::ENGINE_NATBIB_NUMERICAL:
+               cite_engine_str = "natbib_numerical";
+               break;
+       case biblio::ENGINE_NATBIB_AUTHORYEAR:
+               cite_engine_str = "natbib_authoryear";
+               break;
+       case biblio::ENGINE_JURABIB:
+               cite_engine_str = "jurabib";
+               break;
+       }
+
        os << "\\papersize " << string_papersize[papersize2]
           << "\n\\paperpackage " << string_paperpackages[paperpackage]
           << "\n\\use_geometry " << use_geometry
           << "\n\\use_amsmath " << use_amsmath
-          << "\n\\use_natbib " << use_natbib
-          << "\n\\use_numerical_citations " << use_numerical_citations
+          << "\n\\cite_engine " << cite_engine_str
+          << "\n\\use_bibtopic " << use_bibtopic
           << "\n\\paperorientation " << string_orientation[orientation]
           << '\n';
 
@@ -916,6 +946,14 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
                texrow.newline();
        }
 
+       // If we use jurabib, we have to call babel here.
+       if (use_babel && features.isRequired("jurabib")) {
+               os << babelCall(language_options.str())
+                  << '\n'
+                  << features.getBabelOptions();
+               texrow.newline();
+       }
+
        // Now insert the LyX specific LaTeX commands...
 
        // The optional packages;
@@ -985,14 +1023,9 @@ bool BufferParams::writeLaTeX(ostream & os, LaTeXFeatures & features,
 
        // We try to load babel late, in case it interferes
        // with other packages.
-       if (use_babel) {
-               string tmp = lyxrc.language_package;
-               if (!lyxrc.language_global_options
-                   && tmp == "\\usepackage{babel}")
-                       tmp = string("\\usepackage[") +
-                               language_options.str() +
-                               "]{babel}";
-               lyxpreamble += tmp + "\n";
+       // Jurabib has to be called after babel, though.
+       if (use_babel && !features.isRequired("jurabib")) {
+               lyxpreamble += babelCall(language_options.str()) + '\n';
                lyxpreamble += features.getBabelOptions();
        }
 
@@ -1184,3 +1217,12 @@ string const BufferParams::dvips_options() const
                result += ' ' + lyxrc.print_landscape_flag;
        return result;
 }
+
+
+string const BufferParams::babelCall(string const & lang_opts) const
+{
+       string tmp = lyxrc.language_package;
+       if (!lyxrc.language_global_options && tmp == "\\usepackage{babel}")
+               tmp = string("\\usepackage[") + lang_opts + "]{babel}";
+       return tmp;
+}