> Is the from_ascii -> from_utf8 change necessary?
Currently we use from_utf8 and from_ascii inconsistently in BufferParams.cpp: when calling babel we use from_utf8 for the other packages from_ascii. But LaTeXFeatures::getPackages(), LaTeXFeatures::getMacros(), and LaTeXFeatures::getBabelOptions() have the same definition as far as I can see. So I only wanted to make this consistent. Do you prefer from_ascii for all calls?
(Attached is my patch for current trunk after the latest commit.) regards Uwe
Index: src/BufferParams.cpp =================================================================== --- src/BufferParams.cpp (revision 26594) +++ src/BufferParams.cpp (working copy) @@ -917,8 +917,14 @@ } } - 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,7 +1255,16 @@ texrow.newline(); } - // If we use hyperref, jurabib, japanese, or vietnamese, we have to call babel here. + // 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 + if (use_babel && features.isRequired("hyperref") && pdfoptions().colorlinks) { + os << from_utf8(features.getColorOptions()); + texrow.newline(); + } + + // If we use hyperref, jurabib, japanese, or vietnamese, we have to call babel before them. if (use_babel && (features.isRequired("jurabib") || features.isRequired("hyperref") @@ -1263,9 +1278,15 @@ } // Now insert the LyX specific LaTeX commands... + docstring lyxpreamble; + // The color packages (when not loaded before babel) + // (have to be loaded before the optional packages) + if (!(use_babel && features.isRequired("hyperref") && pdfoptions().colorlinks)) + lyxpreamble += from_utf8(features.getColorOptions()); + // The optional packages; - docstring lyxpreamble(from_ascii(features.getPackages())); + lyxpreamble += from_utf8(features.getPackages()); // Line spacing lyxpreamble += from_utf8(spacing().writePreamble(tclass.provides("SetSpace"))); @@ -1284,12 +1305,12 @@ pdfoptions().writeLaTeX(oss, documentClass().provides("hyperref")); lyxpreamble += oss.str(); } - + // Will be surrounded by \makeatletter and \makeatother when needed docstring atlyxpreamble; // Some macros LyX will need - docstring tmppreamble(from_ascii(features.getMacros())); + docstring tmppreamble(from_utf8(features.getMacros())); if (!tmppreamble.empty()) atlyxpreamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% " @@ -1367,8 +1388,7 @@ 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") Index: src/LaTeXFeatures.cpp =================================================================== --- src/LaTeXFeatures.cpp (revision 26600) +++ src/LaTeXFeatures.cpp (working copy) @@ -520,6 +520,35 @@ } +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 @@ 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")) Index: src/LaTeXFeatures.h =================================================================== --- src/LaTeXFeatures.h (revision 26594) +++ src/LaTeXFeatures.h (working copy) @@ -46,6 +46,8 @@ /// 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