From: Georg Baum Date: Sun, 17 Feb 2013 16:53:04 +0000 (+0100) Subject: Fix missing language option for CJKutf8.tex X-Git-Tag: 2.1.0beta1~647 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=4061e5bbdb476da7f646ab44a123cf6be15eaa74;p=features.git Fix missing language option for CJKutf8.tex --- diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index 56be6a1808..a7ef65f53f 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -442,8 +442,8 @@ string remove_braces(string const & value) } // anonymous namespace -Preamble::Preamble() : one_language(true), title_layout_found(false), - h_font_cjk_set(false) +Preamble::Preamble() : one_language(true), explicit_babel(false), + title_layout_found(false), h_font_cjk_set(false) { //h_backgroundcolor; //h_boxbgcolor; @@ -819,9 +819,10 @@ void Preamble::handle_package(Parser &p, string const & name, h_preamble << "\\usepackage[" << opts << "]{babel}\n"; } delete_opt(options, known_languages); - } - else + } else { h_preamble << "\\usepackage{babel}\n"; + explicit_babel = true; + } } else if (name == "polyglossia") { @@ -1884,6 +1885,21 @@ void Preamble::parse(Parser & p, string const & forceclass, p.pushPosition(); h_language = guessLanguage(p, default_language); p.popPosition(); + if (explicit_babel && h_language != default_language) { + // We set the document language to a CJK language, + // but babel is explicitly called in the user preamble + // without options. LyX will not add the default + // language to the document options if it is either + // english, or no text is set as default language. + // Therefore we need to add a language option explicitly. + // FIXME: It would be better to remove all babel calls + // from the user preamble, but this is difficult + // without re-introducing bug 7861. + if (h_options.empty()) + h_options = lyx2babel(default_language); + else + h_options += ',' + lyx2babel(default_language); + } } } @@ -1897,6 +1913,15 @@ string babel2lyx(string const & language) } +string lyx2babel(string const & language) +{ + char const * const * where = is_known(language, known_coded_languages); + if (where) + return known_languages[where - known_coded_languages]; + return language; +} + + string Preamble::polyglossia2lyx(string const & language) { char const * const * where = is_known(language, polyglossia_languages); diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h index f86c414dfc..ecb0be1718 100644 --- a/src/tex2lyx/Preamble.h +++ b/src/tex2lyx/Preamble.h @@ -105,6 +105,8 @@ private: bool one_language; /// the main non-CJK language std::string default_language; + /// Was babel called explicitly? + bool explicit_babel; /// was at least one title layout found? bool title_layout_found; diff --git a/src/tex2lyx/test/CJK.lyx.lyx b/src/tex2lyx/test/CJK.lyx.lyx index 016df3ed0a..8f726a5e78 100644 --- a/src/tex2lyx/test/CJK.lyx.lyx +++ b/src/tex2lyx/test/CJK.lyx.lyx @@ -13,6 +13,7 @@ \end_preamble +\options english \use_default_options false \maintain_unincluded_children false \language japanese-cjk diff --git a/src/tex2lyx/test/CJKutf8.lyx.lyx b/src/tex2lyx/test/CJKutf8.lyx.lyx index a3cf928853..6579600eed 100644 --- a/src/tex2lyx/test/CJKutf8.lyx.lyx +++ b/src/tex2lyx/test/CJKutf8.lyx.lyx @@ -13,6 +13,7 @@ \end_preamble +\options english \use_default_options false \maintain_unincluded_children false \language chinese-traditional diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h index 020682cec8..1e23b7add5 100644 --- a/src/tex2lyx/tex2lyx.h +++ b/src/tex2lyx/tex2lyx.h @@ -45,6 +45,8 @@ public: /// Translate babel language name to LyX language name extern std::string babel2lyx(std::string const & language); +/// Translate LyX language name to babel language name +extern std::string lyx2babel(std::string const & language); /// Translate polyglossia language name to LyX language name extern std::string polyglossia2lyx(std::string const & language); /// Translate basic color name or RGB color in LaTeX syntax to LyX color code