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
This commit is contained in:
Jürgen Spitzmüller 2010-11-14 10:35:35 +00:00
parent 12c7e7dde3
commit cc5dd37a2a
7 changed files with 52 additions and 52 deletions

View 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

View 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;
}

View 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.

View 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

View 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

View 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;

View 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_;
};