]> git.lyx.org Git - features.git/commitdiff
Introduce a new Language option "AsBabelOptions" that specifies whether a language...
authorJürgen Spitzmüller <spitz@lyx.org>
Sun, 14 Nov 2010 10:35:35 +0000 (10:35 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Sun, 14 Nov 2010 10:35:35 +0000 (10:35 +0000)
This allows us to remove some ugly hardcoding of languages in the source.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36292 a592a061-630c-0410-9148-cb99ea01b6c8

lib/languages
src/BufferParams.cpp
src/BufferParams.h
src/LaTeXFeatures.cpp
src/LaTeXFeatures.h
src/Language.cpp
src/Language.h

index 0d3d574a56df6211e5a96091844affc568b627d3..f4c41fdf526021ef95e2bb3e2c71980a5aedf5bf 100644 (file)
@@ -10,6 +10,7 @@
 #      Encoding           <encoding>
 #      InternalEncoding   <true|false>
 #      RTL                <true|false>
+#      AsBabelOptions     <true|false>
 #      LangCode           <language_code>
 #      LangVariety        <language_variety>
 #      PreBabelPreamble
@@ -21,7 +22,7 @@
 # End
 #
 # Omitted elements will be treated as empty
-# (omitted RTL and InternalEncoding as "false")
+# (omitted AsBabelOptions, RTL and InternalEncoding as "false")
 #
 ########################################################################
 
@@ -378,6 +379,7 @@ Language japanese
        BabelName       japanese
        Encoding        jis-plain
        LangCode        ja_JP
+       AsBabelOptions  true
 End
 
 Language japanese-cjk
@@ -413,6 +415,7 @@ Language latvian
        BabelName       latvian
        Encoding        iso8859-4
        LangCode        lv_LV
+       AsBabelOptions  true
 End
 
 Language lithuanian
@@ -420,6 +423,7 @@ Language lithuanian
        BabelName       lithuanian
        Encoding        iso8859-13
        LangCode        lt_LT
+       AsBabelOptions  true
 End
 
 Language lowersorbian
@@ -441,6 +445,7 @@ Language mongolian
        BabelName       mongolian
        Encoding        utf8
        LangCode        mn_MN
+       AsBabelOptions  true
 End
 
 Language norsk
@@ -576,6 +581,7 @@ Language turkmen
        BabelName       turkmen
        Encoding        utf8
        LangCode        tk_TM
+       AsBabelOptions  true
 End
 
 Language ukrainian
@@ -597,6 +603,7 @@ Language vietnamese
        BabelName       vietnam
        Encoding        utf8
        LangCode        vi_VN
+       AsBabelOptions  true
 End
 
 Language welsh
index 2eca1bf2d58be9a02e2c3fe0d883b327331415b7..e3b343a3f727002f59517d4973ab3d234f656bfd 100644 (file)
@@ -1310,27 +1310,8 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
                                language_options << ',';
                        language_options << language->babel();
                }
-               // 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
-               // the same is for all other languages that are not directly supported by
-               // babel, but where LaTeX-packages add babel support.
-               // this is currently the case for Latvian, Lithuanian, Mongolian
-               // and Turkmen
-               size_t latvian = language_options.str().find("latvian");
-               size_t lithu = language_options.str().find("lithuanian");
-               size_t mongo = language_options.str().find("mongolian");
-               size_t turkmen = language_options.str().find("turkmen");
-               // if Japanese is used, babel must directly be loaded
-               // with language options, not in the class options, see
-               // http://www.lyx.org/trac/ticket/4597#c4
-               size_t japan = language_options.str().find("japanese");
-               if (lyxrc.language_global_options && !language_options.str().empty()
-                       && viet == string::npos && japan == string::npos
-                       && latvian == string::npos && lithu == string::npos
-                       && mongo == string::npos && turkmen == string::npos)
+               if (lyxrc.language_global_options
+                   && !features.needBabelLangOptions())
                        clsoptions << language_options.str() << ',';
        }
 
