]> git.lyx.org Git - lyx.git/blobdiff - src/LaTeXFeatures.cpp
tex2lyx: add strike-outs etc. to the TeX testfile
[lyx.git] / src / LaTeXFeatures.cpp
index 2cfc1ce6e2275940c4cb69f7f97f0eb3b11634f9..623204337496372b6b17e13de09b7c6f12c58c60 100644 (file)
@@ -599,7 +599,10 @@ char const * simplefeatures[] = {
        "ifsym",
        "marvosym",
        "txfonts",
+       "pxfonts",
+       "mathdesign",
        "mathrsfs",
+       "mathabx",
        "ascii",
        "url",
        "covington",
@@ -614,8 +617,7 @@ char const * simplefeatures[] = {
        "amscd",
        "slashed",
        "multirow",
-       "tfrupee",
-       "undertilde",
+       "tfrupee"
 };
 
 int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *);
@@ -711,8 +713,9 @@ string const LaTeXFeatures::getPackages() const
 
        // if fontspec is used, AMS packages have to be loaded before
        // fontspec (in BufferParams)
-       if (!params_.useNonTeXFonts && !loadAMSPackages().empty())
-               packages << loadAMSPackages();
+       string const amsPackages = loadAMSPackages();
+       if (!params_.useNonTeXFonts && !amsPackages.empty())
+               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
@@ -745,6 +748,10 @@ string const LaTeXFeatures::getPackages() const
        if (mustProvide("yhmath"))
                packages << "\\usepackage{yhmath}\n";
 
+       if (mustProvide("undertilde") &&
+               params_.use_undertilde != BufferParams::package_off)
+               packages << "\\usepackage{undertilde}\n";
+
        // [x]color and pdfcolmk are handled in getColorOptions() above
        
        // makeidx.sty
@@ -776,7 +783,7 @@ string const LaTeXFeatures::getPackages() const
 
        // esint must be after amsmath and wasysym, since it will redeclare
        // inconsistent integral symbols
