Add BabelOpts to languages

This way, some settings that were hardcoded in BabelPreamble are
customizable in document settings
This commit is contained in:
Juergen Spitzmueller 2024-08-24 14:30:37 +02:00
parent 8ff3e467a1
commit 7e09f574ba
4 changed files with 26 additions and 17 deletions

View File

@ -8,6 +8,7 @@
# GuiName "<Gui Name>"
# HasGuiSupport <true|false>
# BabelName <babelname>
# BabelOpts "<language-specific options>"
# BabelOptFormat <format of option specification>
# PolyglossiaName <polyglossianame>
# PolyglossiaOpts "<language-specific options>"
@ -129,6 +130,8 @@
# be de-activated in some contexts (such as - or =).
# * XindyName holds the value to the (te)xindy -L option. We only give it
# if a corresponding language module exists.
# * BabelOpts are comma separated, no matter how they shall be represented
# in the output.
# * BabelOptFormat specifies how the language-specific options shall be
# passed with babel (which differs between languages).
# You can use the placeholders $lang$ and $opts$ (as in
@ -218,10 +221,8 @@ End
Language ancientgreek
GuiName "Greek (ancient)"
BabelName greek
BabelOpts "ancient"
BabelOptFormat modifier
PostBabelPreamble
\languageattribute{greek}{ancient}
EndPostBabelPreamble
PolyglossiaName greek
PolyglossiaOpts "variant=ancient"
XindyName greek
@ -670,6 +671,7 @@ End
Language estonian
GuiName "Estonian"
BabelName estonian
BabelOpts notilde
BabelOptFormat modifier
PolyglossiaName estonian
XindyName estonian
@ -678,9 +680,6 @@ Language estonian
FontEncoding T1|OT1
DateFormats "d MMMM yyyy|d MMM yyyy|dd.MM.yyyy"
LangCode et_EE
PostBabelPreamble
\addto\extrasestonian{\bbl@deactivate{~}}
EndPostBabelPreamble
End
# the preamble definitions are only used due to bugs in the
@ -1450,6 +1449,7 @@ Language spanish
GuiName "Spanish"
HasGuiSupport true
BabelName spanish
BabelOpts "noquoting, nodecimaldot"
BabelOptFormat modifier
PolyglossiaName spanish
XindyName spanish-modern
@ -1458,27 +1458,23 @@ Language spanish
FontEncoding T1|OT1
DateFormats "d 'de' MMMM 'de' yyyy|d MMM yyyy|dd/MM/yyyy"
LangCode es_ES
PostBabelPreamble
\addto\shorthandsspanish{\spanishdeactivate{~<>}}
\deactivatequoting
EndPostBabelPreamble
End
# there are no spanish shorthands in polyglossia
Language spanish-mexico
GuiName "Spanish (Mexico)"
BabelName spanish
# mexico implies nodecimaldot
BabelOpts "mexico, noquoting"
BabelOptFormat modifier
PolyglossiaName spanish
PolyglossiaOpts "variant=mexican"
XindyName spanish-modern
QuoteStyle french
Encoding iso8859-15
FontEncoding T1|OT1
DateFormats "d 'de' MMMM 'de' yyyy|d MMM yyyy|dd/MM/yyyy"
LangCode es_MX
PostBabelPreamble
\addto\shorthandsspanish{\spanishdeactivate{~<>.}}
\deactivatequoting
EndPostBabelPreamble
End
Language swedish

View File

@ -1371,7 +1371,9 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
if (language != ignore_language)
os << "\\language " << language->lang() << '\n';
for (auto const & s : lang_options_babel_) {
if (!s.second.empty())
Language const * l = languages.getLanguage(s.first);
if (l && l->babelOpts() != s.second)
// babel options can be empty
os << "\\language_options_babel " << s.first << " \"" << s.second << "\"\n";
}
for (auto const & s : lang_options_polyglossia_) {
@ -4039,8 +4041,10 @@ string const BufferParams::bibFileEncoding(string const & file) const
string const BufferParams::babelLangOptions(string const & lang) const
{
if (lang_options_babel_.find(lang) == lang_options_babel_.end())
return string();
if (lang_options_babel_.find(lang) == lang_options_babel_.end()) {
Language const * l = languages.getLanguage(lang);
return l ? l->babelOpts() :string();
}
return lang_options_babel_.find(lang)->second;
}

View File

@ -132,6 +132,7 @@ bool Language::readLanguage(Lexer & lex)
enum LanguageTags {
LA_BABELNAME = 1,
LA_BABELOPTFORMAT,
LA_BABELOPTS,
LA_DATEFORMATS,
LA_ENCODING,
LA_END,
@ -159,6 +160,7 @@ bool Language::readLanguage(Lexer & lex)
{ "activechars", LA_ACTIVECHARS },
{ "babelname", LA_BABELNAME },
{ "babeloptformat", LA_BABELOPTFORMAT },
{ "babelopts", LA_BABELOPTS },
{ "dateformats", LA_DATEFORMATS },
{ "encoding", LA_ENCODING },
{ "end", LA_END },
@ -209,6 +211,9 @@ bool Language::readLanguage(Lexer & lex)
case LA_BABELOPTFORMAT:
lex >> babeloptformat_;
break;
case LA_BABELOPTS:
lex >> babel_opts_;
break;
case LA_POLYGLOSSIANAME:
lex >> polyglossia_name_;
break;

View File

@ -43,6 +43,8 @@ public:
std::string const lang() const { return lang_; }
/// Babel language name
std::string const babel() const { return babel_; }
/// babel language options
std::string const babelOpts() const { return babel_opts_; }
/// Babel option format
std::string const babelOptFormat() const { return babeloptformat_; }
/// polyglossia language name
@ -118,6 +120,8 @@ private:
///
trivstring babel_;
///
trivstring babel_opts_;
///
trivstring babeloptformat_;
///
trivstring polyglossia_name_;