@@ -1744,7 +1725,8 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
                        || features.isRequired("japanese") ) ) {
                                // FIXME UNICODE
                                lyxpreamble += from_utf8(features.getBabelPresettings());
-                               lyxpreamble += from_utf8(babelCall(language_options.str())) + '\n';
+                               lyxpreamble += from_utf8(babelCall(language_options.str(),
+                                                                  features.needBabelLangOptions())) + '\n';
                                lyxpreamble += from_utf8(features.getBabelPostsettings());
        }
 
@@ -1888,7 +1870,8 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
            && !features.isRequired("japanese")) {
                // FIXME UNICODE
                lyxpreamble += from_utf8(features.getBabelPresettings());
-               lyxpreamble += from_utf8(babelCall(language_options.str())) + '\n';
+               lyxpreamble += from_utf8(babelCall(language_options.str(),
+                                                  features.needBabelLangOptions())) + '\n';
                lyxpreamble += from_utf8(features.getBabelPostsettings());
        }
 
@@ -2407,37 +2390,20 @@ string const BufferParams::font_encoding() const
 }
 
 
-string BufferParams::babelCall(string const & lang_opts) const
+string BufferParams::babelCall(string const & lang_opts, bool const langoptions) const
 {
        string lang_pack = lyxrc.language_package;
        if (lang_pack != "\\usepackage{babel}")
                return lang_pack;
-       // suppress the babel call when there is no babel language defined
+       // suppress the babel call if there is no BabelName defined
        // 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();
-       // If 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
-       // the same is for all other languages that are not directly supported by
-       // babel, but where LaTeX-packages add babel support.
-       // this is currently the case for Latvian, Lithuanian, Mongolian
-       // and Turkmen
-       size_t latvian = lang_opts.find("latvian");
-       size_t lithu = lang_opts.find("lithuanian");
-       size_t mongo = lang_opts.find("mongolian");
-       size_t turkmen = lang_opts.find("turkmen");
-       // If Japanese is used, babel must directly be loaded with the
-       // language options, see
-       // http://www.lyx.org/trac/ticket/4597#c4
-       size_t japan = lang_opts.find("japanese");
-       if (!lyxrc.language_global_options || viet != string::npos
-               || japan != string::npos || latvian != string::npos
-               || lithu != string::npos || mongo != string::npos
-               || turkmen != string::npos)
+       // either a specific language (AsBabelOptions setting in
+       // lib/languages) or the prefs require the languages to
+       // be submitted to babel itself (not the class).
+       if (langoptions)
                return "\\usepackage[" + lang_opts + "]{babel}";
        return lang_pack;
 }
index 7a59bae753874ff5d1a7d40d2705b9ad738d4c7b..ffeb33c6718de45af13a3494c3bdb82e7cbfdf69 100644 (file)
@@ -361,7 +361,7 @@ public:
        ///
        std::string paperSizeName(PapersizePurpose purpose) const;
        /// set up if and how babel is called
-       std::string babelCall(std::string const & lang_opts) const;
+       std::string babelCall(std::string const & lang_opts, bool const langoptions) const;
        /// return supported drivers for specific packages
        docstring getGraphicsDriver(std::string const & package) const;
        /// handle inputenc etc.
index 8a40fd4b97cc07fa97aa30e075fa99b4c1ae9c81..8e431011520d1e9a8ef38b2c17de8716a3e04081 100644 (file)
@@ -952,7 +952,7 @@ string const LaTeXFeatures::getBabelPresettings() const
        ostringstream tmp;
 
        LanguageList::const_iterator it  = UsedLanguages_.begin();
-       LanguageList::const_iterator end =  UsedLanguages_.end();
+       LanguageList::const_iterator end = UsedLanguages_.end();
        for (; it != end; ++it)
                if (!(*it)->babel_presettings().empty())
                        tmp << (*it)->babel_presettings() << '\n';
