X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLaTeXFeatures.cpp;h=b72054d9ffd7c56ec291cea5ebf14ad82c9bb6be;hb=55a3dd7b346d29a52ba305a4558e9e380ef50f47;hp=bdf264f9728af0052f02e792225a2787069fc529;hpb=1ef605f6254ef3f3b8cec5440a2e67e6f23a707b;p=lyx.git diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index bdf264f972..b72054d9ff 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -24,6 +24,7 @@ #include "Floating.h" #include "FloatList.h" #include "Language.h" +#include "LaTeXPackages.h" #include "Layout.h" #include "Lexer.h" #include "LyXRC.h" @@ -160,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" @@ -265,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" @@ -281,8 +282,6 @@ static docstring const lyxref_def = from_ascii( // ///////////////////////////////////////////////////////////////////// -LaTeXFeatures::Packages LaTeXFeatures::packages_; - LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p, OutputParams const & r) @@ -294,20 +293,31 @@ bool LaTeXFeatures::useBabel() const { if (usePolyglossia()) return false; - return (lyxrc.language_package_selection != LyXRC::LP_NONE) - || (bufferParams().language->lang() != lyxrc.default_language - && !bufferParams().language->babel().empty()) - || this->hasLanguages(); + if (bufferParams().lang_package == "default") + return (lyxrc.language_package_selection != LyXRC::LP_NONE) + || (bufferParams().language->lang() != lyxrc.default_language + && !bufferParams().language->babel().empty()) + || this->hasLanguages(); + return (bufferParams().lang_package != "none") + || (bufferParams().language->lang() != lyxrc.default_language + && !bufferParams().language->babel().empty()) + || this->hasLanguages(); } bool LaTeXFeatures::usePolyglossia() const { - return (lyxrc.language_package_selection == LyXRC::LP_AUTO) - && isRequired("polyglossia") - && isAvailable("polyglossia") - && !params_.documentClass().provides("babel") - && this->hasPolyglossiaLanguages(); + if (bufferParams().lang_package == "default") + return (lyxrc.language_package_selection == LyXRC::LP_AUTO) + && isRequired("polyglossia") + && isAvailable("polyglossia") + && !params_.documentClass().provides("babel") + && this->hasPolyglossiaLanguages(); + return (bufferParams().lang_package == "auto") + && isRequired("polyglossia") + && isAvailable("polyglossia") + && !params_.documentClass().provides("babel") + && this->hasPolyglossiaLanguages(); } @@ -323,36 +333,6 @@ void LaTeXFeatures::require(set const & names) } -void LaTeXFeatures::getAvailable() -{ - Lexer lex; - support::FileName const real_file = libFileSearch("", "packages.lst"); - - if (real_file.empty()) - return; - - lex.setFile(real_file); - - if (!lex.isOK()) - return; - - // Make sure that we are clean - packages_.clear(); - - bool finished = false; - // Parse config-file - while (lex.isOK() && !finished) { - switch (lex.lex()) { - case Lexer::LEX_FEOF: - finished = true; - break; - default: - packages_.insert(lex.getString()); - } - } -} - - void LaTeXFeatures::useLayout(docstring const & layoutname) { // Some code to avoid loops in dependency definition @@ -368,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; @@ -400,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; @@ -430,13 +410,7 @@ bool LaTeXFeatures::isAvailable(string const & name) //LYXERR0("from=[" << from << "] to=[" << to << "]"); return theConverters().isReachable(from, to); } - - if (packages_.empty()) - getAvailable(); - string n = name; - if (suffixIs(n, ".sty")) - n.erase(name.length() - 4); - return packages_.find(n) != packages_.end(); + return LaTeXPackages::isAvailable(name); } @@ -449,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]) @@ -459,7 +442,7 @@ void LaTeXFeatures::useFloat(string const & name, bool subfloat) // use the "H" modifier. This includes modified table and // figure floats. (Lgb) Floating const & fl = params_.documentClass().floats().getType(name); - if (!fl.floattype().empty() && fl.needsFloatPkg()) { + if (!fl.floattype().empty() && fl.usesFloatPkg()) { require("float"); } } @@ -588,7 +571,10 @@ char const * simplefeatures[] = { "ifsym", "marvosym", "txfonts", + "pxfonts", + "mathdesign", "mathrsfs", + "mathabx", "ascii", "url", "covington", @@ -699,8 +685,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 @@ -733,8 +720,12 @@ 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 if (isRequired("makeidx") || isRequired("splitidx")) { if (!tclass.provides("makeidx") && !isRequired("splitidx")) @@ -753,7 +744,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"; @@ -764,7 +755,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"; @@ -784,7 +775,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"; @@ -829,7 +820,7 @@ string const LaTeXFeatures::getPackages() const } -string LaTeXFeatures::getPreambleSnippets() const +string LaTeXFeatures::getPreambleSnippets() const { ostringstream snip; SnippetList::const_iterator pit = preamble_snippets_.begin(); @@ -840,6 +831,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; @@ -960,17 +962,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"; @@ -980,7 +982,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 @@ -1047,12 +1049,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 @@ -1061,7 +1059,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"; @@ -1097,7 +1095,7 @@ docstring const LaTeXFeatures::getTClassPreamble() const } -docstring const LaTeXFeatures::getTClassHTMLPreamble() const +docstring const LaTeXFeatures::getTClassHTMLPreamble() const { DocumentClass const & tclass = params_.documentClass(); odocstringstream tcpreamble; @@ -1123,10 +1121,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::const_iterator cit = usedLayouts_.begin(); list::const_iterator end = usedLayouts_.end(); for (; cit != end; ++cit) @@ -1147,11 +1148,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(); } } @@ -1171,13 +1185,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()) { @@ -1186,29 +1206,34 @@ 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 + if (fl.isPredefined()) + continue; docstring const type = from_ascii(fl.floattype()); docstring const flname = from_utf8(fl.name()); - docstring name = translateIfPossible(flname, - buffer().language()->code()); - if (use_polyglossia) - snippets.insert(getFloatI18nPreamble( - type, name, - from_ascii(buffer().language()->polyglossia()))); - else + docstring name = buffer().language()->translateLayout(fl.name()); + // only request translation if we have a real translation + // (that differs from the source) + 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) { - name = translateIfPossible(flname, - (*lit)->code()); - if (use_polyglossia) - snippets.insert(getFloatI18nPreamble( - type, name, - from_ascii((*lit)->polyglossia()))); - else + string const code = (*lit)->code(); + name = (*lit)->translateLayout(fl.name()); + // we assume we have a suitable translation if + // either the language is English (we need to + // translate into English if English is a secondary + // language) or if translateIfPossible returns + // something different to the English source. + bool const have_translation = + (flname != name || contains(code, "en")); + if (have_translation) snippets.insert(getFloatI18nPreamble( - type, name, - from_ascii((*lit)->babel()))); + type, name, *lit, + buffer().params().encoding(), + use_polyglossia)); } } } @@ -1297,7 +1322,7 @@ void LaTeXFeatures::getFloatDefinitions(odocstream & os) const Floating const & fl = floats.getType(cit->first); // For builtin floats we do nothing. - if (!fl.needsFloatPkg()) + if (fl.isPredefined()) continue; // We have to special case "table" and "figure" @@ -1325,9 +1350,8 @@ void LaTeXFeatures::getFloatDefinitions(odocstream & os) const docstring const ext = from_ascii(fl.ext()); docstring const within = from_ascii(fl.within()); docstring const style = from_ascii(fl.style()); - docstring const name = translateIfPossible( - from_utf8(fl.name()), - buffer().language()->code()); + docstring const name = + buffer().language()->translateLayout(fl.name()); os << "\\floatstyle{" << style << "}\n" << "\\newfloat{" << type << "}{" << placement << "}{" << ext << '}'; @@ -1350,4 +1374,25 @@ void LaTeXFeatures::getFloatDefinitions(odocstream & os) const } +void LaTeXFeatures::resolveAlternatives() +{ + for (Features::iterator it = features_.begin(); it != features_.end();) { + if (contains(*it, '|')) { + vector const alternatives = getVectorFromString(*it, "|"); + vector::const_iterator const end = alternatives.end(); + vector::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