]> git.lyx.org Git - lyx.git/blobdiff - src/BufferParams.cpp
Further to r26743, add CustomPars and ForcePlain layout tags to InsetLayout,
[lyx.git] / src / BufferParams.cpp
index 7c56e0058c23f500c6a9c36e40b03e26fd621246..dfeed2c9faa1de81463e9c98213f1cf7b38386e7 100644 (file)
@@ -84,8 +84,11 @@ static char const * const string_footnotekinds[] = {
 
 
 static char const * const tex_graphics[] = {
-       "default", "dvips", "dvitops", "emtex",
-       "ln", "oztex", "textures", "none", ""
+       "default", "dvialw", "dvilaser", "dvipdf", "dvipdfm", "dvipdfmx",
+       "dvips", "dvipsone", "dvitops", "dviwin", "dviwindo", "dvi2ps", "emtex",
+       "ln", "oztex", "pctexhp", "pctexps", "pctexwin", "pctex32", "pdftex",
+       "psprint", "pubps", "tcidvi", "textures", "truetex", "vtex", "xdvi",
+       "xetex", "none", ""
 };
 
 
@@ -761,9 +764,9 @@ void BufferParams::writeFile(ostream & os) const
        BranchList::const_iterator it = branchlist().begin();
        BranchList::const_iterator end = branchlist().end();
        for (; it != end; ++it) {
-               os << "\\branch " << to_utf8(it->getBranch())
-                  << "\n\\selected " << it->getSelected()
-                  << "\n\\color " << lyx::X11hexname(it->getColor())
+               os << "\\branch " << to_utf8(it->branch())
+                  << "\n\\selected " << it->isSelected()
+                  << "\n\\color " << lyx::X11hexname(it->color())
                   << "\n\\end_branch"
                   << "\n";
        }
@@ -917,8 +920,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");
@@ -1016,18 +1025,24 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
                                language_options << ',';
                        language_options << language->babel();
                }
-               // if Vietnamese is used, babel must directly be loaded with the
-               // language options, not in the class options, see
+               // if Vietnamese is used, babel must directly be loaded
+               // with language options, not in the class options, see
                // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129417.html
                size_t viet = language_options.str().find("vietnam");
                // viet = string::npos when not found
-               // if Japanese is used, babel must directly be loaded with the
-               // language options, not in the class options, see
+               // if Japanese is used, babel must directly be loaded
+               // with language options, not in the class options, see
                // http://bugzilla.lyx.org/show_bug.cgi?id=4597#c4
                size_t japan = language_options.str().find("japanese");
-               // japan = string::npos when not found
-               if (lyxrc.language_global_options && !language_options.str().empty()
-                       && viet == string::npos && japan == string::npos)
+               // if Latvian or Lithuanian is used, babel must directly be loaded
+               // with language options, not in the class options, see
+               // http://bugzilla.lyx.org/show_bug.cgi?id=5323
+               size_t latvian = language_options.str().find("latvian");
+               size_t lithu = language_options.str().find("lithuanian");
+               if (lyxrc.language_global_options
+                       && !language_options.str().empty()
+                       && viet == string::npos && japan == string::npos
+                       && latvian == string::npos && lithu == string::npos)
                        clsoptions << language_options.str() << ',';
        }
 
@@ -1062,9 +1077,11 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
 
        // set font encoding
        // this one is not per buffer
-       // for arabic_arabi and farsi we also need to load the LAE and LFE encoding
+       // for arabic_arabi and farsi we also need to load the LAE and
+       // LFE encoding
        if (lyxrc.fontenc != "default" && language->lang() != "japanese") {
-               if (language->lang() == "arabic_arabi" || language->lang() == "farsi") {
+               if (language->lang() == "arabic_arabi"
+                   || language->lang() == "farsi") {
                        os << "\\usepackage[" << from_ascii(lyxrc.fontenc)
                           << ",LFE,LAE]{fontenc}\n";
                        texrow.newline();
@@ -1078,13 +1095,20 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
        // handle inputenc etc.
        writeEncodingPreamble(os, features, texrow);
 
-       if (!listings_params.empty()) {
+       if (!listings_params.empty() || features.isRequired("listings")) {
                os << "\\usepackage{listings}\n";
                texrow.newline();
+       }
+       if (!listings_params.empty()) {
                os << "\\lstset{";
-               // do not test validity because listings_params is supposed to be valid
-               string par = InsetListingsParams(listings_params).separatedParams(true);
-               os << from_ascii(par);
+               // do not test validity because listings_params is 
+               // supposed to be valid
+               string par =
+                       InsetListingsParams(listings_params).separatedParams(true);
+               // we can't support all packages, but we should load the color package
+               if (par.find("\\color", 0) != string::npos)
+                       features.require("color");
+               os << from_utf8(par);
                // count the number of newlines
                for (size_t i = 0; i < par.size(); ++i)
                        if (par[i] == '\n')
@@ -1239,23 +1263,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")));
@@ -1274,7 +1305,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;
 
@@ -1357,8 +1388,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")
@@ -1846,8 +1876,14 @@ string BufferParams::babelCall(string const & lang_opts) const
        // language options, see
        // http://bugzilla.lyx.org/show_bug.cgi?id=4597#c4
        size_t japan = lang_opts.find("japanese");
-       // japan = string::npos when not found
-       if (!lyxrc.language_global_options || viet != string::npos || japan != string::npos)
+       // If Latvian or Lithuanian is used, babel must directly be loaded with
+       // the language options, see
+       // http://bugzilla.lyx.org/show_bug.cgi?id=5323
+       size_t latvian = lang_opts.find("latvian");
+       size_t lithu = lang_opts.find("lithuanian");
+       if (!lyxrc.language_global_options || viet != string::npos
+               || japan != string::npos || latvian != string::npos
+               || lithu != string::npos)
                return "\\usepackage[" + lang_opts + "]{babel}";
        return lang_pack;
 }
@@ -1867,8 +1903,8 @@ void BufferParams::writeEncodingPreamble(odocstream & os,
                set<string> encodings =
                        features.getEncodingSet(doc_encoding);
 
-               // If the encodings EUC-JP-plain, JIS-plain, or SJIS-plain are used, the
-               // package inputenc must be omitted. Therefore set the encoding to empty.
+               // If the "japanese" package (i.e. pLaTeX) is used,
+               // inputenc must be omitted.
                // see http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
                if (package == Encoding::japanese)
                     features.require("japanese");
@@ -1916,9 +1952,10 @@ void BufferParams::writeEncodingPreamble(odocstream & os,
                }
        }
 
-       // The encoding "armscii8" is only available when the package "armtex" is loaded.
-       // armscii8 is used for Armenian.
-       if (language->encoding()->latexName() == "armscii8" || inputenc == "armscii8") {
+       // The encoding "armscii8" (for Armenian) is only available when
+       // the package "armtex" is loaded.
+       if (language->encoding()->latexName() == "armscii8"
+           || inputenc == "armscii8") {
                os << "\\usepackage{armtex}\n";
                texrow.newline();
        }