-       if ((mustProvide("esint") || mustProvide("esintoramsmath")) &&
+       if (mustProvide("esint") &&
            params_.use_esint != BufferParams::package_off)
                packages << "\\usepackage{esint}\n";
 
@@ -1059,12 +1066,8 @@ string const LaTeXFeatures::loadAMSPackages() const
        if (mustProvide("amsthm"))
                tmp << "\\usepackage{amsthm}\n";
 
-       // esint is preferred for esintoramsmath
-       if ((mustProvide("amsmath")
-            && params_.use_amsmath != BufferParams::package_off)
-           || (mustProvide("esintoramsmath")
-               && params_.use_esint == BufferParams::package_off
-               && params_.use_amsmath != BufferParams::package_off)) {
+       if (mustProvide("amsmath")
+           && params_.use_amsmath != BufferParams::package_off) {
                tmp << "\\usepackage{amsmath}\n";
        } else {
                // amsbsy and amstext are already provided by amsmath
@@ -1073,7 +1076,7 @@ string const LaTeXFeatures::loadAMSPackages() const
                if (mustProvide("amstext"))
                        tmp << "\\usepackage{amstext}\n";
        }
-       
+
        if (mustProvide("amssymb")
            || params_.use_amsmath == BufferParams::package_on)
                tmp << "\\usepackage{amssymb}\n";
@@ -1159,11 +1162,24 @@ docstring const LaTeXFeatures::getTClassHTMLStyles() const {
 
 
 namespace {
-docstring const getFloatI18nPreamble(docstring const & type, docstring const & name, docstring const & lang)
+docstring const getFloatI18nPreamble(docstring const & type,
+                       docstring const & name, Language const * lang,
+                       Encoding const & enc, bool const polyglossia)
 {
+       docstring const language = polyglossia ? from_ascii(lang->polyglossia())
+                                              : from_ascii(lang->babel());
+       docstring const langenc = from_ascii(lang->encoding()->iconvName());
+       docstring const texenc = from_ascii(lang->encoding()->latexName());
+       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
+               : from_ascii("\\inputencoding{") + texenc + from_ascii("}")
+                       + s1 + langenc + s2 + translated + s1 + bufenc + s2;
+
        odocstringstream os;
-       os << "\\addto\\captions" << lang
-          << "{\\renewcommand{\\" << type << "name}{" << name << "}}\n";
+       os << "\\addto\\captions" << language
+          << "{\\renewcommand{\\" << type << "name}{" << translated << "}}\n";
        return os.str();
 }
 }
@@ -1183,13 +1199,19 @@ docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel, bool use_po
        for (; cit != end; ++cit) {
                // language dependent commands (once per document)
                snippets.insert(tclass[*cit].langpreamble(buffer().language(),
-                                                         use_polyglossia));
+                                               buffer().params().encoding(),
+                                               use_polyglossia));
                // commands for language changing (for multilanguage documents)
                if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
-                       snippets.insert(tclass[*cit].babelpreamble(buffer().language(),
-                                                                  use_polyglossia));
+                       snippets.insert(tclass[*cit].babelpreamble(
+                                               buffer().language(),
+                                               buffer().params().encoding(),
+                                               use_polyglossia));
                        for (lang_it lit = lbeg; lit != lend; ++lit)
-                               snippets.insert(tclass[*cit].babelpreamble(*lit, use_polyglossia));
+                               snippets.insert(tclass[*cit].babelpreamble(
+                                               *lit,
+                                               buffer().params().encoding(),
+                                               use_polyglossia));
                }
        }
        if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) {
@@ -1206,14 +1228,11 @@ docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel, bool use_po
                        docstring name = buffer().language()->translateLayout(fl.name());
                        // only request translation if we have a real translation
                        // (that differs from the source)
-                       if (use_polyglossia && flname != name)
-                               snippets.insert(getFloatI18nPreamble(
-                                       type, name,
-                                       from_ascii(buffer().language()->polyglossia())));
-                       else if (flname != name)
+                       if (flname != name)
                                snippets.insert(getFloatI18nPreamble(
-                                       type, name,
-                                       from_ascii(buffer().language()->babel())));
+                                               type, name, buffer().language(),
+                                               buffer().params().encoding(),
+                                               use_polyglossia));
                        for (lang_it lit = lbeg; lit != lend; ++lit) {
                                string const code = (*lit)->code();
                                name = (*lit)->translateLayout(fl.name());
@@ -1224,14 +1243,11 @@ docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel, bool use_po
                                // something different to the English source.
                                bool const have_translation =
                                        (flname != name || contains(code, "en"));
-                               if (use_polyglossia && have_translation)
-                                       snippets.insert(getFloatI18nPreamble(
-                                               type, name,
-                                               from_ascii((*lit)->polyglossia())));
-                               else if (have_translation)
+                               if (have_translation)
                                        snippets.insert(getFloatI18nPreamble(
-                                               type, name,
-                                               from_ascii((*lit)->babel())));
+                                               type, name, *lit,
+                                               buffer().params().encoding(),
+                                               use_polyglossia));
                        }
                }
        }
@@ -1372,4 +1388,25 @@ void LaTeXFeatures::getFloatDefinitions(odocstream & os) const
 }
 
 
+void LaTeXFeatures::resolveAlternatives()
+{
+       for (Features::iterator it = features_.begin(); it != features_.end();) {
+               if (contains(*it, '|')) {
+                       vector<string> const alternatives = getVectorFromString(*it, "|");
+                       vector<string>::const_iterator const end = alternatives.end();
+                       vector<string>::const_iterator ita = alternatives.begin();
+                       for (; ita != end; ++ita) {
+                               if (isRequired(*ita))
+                                       break;
+                       }
+                       if (ita == end)
+                               require(alternatives.front());
+                       features_.erase(it);
+                       it = features_.begin();
+               } else
+                       ++it;
+       }
+}
+
+
 } // namespace lyx