+ // for the document language in the lib/languages file and if no
+ // other languages are used (lang_opts is then empty)
+ if (lang_opts.empty())
+ return string();
+ // when Vietnamese is used, babel must directly be loaded with the
+ // language options, see
+ // http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129417.html
+ size_t 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;
+}
+
+
+void BufferParams::writeEncodingPreamble(odocstream & os,
+ LaTeXFeatures & features, TexRow & texrow) const
+{
+ if (inputenc == "auto") {
+ string const doc_encoding =
+ language->encoding()->latexName();
+ Encoding::Package const package =
+ language->encoding()->package();
+
+ // Create a list with all the input encodings used
+ // in the document
+ set<string> encodings =
+ features.getEncodingSet(doc_encoding);
+
+ // When the encodings EUC-JP-plain, JIS-plain, or SJIS-plainare used, the
+ // package inputenc must be omitted. Therefore set the encoding to empty.
+ // see http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
+ if (doc_encoding == "EUC-JP-plain" || doc_encoding == "JIS-plain" ||
+ doc_encoding == "SJIS-plain")
+ encodings.clear();
+
+ if (!encodings.empty() || package == Encoding::inputenc) {
+ os << "\\usepackage[";
+ set<string>::const_iterator it = encodings.begin();
+ set<string>::const_iterator const end = encodings.end();
+ if (it != end) {
+ os << from_ascii(*it);
+ ++it;
+ }
+ for (; it != end; ++it)
+ os << ',' << from_ascii(*it);
+ if (package == Encoding::inputenc) {
+ if (!encodings.empty())
+ os << ',';
+ os << from_ascii(doc_encoding);
+ }
+ os << "]{inputenc}\n";
+ texrow.newline();
+ }
+ if (package == Encoding::CJK || features.mustProvide("CJK")) {
+ os << "\\usepackage{CJK}\n";
+ texrow.newline();
+ }
+ } else if (inputenc != "default") {
+ switch (encoding().package()) {
+ case Encoding::none:
+ break;
+ case Encoding::inputenc:
+ os << "\\usepackage[" << from_ascii(inputenc)
+ << "]{inputenc}\n";
+ texrow.newline();
+ break;
+ case Encoding::CJK:
+ os << "\\usepackage{CJK}\n";
+ texrow.newline();
+ break;
+ }
+ }
+
+ // The encoding "armscii8" is only available when the package "armtex" is loaded.
+ // armscii8 is used for Armenian.
+ if (language->encoding()->latexName() == "armscii8" || inputenc == "armscii8") {
+ os << "\\usepackage{armtex}\n";
+ texrow.newline();