X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FLaTeXFeatures.cpp;h=bdf264f9728af0052f02e792225a2787069fc529;hb=a5b01f8f96efc95633a8da1cf4748aa473a89f1a;hp=f694e53797411d99130da7f71db8101307735de2;hpb=fa8dae4201fc25da685a21de0f8968678df8f119;p=lyx.git diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index f694e53797..bdf264f972 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -60,6 +60,11 @@ namespace lyx { static docstring const lyx_def = from_ascii( "\\providecommand{\\LyX}{L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}"); +static docstring const lyx_hyperref_def = from_ascii( + "\\providecommand{\\LyX}{\\texorpdfstring%\n" + " {L\\kern-.1667em\\lower.25em\\hbox{Y}\\kern-.125emX\\@}\n" + " {LyX}}"); + static docstring const noun_def = from_ascii( "\\newcommand{\\noun}[1]{\\textsc{#1}}"); @@ -158,7 +163,9 @@ static docstring const tabularnewline_def = from_ascii( static docstring const lyxgreyedout_def = from_ascii( "%% The greyedout annotation environment\n" - "\\newenvironment{lyxgreyedout}{\\textcolor{note_fontcolor}\\bgroup}{\\egroup}\n"); + "\\newenvironment{lyxgreyedout}\n" + " {\\textcolor{note_fontcolor}\\bgroup\\ignorespaces}\n" + " {\\ignorespacesafterend\\egroup}\n"); // We want to omit the file extension for includegraphics, but this does not // work when the filename contains other dots. @@ -285,11 +292,12 @@ LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p, bool LaTeXFeatures::useBabel() const { + if (usePolyglossia()) + return false; return (lyxrc.language_package_selection != LyXRC::LP_NONE) - && !usePolyglossia() - && ((bufferParams().language->lang() != lyxrc.default_language + || (bufferParams().language->lang() != lyxrc.default_language && !bufferParams().language->babel().empty()) - || this->hasLanguages()); + || this->hasLanguages(); } @@ -298,9 +306,7 @@ bool LaTeXFeatures::usePolyglossia() const return (lyxrc.language_package_selection == LyXRC::LP_AUTO) && isRequired("polyglossia") && isAvailable("polyglossia") - && ((bufferParams().language->lang() != lyxrc.default_language - && !bufferParams().language->polyglossia().empty()) - || this->hasLanguages()) + && !params_.documentClass().provides("babel") && this->hasPolyglossiaLanguages(); } @@ -577,7 +583,6 @@ char const * simplefeatures[] = { "framed", "soul", "textcomp", - "subscript", "pmboxdraw", "bbding", "ifsym", @@ -590,8 +595,8 @@ char const * simplefeatures[] = { "csquotes", "enumitem", "endnotes", + "hhline", "ifthen", - "amsthm", // listings is handled in BufferParams.cpp "bm", "pdfpages", @@ -618,12 +623,12 @@ string const LaTeXFeatures::getColorOptions() const if (mustProvide("color") || mustProvide("xcolor")) { string const package = (mustProvide("xcolor") ? "xcolor" : "color"); - if (params_.graphicsDriver == "default" - || params_.graphicsDriver == "none") + if (params_.graphics_driver == "default" + || params_.graphics_driver == "none") colors << "\\usepackage{" << package << "}\n"; else colors << "\\usepackage[" - << params_.graphicsDriver + << params_.graphics_driver << "]{" << package << "}\n"; } @@ -692,21 +697,17 @@ string const LaTeXFeatures::getPackages() const // than those above. // - // 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)) { - packages << "\\usepackage{amsmath}\n"; - } else { - // amsbsy and amstext are already provided by amsmath - if (mustProvide("amsbsy")) - packages << "\\usepackage{amsbsy}\n"; - if (mustProvide("amstext")) - packages << "\\usepackage{amstext}\n"; - } - + // if fontspec is used, AMS packages have to be loaded before + // fontspec (in BufferParams) + if (!params_.useNonTeXFonts && !loadAMSPackages().empty()) + packages << loadAMSPackages(); + + // fixltx2e must be loaded after amsthm, since amsthm produces an error with + // the redefined \[ command (bug 7233). Load is as early as possible, since + // other packages might profit from it. + if (mustProvide("fixltx2e")) + packages << "\\usepackage{fixltx2e}\n"; + // wasysym is a simple feature, but it must be after amsmath if both // are used // wasysym redefines some integrals (e.g. iint) from amsmath. That @@ -744,12 +745,12 @@ string const LaTeXFeatures::getPackages() const } // graphicx.sty - if (mustProvide("graphicx") && params_.graphicsDriver != "none") { - if (params_.graphicsDriver == "default") + if (mustProvide("graphicx") && params_.graphics_driver != "none") { + if (params_.graphics_driver == "default") packages << "\\usepackage{graphicx}\n"; else packages << "\\usepackage[" - << params_.graphicsDriver + << params_.graphics_driver << "]{graphicx}\n"; } @@ -761,11 +762,6 @@ string const LaTeXFeatures::getPackages() const if (mustProvide("setspace") && !tclass.provides("SetSpace")) packages << "\\usepackage{setspace}\n"; - // amssymb.sty - if (mustProvide("amssymb") - || params_.use_amsmath == BufferParams::package_on) - packages << "\\usepackage{amssymb}\n"; - // esint must be after amsmath and wasysym, since it will redeclare // inconsistent integral symbols if ((mustProvide("esint") || mustProvide("esintoramsmath")) && @@ -825,6 +821,10 @@ string const LaTeXFeatures::getPackages() const "\\makenomenclature\n"; } + // fixltx2e provides subscript + if (mustProvide("subscript") && !isRequired("fixltx2e")) + packages << "\\usepackage{subscript}\n"; + return packages.str(); } @@ -856,8 +856,12 @@ docstring const LaTeXFeatures::getMacros() const macros << papersizepdf_def << '\n'; } - if (mustProvide("LyX")) - macros << lyx_def << '\n'; + if (mustProvide("LyX")) { + if (isRequired("hyperref")) + macros << lyx_hyperref_def << '\n'; + else + macros << lyx_def << '\n'; + } if (mustProvide("noun")) macros << noun_def << '\n'; @@ -868,7 +872,7 @@ docstring const LaTeXFeatures::getMacros() const if (!usePolyglossia() && mustProvide("textgreek")) { // Avoid a LaTeX error if times fonts are used and the grtimes // package is installed but actual fonts are not (bug 6469). - if (params_.fontsRoman == "times") + if (params_.fonts_roman == "times") macros << subst(textgreek_def, from_ascii("\\greektext #1"), from_ascii("%\n \\IfFileExists" @@ -1037,6 +1041,35 @@ bool LaTeXFeatures::needBabelLangOptions() const } +string const LaTeXFeatures::loadAMSPackages() const +{ + ostringstream tmp; + 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)) { + tmp << "\\usepackage{amsmath}\n"; + } else { + // amsbsy and amstext are already provided by amsmath + if (mustProvide("amsbsy")) + tmp << "\\usepackage{amsbsy}\n"; + if (mustProvide("amstext")) + tmp << "\\usepackage{amstext}\n"; + } + + if (mustProvide("amssymb") + || params_.use_amsmath == BufferParams::package_on) + tmp << "\\usepackage{amssymb}\n"; + + return tmp.str(); +} + + docstring const LaTeXFeatures::getTClassPreamble() const { // the text class specific preamble @@ -1124,7 +1157,7 @@ docstring const getFloatI18nPreamble(docstring const & type, docstring const & n } -docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel) const +docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel, bool use_polyglossia) const { DocumentClass const & tclass = params_.documentClass(); // collect preamble snippets in a set to prevent multiple identical @@ -1137,15 +1170,17 @@ docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel) const list::const_iterator end = usedLayouts_.end(); for (; cit != end; ++cit) { // language dependent commands (once per document) - snippets.insert(tclass[*cit].langpreamble(buffer().language())); + snippets.insert(tclass[*cit].langpreamble(buffer().language(), + use_polyglossia)); // commands for language changing (for multilanguage documents) - if (use_babel && !UsedLanguages_.empty()) { - snippets.insert(tclass[*cit].babelpreamble(buffer().language())); + if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) { + snippets.insert(tclass[*cit].babelpreamble(buffer().language(), + use_polyglossia)); for (lang_it lit = lbeg; lit != lend; ++lit) - snippets.insert(tclass[*cit].babelpreamble(*lit)); + snippets.insert(tclass[*cit].babelpreamble(*lit, use_polyglossia)); } } - if (use_babel && !UsedLanguages_.empty()) { + if ((use_babel || use_polyglossia) && !UsedLanguages_.empty()) { FloatList const & floats = params_.documentClass().floats(); UsedFloats::const_iterator fit = usedFloats_.begin(); UsedFloats::const_iterator fend = usedFloats_.end(); @@ -1155,15 +1190,25 @@ docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel) const docstring const flname = from_utf8(fl.name()); docstring name = translateIfPossible(flname, buffer().language()->code()); - snippets.insert(getFloatI18nPreamble( - type, name, - from_ascii(buffer().language()->babel()))); + if (use_polyglossia) + snippets.insert(getFloatI18nPreamble( + type, name, + from_ascii(buffer().language()->polyglossia()))); + else + snippets.insert(getFloatI18nPreamble( + type, name, + from_ascii(buffer().language()->babel()))); for (lang_it lit = lbeg; lit != lend; ++lit) { name = translateIfPossible(flname, (*lit)->code()); - snippets.insert(getFloatI18nPreamble( - type, name, - from_ascii((*lit)->babel()))); + if (use_polyglossia) + snippets.insert(getFloatI18nPreamble( + type, name, + from_ascii((*lit)->polyglossia()))); + else + snippets.insert(getFloatI18nPreamble( + type, name, + from_ascii((*lit)->babel()))); } } }