]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeXFeatures.C
Dekels tabular/textinset patches
[lyx.git] / src / LaTeXFeatures.C
index c7172bfa5577ea7c6d09f4bd6c8f9bfd8e5bc766..b49d820fe6a9a014492dcf1c430a7e1fca0abfe7 100644 (file)
 #include "LaTeXFeatures.h"
 #include "bufferparams.h"
 #include "layout.h"
+#include "support/filetools.h"
+#include "FloatList.h"
 
 using std::endl;
 
-LaTeXFeatures::LaTeXFeatures(BufferParams const & p, int n)
+LaTeXFeatures::LaTeXFeatures(BufferParams const & p, LyXTextClass::size_type n)
        : layout(n, false), params(p)
 {
        // packages
        array = false;
        color = false;
-       graphics = false;
+       graphics = false; // INSET_GRAPHICS: remove this when InsetFig is thrown.
+       graphicx = false;
        setspace = false;
        makeidx = false;
        verbatim = false;
@@ -73,17 +76,16 @@ LaTeXFeatures::LaTeXFeatures(BufferParams const & p, int n)
        NeedLyXMinipageIndent = false;
 }
 
-void LaTeXFeatures::require(string const & name) {
+
+void LaTeXFeatures::require(string const & name)
+{
        if (name == "array") {
                array = true;
        } else if (name == "color") {
                color = true;
        } else if (name == "graphics") {
-#ifdef USE_GRAPHICX
                graphicx = true;
-#else
-               graphics = true;
-#endif
+               graphics = true;// INSET_GRAPHICS: remove this when InsetFig is thrown.
        } else if (name == "setspace") {
                setspace = true;
        } else if (name == "makeidx") {
@@ -123,7 +125,8 @@ void LaTeXFeatures::require(string const & name) {
        }
 }
 
-string LaTeXFeatures::getPackages()
+
+string const LaTeXFeatures::getPackages()
 {
        string packages;
        LyXTextClass const & tclass =
@@ -145,12 +148,22 @@ string LaTeXFeatures::getPackages()
        // makeidx.sty
        if (makeidx) {
                if (! tclass.provides(LyXTextClass::makeidx)
-                   && params.language != "french") // french provides
-                                                   // \index !
+                   && params.language->babel() != "french") // french provides
+                                                            // \index !
                        packages += "\\usepackage{makeidx}\n";
                packages += "\\makeindex\n";
        }
 
+       // graphicx.sty
+       if (graphicx && params.graphicsDriver != "none") {
+               if (params.graphicsDriver == "default")
+                       packages += "\\usepackage{graphicx}\n";
+               else
+                       packages += "\\usepackage[" 
+                               + params.graphicsDriver + "]{graphicx}\n";
+       }
+
+       // INSET_GRAPHICS: remove this when InsetFig is thrown.
        // graphics.sty
        if (graphics && params.graphicsDriver != "none") {
                if (params.graphicsDriver == "default")
@@ -192,22 +205,10 @@ string LaTeXFeatures::getPackages()
                packages += "\\doublespacing\n";
                break;
        case Spacing::Other:
-#ifdef HAVE_SSTREAM
                std::ostringstream value;
-#else
-               char val[30];
-               ostrstream value(val, 30);
-               
-#endif
                value << params.spacing.getValue(); // setw?
-#ifdef HAVE_SSTREAM
                packages += string("\\setstretch{") 
                          + value.str().c_str() + "}\n";
-#else
-               value << '\0';
-               packages += string("\\setstretch{") 
-                         + value.str() + "}\n";
-#endif
                break;
        }
 
@@ -253,11 +254,22 @@ string LaTeXFeatures::getPackages()
                packages += "\\usepackage{prettyref}\n";
 
        // float.sty
-       // This is not correct and needs fixing.
-       // We don't need float.sty if we only use unchanged
-       // table and figure floats. (Lgb)
-       if (!usedFloats.empty())
-               packages += "\\usepackage{float}\n";
+       // We only need float.sty if we use non builtin floats. 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;
+                               break;
+                       }
+               }
+               if (use_float)
+                       packages += "\\usepackage{float}\n";
+       }
        
        packages += externalPreambles;
 
@@ -265,7 +277,7 @@ string LaTeXFeatures::getPackages()
 }
 
 
-string LaTeXFeatures::getMacros()
+string const LaTeXFeatures::getMacros()
 {
        string macros;
 
@@ -318,11 +330,27 @@ string LaTeXFeatures::getMacros()
        // \floatstyle{ruled}
        // \newfloat{algorithm}{htbp}{loa}
        // \floatname{algorithm}{Algorithm}
+       UsedFloats::const_iterator beg = usedFloats.begin();
+       UsedFloats::const_iterator end = usedFloats.end();
+       for (; beg != end; ++beg) {
+               Floating const & fl = floatList.getType((*beg));
+               
+               // We have to special case "table" and "figure"
+               if ((fl.type() == "tabular" && !fl.builtin()) ||
+                   (fl.type() == "figure" && !fl.builtin())) {
+                       // Output code to modify "table" or "figure"
+                       // but only if builtin == false
+                       
+               } else {
+                       // The other non builtin floats.
+               }
+       }
+
        return macros;
 }
 
 
-string LaTeXFeatures::getTClassPreamble()
+string const LaTeXFeatures::getTClassPreamble()
 {
        // the text class specific preamble 
        LyXTextClass const & tclass =
@@ -339,12 +367,17 @@ string LaTeXFeatures::getTClassPreamble()
 }      
 
 
-string LaTeXFeatures::getIncludedFiles()
+string const LaTeXFeatures::getIncludedFiles(string const fname) const
 {
        string sgmlpreamble;
-
-       for(FileMap::const_iterator fi=IncludedFiles.begin(); fi != IncludedFiles.end(); ++fi)
-               sgmlpreamble += "\n<!entity " + fi->first + " system \"" + fi->second + "\">";
+       string basename = BasePath(fname);
+
+       FileMap::const_iterator end = IncludedFiles.end();
+       for (FileMap::const_iterator fi = IncludedFiles.begin();
+            fi != end; ++fi)
+         sgmlpreamble += "\n<!ENTITY " + fi->first
+                       + (IsSGMLFilename(fi->second) ? " SYSTEM \"" : " \"" )
+                       + MakeRelPath(fi->second,basename) + "\">";
 
        return sgmlpreamble;
 }