@@ -968,7 +968,7 @@ string const LaTeXFeatures::getBabelPostsettings() const
        ostringstream tmp;
 
        LanguageList::const_iterator it  = UsedLanguages_.begin();
-       LanguageList::const_iterator end =  UsedLanguages_.end();
+       LanguageList::const_iterator end = UsedLanguages_.end();
        for (; it != end; ++it)
                if (!(*it)->babel_postsettings().empty())
                        tmp << (*it)->babel_postsettings() << '\n';
@@ -979,6 +979,21 @@ string const LaTeXFeatures::getBabelPostsettings() const
 }
 
 
+bool LaTeXFeatures::needBabelLangOptions() const
+{
+       if (!lyxrc.language_global_options || params_.language->asBabelOptions())
+               return true;
+
+       LanguageList::const_iterator it  = UsedLanguages_.begin();
+       LanguageList::const_iterator end = UsedLanguages_.end();
+       for (; it != end; ++it)
+               if ((*it)->asBabelOptions())
+                       return true;
+
+       return false;
+}
+
+
 docstring const LaTeXFeatures::getTClassPreamble() const
 {
        // the text class specific preamble
index 6493f7b2fbd54c04c477dc2a94959a9b201ad90a..9bb50f57cfa6dc00485be95e19f369657f7c343c 100644 (file)
@@ -56,6 +56,8 @@ public:
        std::string const getBabelPresettings() const;
        /// Extra preamble code after babel is called
        std::string const getBabelPostsettings() const;
+       /// Do we need to pass the languages to babel directly? 
+       bool needBabelLangOptions() const;
        /// The definitions needed by the document's textclass
        docstring const getTClassPreamble() const;
        /// The language dependent definitions needed by the document's textclass
index 219021557f352006d14b32d1e24b7b10b8daa9c5..e13e3dc36091abab5807ff17a70bc59c4774079d 100644 (file)
@@ -41,7 +41,8 @@ Language const * reset_language = 0;
 bool Language::readLanguage(Lexer & lex)
 {
        enum LanguageTags {
-               LA_BABELNAME = 1,
+               LA_AS_BABELOPTS = 1,
+               LA_BABELNAME,
                LA_ENCODING,
                LA_END,
                LA_GUINAME,
@@ -55,6 +56,7 @@ bool Language::readLanguage(Lexer & lex)
 
        // Keep these sorted alphabetically!
        LexerKeyword languageTags[] = {
+               { "asbabeloptions",       LA_AS_BABELOPTS },
                { "babelname",            LA_BABELNAME },
                { "encoding",             LA_ENCODING },
                { "end",                  LA_END },
@@ -90,6 +92,9 @@ bool Language::readLanguage(Lexer & lex)
                case LA_END: // end of structure
                        finished = true;
                        break;
+               case LA_AS_BABELOPTS:
+                       lex >> as_babel_options_;
+                       break;
                case LA_BABELNAME:
                        lex >> babel_;
                        break;
@@ -128,6 +133,7 @@ bool Language::readLanguage(Lexer & lex)
 
 bool Language::read(Lexer & lex)
 {
+       as_babel_options_ = 0;
        encoding_ = 0;
        internal_enc_ = 0;
        rightToLeft_ = 0;
index b5aa3d98f6c3f938118c1ce44a0cd15ce6156207..46e65a591ac829ca1d178966020cee52b6e029df 100644 (file)
@@ -55,8 +55,10 @@ public:
        std::string const & babel_postsettings() const { return babel_postsettings_; }
        ///
        std::string const & babel_presettings() const { return babel_presettings_; }
-       ///
+       /// This language internally sets a font encoding
        bool internalFontEncoding() const { return internal_enc_; }
+       /// This language needs to be passed to babel itself (not the class)
+       bool asBabelOptions() const { return as_babel_options_; }
        ///
        bool read(Lexer & lex);
        ///
@@ -86,6 +88,8 @@ private:
        std::string babel_presettings_;
        ///
        bool internal_enc_;
+       ///
+       bool as_babel_options_;
 };