]> git.lyx.org Git - features.git/blobdiff - src/LaTeXFeatures.C
Replace LString.h with support/std_string.h,
[features.git] / src / LaTeXFeatures.C
index 8b86836bedf5c7a92914db6d8e90d1b42e8f464f..61dd5ea3b3263b29ffdeda5b6eb80ab348128121 100644 (file)
@@ -1,27 +1,32 @@
-/* This file is part of
- * ======================================================
+/**
+ * \file LaTeXFeatures.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author José Matos
+ * \author Lars Gullik Bjønnes
+ * \author Jean-Marc Lasgouttes
+ * \author Jürgen Vigna
+ * \author André Pönitz
  *
- *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2001 the LyX Team.
- *
- * ====================================================== */
+ * Full author contact details are available in file CREDITS.
+ */
 
 #include <config.h>
 
 #include "LaTeXFeatures.h"
 #include "debug.h"
 #include "lyx_sty.h"
-#include "lyxrc.h"
 #include "bufferparams.h"
+#include "Floating.h"
 #include "FloatList.h"
 #include "language.h"
 #include "encoding.h"
-#include "LString.h"
+#include "support/std_sstream.h"
 
 #include "support/filetools.h"
-#include "support/lstrings.h"
+
+using namespace lyx::support;
 
 using lyx::textclass_type;
 
@@ -37,6 +42,14 @@ LaTeXFeatures::LaTeXFeatures(BufferParams const & p)
 {}
 
 
+bool LaTeXFeatures::useBabel() const
+{
+       return lyxrc.language_use_babel ||
+               bufferParams().language->lang() != lyxrc.default_language ||
+               this->hasLanguages();
+}
+
+
 void LaTeXFeatures::require(string const & name)
 {
        if (isRequired(name))
@@ -91,9 +104,12 @@ bool LaTeXFeatures::isRequired(string const & name) const
 }
 
 
-void LaTeXFeatures::addExternalPreamble(string const & pream)
+void LaTeXFeatures::addExternalPreamble(string const & preamble)
 {
-       externalPreambles += pream;
+       FeaturesList::const_iterator begin = preamble_snippets.begin();
+       FeaturesList::const_iterator end   = preamble_snippets.end();
+       if (find(begin, end, preamble) == end)
+               preamble_snippets.push_back(preamble);
 }
 
 
@@ -122,7 +138,7 @@ void LaTeXFeatures::includeFile(string const & key, string const & name)
 }
 
 
-bool LaTeXFeatures::hasLanguages()
+bool LaTeXFeatures::hasLanguages() const
 {
        return !UsedLanguages.empty();
 }
@@ -142,7 +158,7 @@ string LaTeXFeatures::getLanguages() const
 }
 
 
-set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding)
+set<string> LaTeXFeatures::getEncodingSet(string const & doc_encoding) const
 {
        set<string> encodings;
        for (LanguageList::const_iterator it =
@@ -175,12 +191,12 @@ int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
 
 }
 
+
 string const LaTeXFeatures::getPackages() const
 {
        ostringstream packages;
        LyXTextClass const & tclass = params.getLyXTextClass();
 
-
        //
        //  These are all the 'simple' includes.  i.e
        //  packages which we just \usepackage{package}
@@ -197,7 +213,8 @@ string const LaTeXFeatures::getPackages() const
        //
 
        if (isRequired("amsmath")
-           && ! tclass.provides(LyXTextClass::amsmath)) {
+           && !tclass.provides(LyXTextClass::amsmath)
+           && params.use_amsmath != BufferParams::AMS_OFF) {
                packages << "\\usepackage{amsmath}\n";
        }
 
@@ -263,7 +280,7 @@ string const LaTeXFeatures::getPackages() const
        }
 
        // amssymb.sty
-       if (isRequired("amssymb") || params.use_amsmath)
+       if (isRequired("amssymb") || params.use_amsmath == BufferParams::AMS_ON)
                packages << "\\usepackage{amssymb}\n";
        // url.sty
        if (isRequired("url") && ! tclass.provides(LyXTextClass::url))
@@ -282,8 +299,6 @@ string const LaTeXFeatures::getPackages() const
                packages << "]{natbib}\n";
        }
 
-       packages << externalPreambles;
-
        return STRCONV(packages.str());
 }
 
@@ -292,6 +307,14 @@ string const LaTeXFeatures::getMacros() const
 {
        ostringstream macros;
 
+       if (!preamble_snippets.empty())
+               macros << '\n';
+       FeaturesList::const_iterator pit  = preamble_snippets.begin();
+       FeaturesList::const_iterator pend = preamble_snippets.end();
+       for (; pit != pend; ++pit) {
+               macros << *pit << '\n';
+       }
+
        if (isRequired("LyX"))
                macros << lyx_def << '\n';
 
@@ -338,6 +361,10 @@ string const LaTeXFeatures::getMacros() const
        if (isRequired("NeedTabularnewline"))
                macros << tabularnewline_def;
 
+       // greyedout environment (note inset)
+       if (isRequired("lyxgreyedout"))
+               macros << lyxgreyedout_def;
+
        // floats
        getFloatDefinitions(macros);