From cc5dd37a2a051778429836331206b5c7800dee16 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Sun, 14 Nov 2010 10:35:35 +0000 Subject: [PATCH] Introduce a new Language option "AsBabelOptions" that specifies whether a language requires to be passed to babel itself (instead of globally to the class). 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 | 9 ++++++- src/BufferParams.cpp | 58 +++++++++---------------------------------- src/BufferParams.h | 2 +- src/LaTeXFeatures.cpp | 19 ++++++++++++-- src/LaTeXFeatures.h | 2 ++ src/Language.cpp | 8 +++++- src/Language.h | 6 ++++- 7 files changed, 52 insertions(+), 52 deletions(-) diff --git a/lib/languages b/lib/languages index 0d3d574a56..f4c41fdf52 100644 --- a/lib/languages +++ b/lib/languages @@ -10,6 +10,7 @@ # Encoding # InternalEncoding # RTL +# AsBabelOptions # LangCode # LangVariety # 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 diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 2eca1bf2d5..e3b343a3f7 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -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; } diff --git a/src/BufferParams.h b/src/BufferParams.h index 7a59bae753..ffeb33c671 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -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. diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp index 8a40fd4b97..8e43101152 100644 --- a/src/LaTeXFeatures.cpp +++ b/src/LaTeXFeatures.cpp @@ -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 diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h index 6493f7b2fb..9bb50f57cf 100644 --- a/src/LaTeXFeatures.h +++ b/src/LaTeXFeatures.h @@ -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 diff --git a/src/Language.cpp b/src/Language.cpp index 219021557f..e13e3dc360 100644 --- a/src/Language.cpp +++ b/src/Language.cpp @@ -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; diff --git a/src/Language.h b/src/Language.h index b5aa3d98f6..46e65a591a 100644 --- a/src/Language.h +++ b/src/Language.h @@ -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_; }; -- 2.39.2