]> 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 b70b7decc3bd2c30121f78351f05b251fbbb4ae7..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::LaTeXFeatures(Buffer const & b, BufferParams const & p)
-       : buffer_(b), params_(p)
+
+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,8 +238,9 @@ char const * simplefeatures[] = {
        "varioref",
        "prettyref",
        "float",
-       "wasy",
-       "dvipost"
+       "dvipost",
+       "fancybox",
+       "calc",
 };
 
 int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
@@ -223,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";
        }
 
@@ -296,7 +351,7 @@ 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";
@@ -304,6 +359,17 @@ 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")) {
+               packages << "\\usepackage[dot]{bibtopic}\n";
+       }
+
        return packages.str();
 }
 
@@ -355,8 +421,6 @@ string const LaTeXFeatures::getMacros() const
                macros << mathcircumflex_def << '\n';
 
        // other
-       if (isRequired("NeedLyXMinipageIndent"))
-               macros << minipageindent_def;
        if (isRequired("ParagraphLeftIndent"))
                macros << paragraphleftindent_def;
        if (isRequired("NeedLyXFootnoteCode"))
@@ -370,6 +434,9 @@ string const LaTeXFeatures::getMacros() const
        if (isRequired("lyxgreyedout"))
                macros << lyxgreyedout_def;
 
+       if (isRequired("lyxdot"))
+               macros << lyxdot_def << '\n';
+
        // floats
        getFloatDefinitions(macros);
 
@@ -407,6 +474,13 @@ string const LaTeXFeatures::getTClassPreamble() const
                tcpreamble << tclass[*cit]->preamble();
        }
 
+       CharStyles::iterator cs = tclass.charstyles().begin();
+       CharStyles::iterator csend = tclass.charstyles().end();
+       for (; cs != csend; ++cs) {
+               if (isRequired(cs->name))
+                       tcpreamble << cs->preamble;
+       }
+
        return tcpreamble.str();
 }
 
@@ -451,7 +525,13 @@ void LaTeXFeatures::showStruct() const {
 
 Buffer const & LaTeXFeatures::buffer() const
 {
-       return buffer_;
+       return *buffer_;
+}
+
+
+void LaTeXFeatures::setBuffer(Buffer const & buffer)
+{
+       buffer_ = &buffer;
 }