]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeXFeatures.cpp
Fix compilation on win
[lyx.git] / src / LaTeXFeatures.cpp
index ea06e62da39f36c3bd93662681727864285f49fe..8ecf8c91677f3ec82e47863aad56d68a295cb70b 100644 (file)
@@ -19,6 +19,7 @@
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "ColorSet.h"
+#include "Converter.h"
 #include "Encoding.h"
 #include "Floating.h"
 #include "FloatList.h"
@@ -28,6 +29,8 @@
 #include "LyXRC.h"
 #include "TextClass.h"
 
+#include "insets/InsetLayout.h"
+
 #include "support/debug.h"
 #include "support/docstream.h"
 #include "support/FileName.h"
@@ -202,11 +205,8 @@ static string const textcyr_def =
        "\\AtBeginDocument{\\DeclareFontEncoding{T2A}{}{}}\n";
 
 static string const lyxmathsym_def =
-       "\\DeclareRobustCommand{\\lyxmathsym}[1]{\\ifmmode\\begingroup\\def\\b@ld{bold}\n"
-       "  \\def\\rmorbf##1{\\ifx\\math@version\\b@ld\\textbf{##1}\\else\\textrm{##1}\\fi}\n"
-       "  \\mathchoice{\\hbox{\\rmorbf{#1}}}{\\hbox{\\rmorbf{#1}}}\n"
-       "  {\\hbox{\\smaller[2]\\rmorbf{#1}}}{\\hbox{\\smaller[3]\\rmorbf{#1}}}\n"
-       "  \\endgroup\\else#1\\fi}\n";
+       "\\newcommand{\\lyxmathsym}[1]{\\ifmmode\\begingroup\\def\\b@ld{bold}\n"
+       "  \\text{\\ifx\\math@version\\b@ld\\bfseries\\fi#1}\\endgroup\\else#1\\fi}\n";
 
 static string const papersizedvi_def =
        "\\special{papersize=\\the\\paperwidth,\\the\\paperheight}\n";
@@ -359,6 +359,26 @@ void LaTeXFeatures::useLayout(docstring const & layoutname)
 }
 
 
+void LaTeXFeatures::useInsetLayout(InsetLayout const & lay)
+{
+       docstring const & lname = lay.name();
+       DocumentClass const & tclass = params_.documentClass();
+       if (!tclass.hasInsetLayout(lname)) {
+               lyxerr << "LaTeXFeatures::useInsetLayout: layout `"
+                      << to_utf8(lname) << "' does not exist in this class"
+                      << endl;
+               return;
+       }
+       // Is this layout already in usedInsetLayouts?
+       if (find(usedInsetLayouts_.begin(), usedInsetLayouts_.end(), lname) 
+                       != usedInsetLayouts_.end())
+               return;
+
+       require(lay.requires());
+       usedInsetLayouts_.push_back(lname);
+}
+
+
 bool LaTeXFeatures::isRequired(string const & name) const
 {
        return features_.find(name) != features_.end();
@@ -373,6 +393,14 @@ bool LaTeXFeatures::mustProvide(string const & name) const
 
 bool LaTeXFeatures::isAvailable(string const & name)
 {
+       string::size_type const i = name.find("->");
+       if (i != string::npos) {
+               string const from = name.substr(0,i);
+               string const to = name.substr(i+2);
+               LYXERR0("from=[" << from << "] to=[" << to << "]");
+               return theConverters().isReachable(from, to);
+       }
+
        if (packages_.empty())
                getAvailable();
        string n = name;
@@ -514,7 +542,6 @@ char const * simplefeatures[] = {
        // listings is handled in BufferParams.cpp
        "bm",
        "pdfpages",
-       "relsize",
        "amscd",
        "slashed"
 };
@@ -549,6 +576,16 @@ string const LaTeXFeatures::getColorOptions() const
        if (mustProvide("pdfcolmk"))
                colors << "\\usepackage{pdfcolmk}\n";
 
+       if (mustProvide("pagecolor")) {
+               // the \pagecolor command must be set after color is loaded and
+               // before pdfpages, therefore add the command here
+               // define the set color
+               colors << "\\definecolor{page_backgroundcolor}{rgb}{";
+               colors << outputLaTeXColor(params_.backgroundcolor) << "}\n";
+               // set the page color
+               colors << "\\pagecolor{page_backgroundcolor}\n";
+       }
+
        return colors.str();
 }
 
@@ -586,9 +623,12 @@ string const LaTeXFeatures::getPackages() const
                && params_.use_esint == BufferParams::package_off
                && params_.use_amsmath != BufferParams::package_off)) {
                packages << "\\usepackage{amsmath}\n";
-       } else if (mustProvide("amsbsy")) {
-               // amsbsy is already provided by amsmath
-               packages << "\\usepackage{amsbsy}\n";
+       } else {
+               // amsbsy and amstext are already provided by amsmath
+               if (mustProvide("amsbsy"))
+                       packages << "\\usepackage{amsbsy}\n";
+               if (mustProvide("amstext"))
+                       packages << "\\usepackage{amstext}\n";
        }
        
        // wasysym is a simple feature, but it must be after amsmath if both
