From: Uwe Stöhr Date: Mon, 29 Sep 2008 19:18:00 +0000 (+0000) Subject: BufferParams.cpp, LaTeXFeatures.cpp: fix http://bugzilla.lyx.org/show_bug.cgi?id... X-Git-Tag: 1.6.10~3262 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=4c48e7746b245ef6e3ae30d98894edcabbf9fef3;hp=e400b46fd44fa4ad7d7f33120f3b74cca47daed8;p=features.git BufferParams.cpp, LaTeXFeatures.cpp: fix http://bugzilla.lyx.org/show_bug.cgi?id=5291 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26627 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 3870c1f552..1f7d0db196 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -917,8 +917,14 @@ void BufferParams::validate(LaTeXFeatures & features) const } } - if (pdfoptions().use_hyperref) + if (pdfoptions().use_hyperref) { features.require("hyperref"); + // due to interferences with babel and hyperref, the color package has to + // be loaded after hyperref when hyperref is used with the colorlinks + // option, see http://bugzilla.lyx.org/show_bug.cgi?id=5291 + if (pdfoptions().colorlinks) + features.require("color"); + } if (language->lang() == "vietnamese") features.require("vietnamese"); @@ -1249,23 +1255,30 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features, texrow.newline(); } - // If we use hyperref, jurabib, japanese, or vietnamese, we have to call babel here. + // Now insert the LyX specific LaTeX commands... + docstring lyxpreamble; + + // due to interferences with babel and hyperref, the color package has to + // be loaded (when it is not already loaded) before babel when hyperref + // is used with the colorlinks option, see + // http://bugzilla.lyx.org/show_bug.cgi?id=5291 + // we decided therefore to load color always before babel, see + // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg144349.html + lyxpreamble += from_ascii(features.getColorOptions()); + + // If we use hyperref, jurabib, japanese, or vietnamese, we have to call babel before them. if (use_babel && (features.isRequired("jurabib") || features.isRequired("hyperref") || features.isRequired("vietnamese") || features.isRequired("japanese") ) ) { - // FIXME UNICODE - os << from_utf8(babelCall(language_options.str())) - << '\n' - << from_utf8(features.getBabelOptions()); - texrow.newline(); + // FIXME UNICODE + lyxpreamble += from_utf8(babelCall(language_options.str())) + '\n'; + lyxpreamble += from_utf8(features.getBabelOptions()) + '\n'; } - // Now insert the LyX specific LaTeX commands... - // The optional packages; - docstring lyxpreamble(from_ascii(features.getPackages())); + lyxpreamble += from_ascii(features.getPackages()); // Line spacing lyxpreamble += from_utf8(spacing().writePreamble(tclass.provides("SetSpace"))); @@ -1284,7 +1297,7 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features, pdfoptions().writeLaTeX(oss, documentClass().provides("hyperref")); lyxpreamble += oss.str(); } - + // Will be surrounded by \makeatletter and \makeatother when needed docstring atlyxpreamble; @@ -1367,8 +1380,7 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features, else lyxpreamble += '\n' + atlyxpreamble; - // We try to load babel late, in case it interferes - // with other packages. + // We try to load babel late, in case it interferes with other packages. // Jurabib and Hyperref have to be called after babel, though. if (use_babel && !features.isRequired("jurabib") && !features.isRequired("hyperref") diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index c03b35ca34..a8660d776a 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -520,6 +520,35 @@ int const nb_simplefeatures = sizeof(simplefeatures) / sizeof(char const *); } +string const LaTeXFeatures::getColorOptions() const +{ + ostringstream colors; + + // Handling the color packages separately is needed to be able to load them + // before babel when hyperref is loaded with the colorlinks option + // for more info see Bufferparams.cpp + + // [x]color.sty + if (mustProvide("color") || mustProvide("xcolor")) { + string const package = + (mustProvide("xcolor") ? "xcolor" : "color"); + if (params_.graphicsDriver == "default" + || params_.graphicsDriver == "none") + colors << "\\usepackage{" << package << "}\n"; + else + colors << "\\usepackage[" + << params_.graphicsDriver + << "]{" << package << "}\n"; + } + + // pdfcolmk must be loaded after color + if (mustProvide("pdfcolmk")) + colors << "\\usepackage{pdfcolmk}\n"; + + return colors.str(); +} + + string const LaTeXFeatures::getPackages() const { ostringstream packages; @@ -573,23 +602,8 @@ string const LaTeXFeatures::getPackages() const if (mustProvide("accents")) packages << "\\usepackage{accents}\n"; - // [x]color.sty - if (mustProvide("color") || mustProvide("xcolor")) { - string const package = - (mustProvide("xcolor") ? "xcolor" : "color"); - if (params_.graphicsDriver == "default" - || params_.graphicsDriver == "none") - packages << "\\usepackage{" << package << "}\n"; - else - packages << "\\usepackage[" - << params_.graphicsDriver - << "]{" << package << "}\n"; - } - - // pdfcolmk must be loaded after color - if (mustProvide("pdfcolmk")) - packages << "\\usepackage{pdfcolmk}\n"; - + // [x]color and pdfcolmk are handled in getColorOptions() above + // makeidx.sty if (isRequired("makeidx")) { if (!tclass.provides("makeidx")) diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h index bcf1ed43b8..1a484f730c 100644 --- a/src/LaTeXFeatures.h +++ b/src/LaTeXFeatures.h @@ -46,6 +46,8 @@ public: /// LaTeXFeatures(Buffer const &, BufferParams const &, OutputParams const &); + /// The color packages + std::string const getColorOptions() const; /// The packages needed by the document std::string const getPackages() const; /// The macros definitions needed by the document