]> git.lyx.org Git - lyx.git/blobdiff - src/BufferParams.cpp
Fix scons and a file inclusion problem in ControlCommand.h
[lyx.git] / src / BufferParams.cpp
index 50828faad7e469d45810773d9f9eb086e649f779..40aba23a00d9c39545914461fc9a300ff78ff471 100644 (file)
@@ -54,6 +54,7 @@
 
 using std::count;
 using std::endl;
+using std::find;
 using std::string;
 using std::istringstream;
 using std::ostream;
@@ -899,7 +900,12 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
                                language_options << ',';
                        language_options << language->babel();
                }
-               if (lyxrc.language_global_options && !language_options.str().empty())
+               // when Vietnamese is used, babel must directly be loaded with the
+               // language options, not in the class options
+               int viet = language_options.str().find("vietnam");
+               // viet = string::npos when not found
+               if (lyxrc.language_global_options && !language_options.str().empty()
+                       && viet == string::npos)
                        clsoptions << language_options.str() << ',';
        }
 
@@ -1120,6 +1126,34 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
        // The optional packages;
        docstring lyxpreamble(from_ascii(features.getPackages()));
 
+       // We try to load babel late, in case it interferes
+       // with other packages. But some packages also need babel to be loaded
+       // before, e.g. jurabib has to be called after babel.
+       // So load babel after the optional packages but before the user-defined
+       // preamble. This allows the users to redefine babel commands, e.g. to
+       // translate the word "Index" to the German "Stichwortverzeichnis".
+       // For more infos why this place was chosen, see
+       // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg128425.html
+       // if you encounter problem, you can shift babel to its old place behind
+       // the user-defined preamble
+       if (use_babel && !features.isRequired("jurabib")) {
+               // FIXME UNICODE
+               lyxpreamble += from_utf8(babelCall(language_options.str())) + '\n';
+               lyxpreamble += from_utf8(features.getBabelOptions());
+       }
+
+       // PDF support.
+       // * Hyperref manual: "Make sure it comes last of your loaded
+       //   packages, to give it a fighting chance of not being over-written,
+       //   since its job is to redefine many LATEX commands."
+       // * Email from Heiko Oberdiek: "It is usually better to load babel
+       //   before hyperref. Then hyperref has a chance to detect babel.
+       // * Has to be loaded before the "LyX specific LaTeX commands" to
+       //   avoid errors with algorithm floats.
+       odocstringstream oss;
+       pdfoptions().writeLaTeX(oss);
+       lyxpreamble += oss.str();
+
        // this might be useful...
        lyxpreamble += "\n\\makeatletter\n";
 
@@ -1183,24 +1217,6 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
        if (!bullets_def.empty())
                lyxpreamble += bullets_def + "}\n\n";
 
-       // PDF support. Hypreref manual: "Make sure it comes last of your loaded
-       // packages, to give it a fighting chance of not being over-written,
-       // since its job is to redefine many LATEX commands."
-       // Has to be put into lyxpreamble (preserving line-counting for error
-       // parsing).
-       odocstringstream oss;
-       pdfoptions().writeLaTeX(oss);
-       lyxpreamble += oss.str();
-
-       // We try to load babel late, in case it interferes
-       // with other packages.
-       // Jurabib has to be called after babel, though.
-       if (use_babel && !features.isRequired("jurabib")) {
-               // FIXME UNICODE
-               lyxpreamble += from_utf8(babelCall(language_options.str())) + '\n';
-               lyxpreamble += from_utf8(features.getBabelOptions());
-       }
-
        lyxpreamble += "\\makeatother\n\n";
 
        int const nlines =
@@ -1538,7 +1554,11 @@ string const BufferParams::babelCall(string const & lang_opts) const
        // other languages are used (lang_opts is then empty)
        if (lang_opts.empty())
                return string();
-       if (!lyxrc.language_global_options)
+       // when Vietnamese is used, babel must directly be loaded with the
+       // language options
+       int viet = lang_opts.find("vietnam");
+       // viet = string::npos when not found
+       if (!lyxrc.language_global_options || viet != string::npos)
                return "\\usepackage[" + lang_opts + "]{babel}";
        return lang_pack;
 }