]> 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 821f248fc4bbdd7a25a205c54322774c543d8551..2b363bdde440e907b1b3a07de85a3cd5be80e0f8 100644 (file)
@@ -22,6 +22,7 @@
 #include "Floating.h"
 #include "FloatList.h"
 #include "language.h"
+#include "lyxlex.h"
 #include "lyx_sty.h"
 #include "lyxrc.h"
 
@@ -30,6 +31,7 @@
 #include <sstream>
 
 using lyx::support::IsSGMLFilename;
+using lyx::support::LibFileSearch;
 using lyx::support::MakeRelPath;
 using lyx::support::OnlyPath;
 
@@ -44,6 +46,9 @@ 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)
 {}
@@ -66,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
@@ -111,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();
@@ -189,7 +238,6 @@ char const * simplefeatures[] = {
        "varioref",
        "prettyref",
        "float",
-       "wasysym",
        "dvipost",
        "fancybox",
        "calc",
@@ -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";
        }