]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeXFeatures.C
Applied Angus patch to compile on DEC C++ and to avoid name clashes
[lyx.git] / src / LaTeXFeatures.C
index a50eac97fce2d897ad32b9f5eed9514c2310cd98..2da36b28b8c67fe849a2c4a6cf560f1accfac72a 100644 (file)
@@ -22,6 +22,8 @@
 #include "LaTeXFeatures.h"
 #include "bufferparams.h"
 #include "layout.h"
+#include "support/filetools.h"
+#include "FloatList.h"
 
 using std::endl;
 
@@ -252,11 +254,22 @@ string const 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;
 
@@ -317,6 +330,52 @@ string const LaTeXFeatures::getMacros()
        // \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();
+
+       for (LanguageList::const_iterator cit = UsedLanguages.begin();
+            cit != UsedLanguages.end(); ++cit)
+               if (!(*cit)->latex_options().empty())
+                       macros += (*cit)->latex_options() + '\n';
+       if (!params.language->latex_options().empty())
+               macros += params.language->latex_options() + '\n';
+
        return macros;
 }
 
@@ -338,14 +397,17 @@ string const LaTeXFeatures::getTClassPreamble()
 }      
 
 
-string const LaTeXFeatures::getIncludedFiles()
+string const LaTeXFeatures::getIncludedFiles(string const fname) const
 {
        string sgmlpreamble;
+       string basename = OnlyPath(fname);
+
        FileMap::const_iterator end = IncludedFiles.end();
        for (FileMap::const_iterator fi = IncludedFiles.begin();
             fi != end; ++fi)
-               sgmlpreamble += "\n<!entity " + fi->first
-                       + " system \"" + fi->second + "\">";
+         sgmlpreamble += "\n<!ENTITY " + fi->first
+                       + (IsSGMLFilename(fi->second) ? " SYSTEM \"" : " \"" )
+                       + MakeRelPath(fi->second,basename) + "\">";
 
        return sgmlpreamble;
 }