]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeXFeatures.C
next step...
[lyx.git] / src / LaTeXFeatures.C
index d01f6b3b8b32f56bc69060228acba5149461d3c1..0f4d8dd2faad20570f8f4022233fcc8f5a5cb473 100644 (file)
@@ -1,11 +1,10 @@
-// -*- C++ -*-
 /* This file is part of
  * ====================================================== 
  * 
  *           LyX, The Document Processor
  *        
  *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2000 the LyX Team.
+ *           Copyright 1995-2001 the LyX Team.
  *
  * ====================================================== */
 
@@ -23,6 +22,7 @@
 #include "bufferparams.h"
 #include "layout.h"
 #include "support/filetools.h"
+#include "support/lstrings.h"
 #include "FloatList.h"
 #include "language.h"
 
@@ -40,7 +40,7 @@ LaTeXFeatures::LaTeXFeatures(BufferParams const & p, LyXTextClass::size_type n)
        makeidx = false;
        verbatim = false;
        longtable = false;
-       algorithm = false;
+       //algorithm = false;
        rotating = false;
        amssymb = false;
        latexsym = false;
@@ -51,6 +51,8 @@ LaTeXFeatures::LaTeXFeatures(BufferParams const & p, LyXTextClass::size_type n)
        varioref = false;
        prettyref = false;
        chess = false;
+       natbib = false;
+       floats = false;
        
        // commands
        lyx = false;
@@ -72,7 +74,7 @@ LaTeXFeatures::LaTeXFeatures(BufferParams const & p, LyXTextClass::size_type n)
        boldsymbol = false;
     
        // special features
-       LyXParagraphIndent = false;
+       ParagraphIndent = false;
        NeedLyXFootnoteCode = false;
        NeedLyXMinipageIndent = false;
 }
@@ -95,8 +97,8 @@ void LaTeXFeatures::require(string const & name)
                verbatim = true;
        } else if (name == "longtable") {
                longtable = true;
-       } else if (name == "algorithm") {
-               algorithm = true;
+       //} else if (name == "algorithm") {
+       //algorithm = true;
        } else if (name == "rotating") {
                rotating = true;
        } else if (name == "amssymb") {
@@ -123,6 +125,10 @@ void LaTeXFeatures::require(string const & name)
                boldsymbol = true;
        } else if (name == "binom") {
                binom = true;
+       } else if (name == "natbib") {
+               natbib = true;
+       } else if (name == "float") {
+               floats = true;
        }
 }
 
@@ -149,9 +155,7 @@ string const LaTeXFeatures::getPackages() const
                
        // makeidx.sty
        if (makeidx) {
-               if (! tclass.provides(LyXTextClass::makeidx)
-                   && params.language->babel() != "french") // french provides
-                                                            // \index !
+               if (! tclass.provides(LyXTextClass::makeidx))
                        packages << "\\usepackage{makeidx}\n";
                packages << "\\makeindex\n";
        }
@@ -181,9 +185,9 @@ string const LaTeXFeatures::getPackages() const
        if (verbatim)
                packages << "\\usepackage{verbatim}\n";
 
