]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeXFeatures.cpp
The logic of the endParagraph() routine is wrong. We should first
[lyx.git] / src / LaTeXFeatures.cpp
index 528ef460ceca6f20c0a2e63cfd121986161fddfd..f1d315cae84e3341ebea09efdff2715cce1b9aeb 100644 (file)
@@ -161,7 +161,7 @@ static docstring const mathcircumflex_def = from_ascii(
 static docstring const tabularnewline_def = from_ascii(
        "%% Because html converters don't know tabularnewline\n"
        "\\providecommand{\\tabularnewline}{\\\\}\n");
-       
+
 static docstring const lyxgreyedout_def = from_ascii(
        "%% The greyedout annotation environment\n"
        "\\newenvironment{lyxgreyedout}\n"
@@ -266,10 +266,10 @@ static docstring const ogonek_def = from_ascii(
 
 static docstring const lyxref_def = from_ascii(
                "\\RS@ifundefined{subref}\n"
-               "  {\\def\\RSsubtxt{section~}\\newref{sub}{name = \\RSsubtxt}}\n" 
+               "  {\\def\\RSsubtxt{section~}\\newref{sub}{name = \\RSsubtxt}}\n"
                "  {}\n"
                "\\RS@ifundefined{thmref}\n"
-               "  {\\def\\RSthmtxt{theorem~}\\newref{thm}{name = \\RSthmtxt}}\n" 
+               "  {\\def\\RSthmtxt{theorem~}\\newref{thm}{name = \\RSthmtxt}}\n"
                "  {}\n"
                "\\RS@ifundefined{lemref}\n"
                "  {\\def\\RSlemtxt{lemma~}\\newref{lem}{name = \\RSlemtxt}}\n" 
@@ -348,7 +348,7 @@ void LaTeXFeatures::useLayout(docstring const & layoutname)
        DocumentClass const & tclass = params_.documentClass();
        if (tclass.hasLayout(layoutname)) {
                // Is this layout already in usedLayouts?
-               if (find(usedLayouts_.begin(), usedLayouts_.end(), layoutname) 
+               if (find(usedLayouts_.begin(), usedLayouts_.end(), layoutname)
                    != usedLayouts_.end())
                        return;
 
@@ -380,7 +380,7 @@ void LaTeXFeatures::useInsetLayout(InsetLayout const & lay)
        if (!tclass.hasInsetLayout(lname))
                return;
        // Is this layout already in usedInsetLayouts?
-       if (find(usedInsetLayouts_.begin(), usedInsetLayouts_.end(), lname) 
+       if (find(usedInsetLayouts_.begin(), usedInsetLayouts_.end(), lname)
                        != usedInsetLayouts_.end())
                return;
 
@@ -423,6 +423,15 @@ void LaTeXFeatures::addPreambleSnippet(string const & preamble)
 }
 
 
+void LaTeXFeatures::addCSSSnippet(std::string const & snippet)
+{
+       SnippetList::const_iterator begin = css_snippets_.begin();
+       SnippetList::const_iterator end   = css_snippets_.end();
+       if (find(begin, end, snippet) == end)
+               css_snippets_.push_back(snippet);
+}
+
+
 void LaTeXFeatures::useFloat(string const & name, bool subfloat)
 {
        if (!usedFloats_[name])
@@ -566,6 +575,8 @@ char const * simplefeatures[] = {
        "mathdesign",
        "mathrsfs",
        "mathabx",
+       "mathtools",
+       "cancel",
        "ascii",
        "url",
        "covington",
@@ -681,7 +692,7 @@ string const LaTeXFeatures::getPackages() const
                packages << amsPackages;
 
        // fixltx2e must be loaded after amsthm, since amsthm produces an error with
-       // the redefined \[ command (bug 7233). Load is as early as possible, since
+       // the redefined \[ command (bug 7233). Load it as early as possible, since
        // other packages might profit from it.
        if (mustProvide("fixltx2e"))
                packages << "\\usepackage{fixltx2e}\n";
@@ -695,28 +706,31 @@ string const LaTeXFeatures::getPackages() const
        // integral symbols from wasysym and amsmath.
        // See http://www.lyx.org/trac/ticket/1942
        if (mustProvide("wasysym") &&
-           (params_.use_esint != BufferParams::package_off || !isRequired("esint")))
+           params_.use_package("wasysym") != BufferParams::package_off &&
+           (params_.use_package("esint") != BufferParams::package_off || !isRequired("esint")))
                packages << "\\usepackage{wasysym}\n";
 
        // accents must be loaded after amsmath
-       if (mustProvide("accents"))
+       if (mustProvide("accents") &&
+           params_.use_package("accents") != BufferParams::package_off)
                packages << "\\usepackage{accents}\n";
 
        // mathdots must be loaded after amsmath
        if (mustProvide("mathdots") &&
-               params_.use_mathdots != BufferParams::package_off)
+               params_.use_package("mathdots") != BufferParams::package_off)
                packages << "\\usepackage{mathdots}\n";
 
        // yhmath must be loaded after amsmath
-       if (mustProvide("yhmath"))
+       if (mustProvide("yhmath") &&
+           params_.use_package("yhmath") != BufferParams::package_off)
                packages << "\\usepackage{yhmath}\n";
 
        if (mustProvide("undertilde") &&
-               params_.use_undertilde != BufferParams::package_off)
+               params_.use_package("undertilde") != BufferParams::package_off)
                packages << "\\usepackage{undertilde}\n";
 
        // [x]color and pdfcolmk are handled in getColorOptions() above
-       
+
        // makeidx.sty
        if (isRequired("makeidx") || isRequired("splitidx")) {
                if (!tclass.provides("makeidx") && !isRequired("splitidx"))
@@ -735,7 +749,7 @@ string const LaTeXFeatures::getPackages() const
                                 << params_.graphics_driver
                                 << "]{graphicx}\n";
        }
-       
+
        // lyxskak.sty --- newer chess support based on skak.sty
        if (mustProvide("chess"))
                packages << "\\usepackage[ps,mover]{lyxskak}\n";
@@ -747,7 +761,7 @@ string const LaTeXFeatures::getPackages() const
        // esint must be after amsmath and wasysym, since it will redeclare
        // inconsistent integral symbols
        if (mustProvide("esint") &&
-           params_.use_esint != BufferParams::package_off)
+           params_.use_package("esint") != BufferParams::package_off)
                packages << "\\usepackage{esint}\n";
 
        // natbib.sty
@@ -756,7 +770,7 @@ string const LaTeXFeatures::getPackages() const
        // This special case is indicated by the "natbib-internal" key.
        if (mustProvide("natbib") && !tclass.provides("natbib-internal")) {
                packages << "\\usepackage[";
-               if (params_.citeEngine() == ENGINE_NATBIB_NUMERICAL)
+               if (params_.citeEngineType() == ENGINE_TYPE_NUMERICAL)
                        packages << "numbers";
                else
                        packages << "authoryear";
@@ -766,7 +780,7 @@ string const LaTeXFeatures::getPackages() const
        // jurabib -- we need version 0.6 at least.
        if (mustProvide("jurabib"))
                packages << "\\usepackage{jurabib}[2004/01/25]\n";
-       
+
        // xargs -- we need version 1.09 at least
        if (mustProvide("xargs"))
                packages << "\\usepackage{xargs}[2008/03/08]\n";
@@ -786,9 +800,8 @@ string const LaTeXFeatures::getPackages() const
                packages << "\\PassOptionsToPackage{normalem}{ulem}\n"
                            "\\usepackage{ulem}\n";
 
-       if (params_.use_mhchem == BufferParams::package_on ||
-           (mustProvide("mhchem") &&
-            params_.use_mhchem != BufferParams::package_off))
+       if (mustProvide("mhchem") &&
+           params_.use_package("mhchem") != BufferParams::package_off)
                packages << "\\PassOptionsToPackage{version=3}{mhchem}\n"
                            "\\usepackage{mhchem}\n";
 
@@ -811,7 +824,7 @@ string const LaTeXFeatures::getPackages() const
 }
 
 
-string LaTeXFeatures::getPreambleSnippets() const 
+string LaTeXFeatures::getPreambleSnippets() const
 {
        ostringstream snip;
        SnippetList::const_iterator pit  = preamble_snippets_.begin();
@@ -822,6 +835,17 @@ string LaTeXFeatures::getPreambleSnippets() const
 }
 
 
+std::string LaTeXFeatures::getCSSSnippets() const
+{
+       ostringstream snip;
+       SnippetList::const_iterator pit  = css_snippets_.begin();
+       SnippetList::const_iterator pend = css_snippets_.end();
+       for (; pit != pend; ++pit)
+               snip << *pit << '\n';
+       return snip.str();
+}
+
+
 docstring const LaTeXFeatures::getMacros() const
 {
        odocstringstream macros;
@@ -942,17 +966,17 @@ docstring const LaTeXFeatures::getMacros() const
 
        // floats
        getFloatDefinitions(macros);
-       
-       if (mustProvide("refstyle")) 
-               macros << lyxref_def << '\n';   
-       
+
+       if (mustProvide("refstyle"))
+               macros << lyxref_def << '\n';
+
        // change tracking
        if (mustProvide("ct-dvipost"))
                macros << changetracking_dvipost_def;
-       
+
        if (mustProvide("ct-xcolor-ulem")) {
                streamsize const prec = macros.precision(2);
-       
+
                RGBColor cadd = rgbFromHexName(lcolor.getX11Name(Color_addedtext));
                macros << "\\providecolor{lyxadded}{rgb}{"
                       << cadd.r / 255.0 << ',' << cadd.g / 255.0 << ',' << cadd.b / 255.0 << "}\n";
@@ -962,7 +986,7 @@ docstring const LaTeXFeatures::getMacros() const
                       << cdel.r / 255.0 << ',' << cdel.g / 255.0 << ',' << cdel.b / 255.0 << "}\n";
 
                macros.precision(prec);
-               
+
                if (isRequired("hyperref"))
                        macros << changetracking_xcolor_ulem_hyperref_def;
                else
@@ -1030,7 +1054,7 @@ string const LaTeXFeatures::loadAMSPackages() const
                tmp << "\\usepackage{amsthm}\n";
 
        if (mustProvide("amsmath")
-           && params_.use_amsmath != BufferParams::package_off) {
+           && params_.use_package("amsmath") != BufferParams::package_off) {
                tmp << "\\usepackage{amsmath}\n";
        } else {
                // amsbsy and amstext are already provided by amsmath
@@ -1041,7 +1065,7 @@ string const LaTeXFeatures::loadAMSPackages() const
        }
 
        if (mustProvide("amssymb")
-           || params_.use_amsmath == BufferParams::package_on)
+           || params_.use_package("amsmath") == BufferParams::package_on)
                tmp << "\\usepackage{amssymb}\n";
 
        return tmp.str();
@@ -1075,7 +1099,7 @@ docstring const LaTeXFeatures::getTClassPreamble() const
 }
 
 
-docstring const LaTeXFeatures::getTClassHTMLPreamble() const 
+docstring const LaTeXFeatures::getTClassHTMLPreamble() const
 {
        DocumentClass const & tclass = params_.documentClass();
        odocstringstream tcpreamble;
@@ -1101,10 +1125,13 @@ docstring const LaTeXFeatures::getTClassHTMLPreamble() const
 }
 
 
-docstring const LaTeXFeatures::getTClassHTMLStyles() const {
+docstring const LaTeXFeatures::getTClassHTMLStyles() const
+{
        DocumentClass const & tclass = params_.documentClass();
        odocstringstream tcpreamble;
 
+       tcpreamble << tclass.htmlstyles();
+
        list<docstring>::const_iterator cit = usedLayouts_.begin();
        list<docstring>::const_iterator end = usedLayouts_.end();
        for (; cit != end; ++cit)
@@ -1129,6 +1156,15 @@ docstring const getFloatI18nPreamble(docstring const & type,
                        docstring const & name, Language const * lang,
                        Encoding const & enc, bool const polyglossia)
 {
+       // Check whether name can be encoded in the buffer encoding
+       bool encodable = true;
+       for (size_t i = 0; i < name.size(); ++i) {
+               if (!enc.encodable(name[i])) {
+                       encodable = false;
+                       break;
+               }
+       }
+
        docstring const language = polyglossia ? from_ascii(lang->polyglossia())
                                               : from_ascii(lang->babel());
        docstring const langenc = from_ascii(lang->encoding()->iconvName());
@@ -1136,9 +1172,9 @@ docstring const getFloatI18nPreamble(docstring const & type,
        docstring const bufenc = from_ascii(enc.iconvName());
        docstring const s1 = docstring(1, 0xF0000);
        docstring const s2 = docstring(1, 0xF0001);
-       docstring const translated = (langenc == bufenc) ? name
+       docstring const translated = encodable ? name
                : from_ascii("\\inputencoding{") + texenc + from_ascii("}")
-                       + s1 + langenc + s2 + translated + s1 + bufenc + s2;
+                       + s1 + langenc + s2 + name + s1 + bufenc + s2;
 
        odocstringstream os;
        os << "\\addto\\captions" << language
@@ -1183,7 +1219,7 @@ docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel, bool use_po
                UsedFloats::const_iterator fend = usedFloats_.end();
                for (; fit != fend; ++fit) {
                        Floating const & fl = floats.getType(fit->first);
-                       // we assume builtin floats are translated 
+                       // we assume builtin floats are translated
                        if (fl.isPredefined())
                                continue;
                        docstring const type = from_ascii(fl.floattype());