]> 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 9cbbc3288c564c9e76c60aa34443f15740d92782..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,6 +43,11 @@ 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)
@@ -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";
        }
 
@@ -307,6 +359,11 @@ string const LaTeXFeatures::getPackages() const
                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")) {