X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLaTeXFeatures.cpp;h=48c416dc0e778f96c7a564743d89497797299fb3;hb=10be0c43f20a27a1e6af82241ad5ec6b5cad3eca;hp=400dfb6c3e133708a91ab13adf39362f2fb223e2;hpb=96ca121fc959f28eaa054e975907c97f3cee7db9;p=lyx.git diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 400dfb6c3e..48c416dc0e 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -134,24 +134,6 @@ static docstring const paragraphleftindent_def = from_ascii( "}\n" "{\\end{list}}\n"); -static docstring const floatingfootnote_def = from_ascii( - "%% Special footnote code from the package 'stblftnt.sty'\n" - "%% Author: Robin Fairbairns -- Last revised Dec 13 1996\n" - "\\let\\SF@@footnote\\footnote\n" - "\\def\\footnote{\\ifx\\protect\\@typeset@protect\n" - " \\expandafter\\SF@@footnote\n" - " \\else\n" - " \\expandafter\\SF@gobble@opt\n" - " \\fi\n" - "}\n" - "\\expandafter\\def\\csname SF@gobble@opt \\endcsname{\\@ifnextchar[%]\n" - " \\SF@gobble@twobracket\n" - " \\@gobble\n" - "}\n" - "\\edef\\SF@gobble@opt{\\noexpand\\protect\n" - " \\expandafter\\noexpand\\csname SF@gobble@opt \\endcsname}\n" - "\\def\\SF@gobble@twobracket[#1]#2{}\n"); - static docstring const binom_def = from_ascii( "%% Binom macro for standard LaTeX users\n" "\\newcommand{\\binom}[2]{{#1 \\choose #2}}\n"); @@ -833,6 +815,22 @@ string const LaTeXFeatures::getColorOptions() const } +string const LaTeXFeatures::getPackageOptions() const +{ + ostringstream packageopts; + // Output all the package option stuff we have been asked to do. + map::const_iterator it = + params_.documentClass().packageOptions().begin(); + map::const_iterator en = + params_.documentClass().packageOptions().end(); + for (; it != en; ++it) + if (mustProvide(it->first)) + packageopts << "\\PassOptionsToPackage{" << it->second << "}" + << "{" << it->first << "}\n"; + return packageopts.str(); +} + + string const LaTeXFeatures::getPackages() const { ostringstream packages; @@ -843,16 +841,6 @@ string const LaTeXFeatures::getPackages() const // also unknown packages can be requested. They are silently // swallowed now. We should change this eventually. - // Output all the package option stuff we have been asked to do. - map::const_iterator it = - params_.documentClass().packageOptions().begin(); - map::const_iterator en = - params_.documentClass().packageOptions().end(); - for (; it != en; ++it) - if (mustProvide(it->first)) - packages << "\\PassOptionsToPackage{" << it->second << "}" - << "{" << it->first << "}\n"; - // These are all the 'simple' includes. i.e // packages which we just \usepackage{package} for (int i = 0; i < nb_simplefeatures; ++i) { @@ -1050,6 +1038,12 @@ string const LaTeXFeatures::getPackages() const if (mustProvide("subscript") && !isRequired("fixltx2e")) packages << "\\usepackage{subscript}\n"; + // footmisc must be loaded after setspace + // Set options here, load the package after the user preamble to + // avoid problems with manual loaded footmisc. + if (mustProvide("footmisc")) + packages << "\\PassOptionsToPackage{stable}{footmisc}\n"; + return packages.str(); } @@ -1178,8 +1172,6 @@ docstring const LaTeXFeatures::getMacros() const // other if (mustProvide("ParagraphLeftIndent")) macros << paragraphleftindent_def; - if (mustProvide("NeedLyXFootnoteCode")) - macros << floatingfootnote_def; // some problems with tex->html converters if (mustProvide("NeedTabularnewline")) @@ -1431,7 +1423,8 @@ docstring const getFloatI18nPreamble(docstring const & type, docstring const i18npreamble(docstring const & templ, Language const * lang, - Encoding const & enc, bool const polyglossia) + Encoding const & enc, bool const polyglossia, + bool const need_fixedwidth) { if (templ.empty()) return templ; @@ -1443,6 +1436,24 @@ docstring const i18npreamble(docstring const & templ, Language const * lang, string const langenc = lang->encoding()->iconvName(); string const texenc = lang->encoding()->latexName(); string const bufenc = enc.iconvName(); + Encoding const * testenc(&enc); + bool lang_fallback = false; + bool ascii_fallback = false; + if (need_fixedwidth && !enc.hasFixedWidth()) { + if (lang->encoding()->hasFixedWidth()) { + testenc = lang->encoding(); + lang_fallback = true; + } else { + // We need a fixed width encoding, but both the buffer + // encoding and the language encoding are variable + // width. As a last fallback, try to convert to pure + // ASCII using the LaTeX commands defined in unicodesymbols. + testenc = encodings.fromLyXName("ascii"); + if (!testenc) + return docstring(); + ascii_fallback = true; + } + } // First and second character of plane 15 (Private Use Area) string const s1 = "\xf3\xb0\x80\x80"; // U+F0000 string const s2 = "\xf3\xb0\x80\x81"; // U+F0001 @@ -1456,16 +1467,18 @@ docstring const i18npreamble(docstring const & templ, Language const * lang, docstring const name = lang->translateLayout(key); // 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])) { + for (size_t i = 0; i < name.size() && encodable; ++i) + if (!testenc->encodable(name[i])) encodable = false; - break; - } - } - string const translated = encodable ? to_utf8(name) - : "\\inputencoding{" + texenc + "}" - + s1 + langenc + s2 + to_utf8(name) - + s1 + bufenc + s2; + string translated; + if (encodable && !lang_fallback) + translated = to_utf8(name); + else if (ascii_fallback) + translated = to_ascii(testenc->latexString(name).first); + else + translated = "\\inputencoding{" + texenc + "}" + + s1 + langenc + s2 + to_utf8(name) + + s1 + bufenc + s2; preamble = subst(preamble, sub.str(), translated); } return from_utf8(preamble); @@ -1490,20 +1503,20 @@ docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel, bool use_po snippets.insert(i18npreamble(tclass[*cit].langpreamble(), buffer().language(), buffer().params().encoding(), - use_polyglossia)); + use_polyglossia, false)); // commands for language changing (for multilanguage documents) if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) { snippets.insert(i18npreamble( tclass[*cit].babelpreamble(), buffer().language(), buffer().params().encoding(), - use_polyglossia)); + use_polyglossia, false)); for (lang_it lit = lbeg; lit != lend; ++lit) snippets.insert(i18npreamble( tclass[*cit].babelpreamble(), *lit, buffer().params().encoding(), - use_polyglossia)); + use_polyglossia, false)); } } if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) { @@ -1551,24 +1564,30 @@ docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel, bool use_po TextClass::InsetLayouts::const_iterator it = ils.find(*cit); if (it == ils.end()) continue; + // The listings package does not work with variable width + // encodings, only with fixed width encodings. Therefore we + // need to force a fixed width encoding for + // \lstlistlistingname and \lstlistingname (bug 9382). + // This needs to be consistent with InsetListings::latex(). + bool const need_fixedwidth = it->second.fixedwidthpreambleencoding(); // language dependent commands (once per document) snippets.insert(i18npreamble(it->second.langpreamble(), buffer().language(), buffer().params().encoding(), - use_polyglossia)); + use_polyglossia, need_fixedwidth)); // commands for language changing (for multilanguage documents) if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) { snippets.insert(i18npreamble( it->second.babelpreamble(), buffer().language(), buffer().params().encoding(), - use_polyglossia)); + use_polyglossia, need_fixedwidth)); for (lang_it lit = lbeg; lit != lend; ++lit) snippets.insert(i18npreamble( it->second.babelpreamble(), *lit, buffer().params().encoding(), - use_polyglossia)); + use_polyglossia, need_fixedwidth)); } }