]> git.lyx.org Git - features.git/commitdiff
BufferParams.cpp, LaTeXFeatures.cpp: fix http://bugzilla.lyx.org/show_bug.cgi?id...
authorUwe Stöhr <uwestoehr@web.de>
Mon, 29 Sep 2008 19:18:00 +0000 (19:18 +0000)
committerUwe Stöhr <uwestoehr@web.de>
Mon, 29 Sep 2008 19:18:00 +0000 (19:18 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@26627 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferParams.cpp
src/LaTeXFeatures.cpp
src/LaTeXFeatures.h

index 3870c1f55260abfa79b51cc91628f36fdcb3a4e7..1f7d0db19686464135593a3d64b471b0eeb35ce6 100644 (file)
@@ -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")
index c03b35ca3448974395422b167d5987cc3e966373..a8660d776a707ef6d4d9d5e7607befe91d810c79 100644 (file)
@@ -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"))
index bcf1ed43b82b618701684c670579ed40e48f4b69..1a484f730c470921b08b27ba5c96123e8de7dcf9 100644 (file)
@@ -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