]> git.lyx.org Git - features.git/commitdiff
Fix missing language option for CJKutf8.tex
authorGeorg Baum <baum@lyx.org>
Sun, 17 Feb 2013 16:53:04 +0000 (17:53 +0100)
committerGeorg Baum <baum@lyx.org>
Mon, 18 Feb 2013 19:05:33 +0000 (20:05 +0100)
src/tex2lyx/Preamble.cpp
src/tex2lyx/Preamble.h
src/tex2lyx/test/CJK.lyx.lyx
src/tex2lyx/test/CJKutf8.lyx.lyx
src/tex2lyx/tex2lyx.h

index 56be6a180862e6b3a81fdb7598a687d65bced89a..a7ef65f53fd958ba71415486e878fea7e7ac307c 100644 (file)
@@ -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);
index f86c414dfccc9a3cef03a312a8921299aba6763a..ecb0be17189dd8d38cc341a5eebc130a5e0a5ebb 100644 (file)
@@ -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;
index 016df3ed0a776018c9ef0186c079b56707058cbe..8f726a5e78910b5dbe885e4f8b04c4410a30c6ab 100644 (file)
@@ -13,6 +13,7 @@
 
 
 \end_preamble
+\options english
 \use_default_options false
 \maintain_unincluded_children false
 \language japanese-cjk
index a3cf92885307a7ca328626960f1635f1befd5bbd..6579600eed9e9d3a39dfeaf431b439169f352c3e 100644 (file)
@@ -13,6 +13,7 @@
 
 
 \end_preamble
+\options english
 \use_default_options false
 \maintain_unincluded_children false
 \language chinese-traditional
index 020682cec8695c6eac4f536acaf47bd11d6efc00..1e23b7add574ced8318c52fdb9398cf495a81a69 100644 (file)
@@ -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