@@ -610,9 +650,11 @@ string const LaTeXFeatures::getPackages() const
        // [x]color and pdfcolmk are handled in getColorOptions() above
        
        // makeidx.sty
-       if (isRequired("makeidx")) {
-               if (!tclass.provides("makeidx"))
+       if (isRequired("makeidx") || isRequired("splitidx")) {
+               if (!tclass.provides("makeidx") && !isRequired("splitidx"))
                        packages << "\\usepackage{makeidx}\n";
+               if (!tclass.provides("splitidx") && isRequired("splitidx"))
+                       packages << "\\usepackage{splitidx}\n";
                packages << "\\makeindex\n";
        }
 
@@ -870,18 +912,101 @@ docstring const LaTeXFeatures::getTClassPreamble() const
 
        tcpreamble << tclass.preamble();
 
+       list<docstring>::const_iterator cit = usedLayouts_.begin();
+       list<docstring>::const_iterator end = usedLayouts_.end();
+       for (; cit != end; ++cit)
+               tcpreamble << tclass[*cit].preamble();
+
+       cit = usedInsetLayouts_.begin();
+       end = usedInsetLayouts_.end();
+       TextClass::InsetLayouts const & ils = tclass.insetLayouts();
+       for (; cit != end; ++cit) {
+               TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
+               if (it == ils.end())
+                       continue;
+               tcpreamble << it->second.preamble();
+       }
+
+       return tcpreamble.str();
+}
+
+
+docstring const LaTeXFeatures::getTClassHTMLPreamble() const 
+{
+       DocumentClass const & tclass = params_.documentClass();
+       odocstringstream tcpreamble;
+
+       tcpreamble << tclass.htmlpreamble();
+
+       list<docstring>::const_iterator cit = usedLayouts_.begin();
+       list<docstring>::const_iterator end = usedLayouts_.end();
+       for (; cit != end; ++cit)
+               tcpreamble << tclass[*cit].htmlpreamble();
+
+       cit = usedInsetLayouts_.begin();
+       end = usedInsetLayouts_.end();
+       TextClass::InsetLayouts const & ils = tclass.insetLayouts();
+       for (; cit != end; ++cit) {
+               TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
+               if (it == ils.end())
+                       continue;
+               tcpreamble << it->second.htmlpreamble();
+       }
+
+       return tcpreamble.str();
+}
+
+
+docstring const LaTeXFeatures::getTClassHTMLStyles() const {
+       DocumentClass const & tclass = params_.documentClass();
+       odocstringstream tcpreamble;
+
+       list<docstring>::const_iterator cit = usedLayouts_.begin();
+       list<docstring>::const_iterator end = usedLayouts_.end();
+       for (; cit != end; ++cit)
+               tcpreamble << tclass[*cit].htmlstyle();
+
+       cit = usedInsetLayouts_.begin();
+       end = usedInsetLayouts_.end();
+       TextClass::InsetLayouts const & ils = tclass.insetLayouts();
+       for (; cit != end; ++cit) {
+               TextClass::InsetLayouts::const_iterator it = ils.find(*cit);
+               if (it == ils.end())
+                       continue;
+               tcpreamble << it->second.htmlstyle();
+       }
+
+       return tcpreamble.str();
+}
+
+
+docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel) const
+{
+       DocumentClass const & tclass = params_.documentClass();
+       // collect preamble snippets in a set to prevent multiple identical
+       // commands (would happen if e.g. both theorem and theorem* are used)
+       set<docstring> snippets;
        typedef LanguageList::const_iterator lang_it;
        lang_it const lbeg = UsedLanguages_.begin();
        lang_it const lend =  UsedLanguages_.end();
        list<docstring>::const_iterator cit = usedLayouts_.begin();
        list<docstring>::const_iterator end = usedLayouts_.end();
        for (; cit != end; ++cit) {
-               tcpreamble << tclass[*cit].preamble();
-               tcpreamble << tclass[*cit].i18npreamble(buffer().language());
-               for (lang_it lit = lbeg; lit != lend; ++lit)
-                       tcpreamble << tclass[*cit].i18npreamble(*lit);
+               // language dependent commands (once per document)
+               snippets.insert(tclass[*cit].langpreamble(buffer().language()));
+               // commands for language changing (for multilanguage documents)
+               if (use_babel && !UsedLanguages_.empty()) {
+                       snippets.insert(tclass[*cit].babelpreamble(buffer().language()));
+                       for (lang_it lit = lbeg; lit != lend; ++lit)
+                               snippets.insert(tclass[*cit].babelpreamble(*lit));
+               }
        }
 
+       odocstringstream tcpreamble;
+       set<docstring>::const_iterator const send = snippets.end();
+       set<docstring>::const_iterator it = snippets.begin();
+       for (; it != send; ++it)
+               tcpreamble << *it;
        return tcpreamble.str();
 }