]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeXFeatures.C
Fix bug 2195: Slowness in rendering inside insets, especially on the Mac
[lyx.git] / src / LaTeXFeatures.C
index 9120330be01930af27c54fd19dffa89ab7afda05..2b363bdde440e907b1b3a07de85a3cd5be80e0f8 100644 (file)
 #include "Floating.h"
 #include "FloatList.h"
 #include "language.h"
+#include "lyxlex.h"
 #include "lyx_sty.h"
 #include "lyxrc.h"
 
 #include "support/filetools.h"
 
-#include "support/std_sstream.h"
+#include <sstream>
 
 using lyx::support::IsSGMLFilename;
+using lyx::support::LibFileSearch;
 using lyx::support::MakeRelPath;
 using lyx::support::OnlyPath;
 
@@ -41,9 +43,14 @@ using std::ostream;
 using std::ostringstream;
 using std::set;
 
+namespace biblio = lyx::biblio;
+
+
+LaTeXFeatures::PackagesList LaTeXFeatures::packages_;
+
 
 LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p, bool n)
-       : buffer_(b), params_(p), nice_(n)
+       : buffer_(&b), params_(p), nice_(n)
 {}
 
 
@@ -64,6 +71,42 @@ void LaTeXFeatures::require(string const & name)
 }
 
 
+void LaTeXFeatures::getAvailable()
+{
+       LyXLex lex(0, 0);
+       string real_file = LibFileSearch("", "packages.lst");
+
+       if (real_file.empty())
+               return;
+
+       lex.setFile(real_file);
+
+       if (!lex.isOK())
+               return;
+
+       // Make sure that we are clean
+       packages_.clear();
+
+       bool finished = false;
+       // Parse config-file
+       while (lex.isOK() && !finished) {
+               switch (lex.lex()) {
+               case LyXLex::LEX_FEOF:
+                       finished = true;
+                       break;
+               default:
+                       string const name = lex.getString();
+                       PackagesList::const_iterator begin = packages_.begin();
+                       PackagesList::const_iterator end   = packages_.end();
+                       if (find(begin, end, name) == end)
+                               packages_.push_back(name);
+               }
+       }
+
+       return;
+}
+
+
 void LaTeXFeatures::useLayout(string const & layoutname)
 {
        // Some code to avoid loops in dependency definition
@@ -109,6 +152,14 @@ bool LaTeXFeatures::isRequired(string const & name) const
 }
 
 
+bool LaTeXFeatures::isAvailable(string const & name) const
+{
+       if (packages_.empty())
+               getAvailable();
+       return find(packages_.begin(), packages_.end(), name) != packages_.end();
+}
+
+
 void LaTeXFeatures::addExternalPreamble(string const & preamble)
 {
        FeaturesList::const_iterator begin = preamble_snippets_.begin();
@@ -158,7 +209,6 @@ string LaTeXFeatures::getLanguages() const
             cit != UsedLanguages_.end();
             ++cit)
                languages << (*cit)->babel() << ',';
-
        return languages.str();
 }
 
@@ -188,11 +238,9 @@ char const * simplefeatures[] = {
        "varioref",
        "prettyref",
        "float",
-       "wasy",
        "dvipost",
        "fancybox",
        "calc",
-       "jurabib"
 };
 
 int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
@@ -226,14 +274,18 @@ string const LaTeXFeatures::getPackages() const
                packages << "\\usepackage{amsmath}\n";
        }
 
+       // wasysym is a simple feature, but it must be after amsmath if both
+       // are used
+       if (isRequired("wasysym"))
+               packages << "\\usepackage{wasysym}\n";
+
        // color.sty
        if (isRequired("color")) {
                if (params_.graphicsDriver == "default")
-                       packages << "\\usepackage[usenames]{color}\n";
+                       packages << "\\usepackage{color}\n";
                else
                        packages << "\\usepackage["
                                 << params_.graphicsDriver
-                                << ",usenames"
                                 << "]{color}\n";
        }
 
@@ -299,14 +351,19 @@ string const LaTeXFeatures::getPackages() const
        // natbib.sty
        if (isRequired("natbib") && ! tclass.provides(LyXTextClass::natbib)) {
                packages << "\\usepackage[";
-               if (params_.use_numerical_citations) {
+               if (params_.cite_engine == biblio::ENGINE_NATBIB_NUMERICAL) {
                        packages << "numbers";
                } else {
                        packages << "authoryear";
                }
                packages << "]{natbib}\n";
        }
-       
+
+       // jurabib -- we need version 0.6 at least.
+       if (isRequired("jurabib")) {
+               packages << "\\usepackage{jurabib}[2004/01/25]\n";
+       }
+
        // bibtopic -- the dot provides the aux file naming which
        // LyX can detect.
        if (isRequired("bibtopic")) {
@@ -377,6 +434,9 @@ string const LaTeXFeatures::getMacros() const
        if (isRequired("lyxgreyedout"))
                macros << lyxgreyedout_def;
 
+       if (isRequired("lyxdot"))
+               macros << lyxdot_def << '\n';
+
        // floats
        getFloatDefinitions(macros);
 
@@ -420,7 +480,7 @@ string const LaTeXFeatures::getTClassPreamble() const
                if (isRequired(cs->name))
                        tcpreamble << cs->preamble;
        }
-       
+
        return tcpreamble.str();
 }
 
@@ -465,7 +525,13 @@ void LaTeXFeatures::showStruct() const {
 
 Buffer const & LaTeXFeatures::buffer() const
 {
-       return buffer_;
+       return *buffer_;
+}
+
+
+void LaTeXFeatures::setBuffer(Buffer const & buffer)
+{
+       buffer_ = &buffer;
 }