-       if (algorithm) {
-               packages << "\\usepackage{algorithm}\n";
-       }
+       //if (algorithm) {
+       //      packages << "\\usepackage{algorithm}\n";
+       //}
 
        // lyxchess.sty
        if (chess) {
@@ -256,21 +260,33 @@ string const LaTeXFeatures::getPackages() const
                packages << "\\usepackage{prettyref}\n";
 
        // float.sty
-       // We only need float.sty if we use non builtin floats. This includes
-       // modified table and figure floats. (Lgb)
+       // We only need float.sty if we use non builtin floats, or if we
+       // use the "H" modifier. This includes modified table and
+       // figure floats. (Lgb)
        if (!usedFloats.empty()) {
-               bool use_float = false;
                UsedFloats::const_iterator beg = usedFloats.begin();
                UsedFloats::const_iterator end = usedFloats.end();
                for (; beg != end; ++beg) {
                        Floating const & fl = floatList.getType((*beg));
                        if (!fl.type().empty() && !fl.builtin()) {
-                               use_float = true;
+                               const_cast<LaTeXFeatures *>(this)->floats = true;
                                break;
                        }
                }
-               if (use_float)
-                       packages << "\\usepackage{float}\n";
+       }
+       if (floats) {
+               packages << "\\usepackage{float}\n";
+       }
+       
+       // natbib.sty
+       if (natbib) {
+               packages << "\\usepackage[";
+               if (params.use_numerical_citations) {
+                       packages << "numbers";
+               } else {
+                       packages << "authoryear";
+               }
+               packages << "]{natbib}\n";
        }
        
        packages << externalPreambles;
@@ -321,7 +337,7 @@ string const LaTeXFeatures::getMacros() const
        // other
         if (NeedLyXMinipageIndent) 
                macros << minipageindent_def;
-        if (LyXParagraphIndent) 
+        if (ParagraphIndent) 
                macros << paragraphindent_def;
         if (NeedLyXFootnoteCode) 
                macros << floatingfootnote_def;
@@ -329,52 +345,6 @@ string const LaTeXFeatures::getMacros() const
        // floats
        getFloatDefinitions(macros);
 
-#if 0
-       // Here we will output the code to create the needed float styles.
-       // We will try to do this as minimal as possible.
-       // \floatstyle{ruled}
-       // \newfloat{algorithm}{htbp}{loa}
-       // \floatname{algorithm}{Algorithm}
-       UsedFloats::const_iterator cit = usedFloats.begin();
-       UsedFloats::const_iterator end = usedFloats.end();
-       ostringstream floats;
-       for (; cit != end; ++cit) {
-               Floating const & fl = floatList.getType((*cit));
-
-               // For builtin floats we do nothing.
-               if (fl.builtin()) continue;
-               
-               // We have to special case "table" and "figure"
-               if (fl.type() == "tabular" || fl.type() == "figure") {
-                       // Output code to modify "table" or "figure"
-                       // but only if builtin == false
-               } else {
-                       // The other non builtin floats.
-
-                       string type = fl.type();
-                       string placement = fl.placement();
-                       string ext = fl.ext();
-                       string within = fl.within();
-                       string style = fl.style();
-                       string name = fl.name();
-                       floats << "\\floatstyle{" << style << "}\n"
-                              << "\\newfloat{" << type << "}{" << placement
-                              << "}{" << ext << "}";
-                       if (!within.empty())
-                               floats << "[" << within << "]";
-                       floats << "\n"
-                              << "\\floatname{" << type << "}{"
-                              << name << "}\n";
-
-                       // What missing here is to code to minimalize the code
-                       // outputted so that the same flotastyle will not be
-                       // used several times. when the same style is still in
-                       // effect. (Lgb)
-               }
-       }
-       macros += floats.str().c_str();
-#endif
-       
        for (LanguageList::const_iterator cit = UsedLanguages.begin();
             cit != UsedLanguages.end(); ++cit)
                if (!(*cit)->latex_options().empty())
@@ -405,6 +375,20 @@ string const LaTeXFeatures::getTClassPreamble() const
 }      
 
 
+string const LaTeXFeatures::getLyXSGMLEntities() const
+{
+       // Definition of entities used in the document that are LyX related.
+       ostringstream entities;
+
+       if (lyxarrow) {
+               entities << "<!ENTITY lyxarrow \"-&gt;\">"
+                        << '\n';
+       }
+
+       return entities.str().c_str();
+}
+
+
 string const LaTeXFeatures::getIncludedFiles(string const & fname) const
 {
        ostringstream sgmlpreamble;
@@ -415,13 +399,13 @@ string const LaTeXFeatures::getIncludedFiles(string const & fname) const
             fi != end; ++fi)
                sgmlpreamble << "\n<!ENTITY " << fi->first
                             << (IsSGMLFilename(fi->second) ? " SYSTEM \"" : " \"" )
-                            << MakeRelPath(fi->second,basename) << "\">";
+                            << MakeRelPath(fi->second, basename) << "\">";
 
        return sgmlpreamble.str().c_str();
 }
 
 
-void LaTeXFeatures::showStruct() const{
+void LaTeXFeatures::showStruct() const {
        lyxerr << "LyX needs the following commands when LaTeXing:"
               << "\n***** Packages:" << getPackages()
               << "\n***** Macros:" << getMacros()
@@ -436,7 +420,7 @@ BufferParams const & LaTeXFeatures::bufferParams() const
 }
 
 
-void LaTeXFeatures::getFloatDefinitions(ostream & os) const
+void LaTeXFeatures::getFloatDefinitions(std::ostream & os) const
 {
        // Here we will output the code to create the needed float styles.
        // We will try to do this as minimal as possible.