- Add the option to disable babel for documents whose language is equal to

default_language
- Use \foreignlanguage to locally change the language inside a paragraph


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1617 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Dekel Tsur 2001-02-25 10:22:54 +00:00
parent ef88cb6ff0
commit 86dc4696af
11 changed files with 189 additions and 30 deletions

View File

@ -1,3 +1,13 @@
2001-02-23 Dekel Tsur <dekelts@tau.ac.il>
* lyxrc.C: Add language_command_local, language_use_babel and
language_global_options.
* lyxfont.C (latexWriteStartChanges): Use language_command_local.
* buffer.C (makeLaTeXFile): Use language_use_babel and
language_global_options.
2001-02-23 Juergen Vigna <jug@sad.it>
* lyxfunc.C (Dispatch): removed the whole part of the switch statement

View File

@ -1541,6 +1541,7 @@ void Buffer::writeFileAscii(ostream & ofs, int linelen)
ofs << "\n";
}
bool use_babel;
void Buffer::makeLaTeXFile(string const & fname,
string const & original_path,
@ -1669,24 +1670,28 @@ void Buffer::makeLaTeXFile(string const & fname,
options += "landscape,";
// language should be a parameter to \documentclass
bool use_babel = false;
use_babel = false;
string language_options;
if (params.language->babel() == "hebrew"
&& default_language->babel() != "hebrew")
// This seems necessary
features.UsedLanguages.insert(default_language);
if (lyxrc.language_use_babel ||
#ifdef DO_USE_DEFAULT_LANGUAGE
if (params.language->lang() != "default" ||
!features.UsedLanguages.empty()) {
params.language->lang() != "default" ||
#endif
params.language->lang() != lyxrc.default_language ||
!features.UsedLanguages.empty()) {
use_babel = true;
for (LaTeXFeatures::LanguageList::const_iterator cit =
features.UsedLanguages.begin();
cit != features.UsedLanguages.end(); ++cit)
options += (*cit)->babel() + ",";
options += params.language->babel() + ',';
#ifdef DO_USE_DEFAULT_LANGUAGE
language_options += (*cit)->babel() + ',';
language_options += params.language->babel();
if (lyxrc.language_global_options)
options += language_options + ',';
}
#endif
// the user-defined options
if (!params.options.empty()) {
@ -1868,7 +1873,12 @@ void Buffer::makeLaTeXFile(string const & fname,
// We try to load babel late, in case it interferes
// with other packages.
if (use_babel) {
ofs << lyxrc.language_package << endl;
string tmp = lyxrc.language_package;
if (!lyxrc.language_global_options
&& tmp == "\\usepackage{babel}")
tmp = "\\usepackage[" +
language_options + "]{babel}";
ofs << tmp << "\n";
texrow.newline();
}

View File

@ -1,3 +1,8 @@
2001-02-23 Dekel Tsur <dekelts@tau.ac.il>
* FormPreferences.C: Handle lyxrc.language_use_babel and
lyxrc.language_global_options.
2001-02-23 Angus Leeming <a.leeming@ic.ac.uk>
* FormPreferences(GetFrom, GetTo): use size_type rather than int.

View File

@ -1184,7 +1184,7 @@ bool FormPreferences::Converters::Input()
string const FormPreferences::Converters::GetFrom() const
{
Formats::FormatList::size_type const i =
::Formats::FormatList::size_type const i =
fl_get_choice(dialog_->choice_from);
if (i > 0 && i <= local_formats.size())
@ -1199,7 +1199,7 @@ string const FormPreferences::Converters::GetFrom() const
string const FormPreferences::Converters::GetTo() const
{
Formats::FormatList::size_type const i =
::Formats::FormatList::size_type const i =
fl_get_choice(dialog_->choice_from);
if (i > 0 && i <= local_formats.size())
@ -1649,14 +1649,20 @@ void FormPreferences::Language::apply()
button = fl_get_button(dialog_->check_rtl_support);
lyxrc.rtl_support = static_cast<bool>(button);
button = fl_get_button(dialog_->check_mark_foreign);
lyxrc.mark_foreign_language = static_cast<bool>(button);
button = fl_get_button(dialog_->check_auto_begin);
lyxrc.language_auto_begin = static_cast<bool>(button);
button = fl_get_button(dialog_->check_auto_end);
lyxrc.language_auto_end = static_cast<bool>(button);
button = fl_get_button(dialog_->check_mark_foreign);
lyxrc.mark_foreign_language = static_cast<bool>(button);
button = fl_get_button(dialog_->check_use_babel);
lyxrc.language_use_babel = static_cast<bool>(button);
button = fl_get_button(dialog_->check_global_options);
lyxrc.language_global_options = static_cast<bool>(button);
lyxrc.language_package = fl_get_input(dialog_->input_package);
lyxrc.language_command_begin = fl_get_input(dialog_->input_command_begin);
@ -1713,6 +1719,8 @@ void FormPreferences::Language::build()
setPreHandler(dialog_->check_mark_foreign);
setPreHandler(dialog_->check_auto_begin);
setPreHandler(dialog_->check_auto_end);
setPreHandler(dialog_->check_use_babel);
setPreHandler(dialog_->check_global_options);
setPreHandler(dialog_->input_command_begin);
setPreHandler(dialog_->input_command_end);
@ -1737,12 +1745,16 @@ FormPreferences::Language::feedback(FL_OBJECT const * const ob) const
str = lyxrc.getDescription(LyXRC::RC_KBMAP_SECONDARY);
else if (ob == dialog_->check_rtl_support)
str = lyxrc.getDescription(LyXRC::RC_RTL_SUPPORT);
else if (ob == dialog_->check_mark_foreign)
str = lyxrc.getDescription(LyXRC::RC_MARK_FOREIGN_LANGUAGE);
else if (ob == dialog_->check_auto_begin)
str = lyxrc.getDescription(LyXRC::RC_LANGUAGE_AUTO_BEGIN);
else if (ob == dialog_->check_auto_end)
str = lyxrc.getDescription(LyXRC::RC_LANGUAGE_AUTO_END);
else if (ob == dialog_->check_mark_foreign)
str = lyxrc.getDescription(LyXRC::RC_MARK_FOREIGN_LANGUAGE);
else if (ob == dialog_->check_use_babel)
str = lyxrc.getDescription(LyXRC::RC_LANGUAGE_USE_BABEL);
else if (ob == dialog_->check_global_options)
str = lyxrc.getDescription(LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS);
else if (ob == dialog_->input_package)
str = lyxrc.getDescription(LyXRC::RC_LANGUAGE_PACKAGE);
else if (ob == dialog_->input_command_begin)
@ -1833,10 +1845,13 @@ void FormPreferences::Language::update()
}
fl_set_button(dialog_->check_rtl_support, lyxrc.rtl_support);
fl_set_button(dialog_->check_auto_begin, lyxrc.language_auto_begin);
fl_set_button(dialog_->check_auto_end, lyxrc.language_auto_end);
fl_set_button(dialog_->check_mark_foreign,
lyxrc.mark_foreign_language);
fl_set_button(dialog_->check_auto_begin, lyxrc.language_auto_begin);
fl_set_button(dialog_->check_auto_end, lyxrc.language_auto_end);
fl_set_button(dialog_->check_use_babel, lyxrc.language_use_babel);
fl_set_button(dialog_->check_global_options,
lyxrc.language_global_options);
fl_set_input(dialog_->input_package,
lyxrc.language_package.c_str());

View File

@ -406,7 +406,7 @@ FD_form_language * FormPreferences::build_language()
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("RtL support|#R");
fdui->check_rtl_support = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 154, 161, 30, 30, idex(_(dummy)));
fdui->check_rtl_support = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 140, 161, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
@ -414,7 +414,7 @@ FD_form_language * FormPreferences::build_language()
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Mark foreign|#M");
fdui->check_mark_foreign = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 154, 187, 30, 30, idex(_(dummy)));
fdui->check_mark_foreign = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 140, 187, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
@ -422,7 +422,7 @@ FD_form_language * FormPreferences::build_language()
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Auto begin|#b");
fdui->check_auto_begin = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 362, 161, 30, 30, idex(_(dummy)));
fdui->check_auto_begin = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 265, 161, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
@ -430,7 +430,7 @@ FD_form_language * FormPreferences::build_language()
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Auto finish|#f");
fdui->check_auto_end = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 362, 187, 30, 30, idex(_(dummy)));
fdui->check_auto_end = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 265, 187, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
@ -468,6 +468,22 @@ FD_form_language * FormPreferences::build_language()
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fdui->button_kbmap2_browse = obj = fl_add_button(FL_NORMAL_BUTTON, 341, 128, 90, 30, _("Browse"));
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Use babel|#U");
fdui->check_use_babel = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 390, 161, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_lalign(obj, FL_ALIGN_LEFT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
{
char const * const dummy = N_("Global|#G");
fdui->check_global_options = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 390, 187, 30, 30, idex(_(dummy)));
fl_set_button_shortcut(obj, scex(_(dummy)), 1);
}
fl_set_object_lsize(obj, FL_NORMAL_SIZE);
fl_set_object_lalign(obj, FL_ALIGN_LEFT);
fl_set_object_callback(obj, C_FormBaseInputCB, 0);
fl_end_form();
fdui->form->fdui = fdui;

View File

@ -124,6 +124,8 @@ struct FD_form_language {
FL_OBJECT *input_kbmap2;
FL_OBJECT *button_kbmap1_browse;
FL_OBJECT *button_kbmap2_browse;
FL_OBJECT *check_use_babel;
FL_OBJECT *check_global_options;
};
struct FD_form_colors {
~FD_form_colors();

View File

@ -924,7 +924,7 @@ argument: 0
Name: form_language
Width: 450
Height: 360
Number of Objects: 14
Number of Objects: 16
--------------------
class: FL_BOX
@ -1001,7 +1001,7 @@ argument: 0
--------------------
class: FL_CHECKBUTTON
type: PUSH_BUTTON
box: 154 161 30 30
box: 140 161 30 30
boxtype: FL_NO_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_LEFT
@ -1019,7 +1019,7 @@ argument: 0
--------------------
class: FL_CHECKBUTTON
type: PUSH_BUTTON
box: 154 187 30 30
box: 140 187 30 30
boxtype: FL_NO_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_LEFT
@ -1037,7 +1037,7 @@ argument: 0
--------------------
class: FL_CHECKBUTTON
type: PUSH_BUTTON
box: 362 161 30 30
box: 265 161 30 30
boxtype: FL_NO_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_LEFT
@ -1055,7 +1055,7 @@ argument: 0
--------------------
class: FL_CHECKBUTTON
type: PUSH_BUTTON
box: 362 187 30 30
box: 265 187 30 30
boxtype: FL_NO_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_LEFT
@ -1178,6 +1178,42 @@ name: button_kbmap2_browse
callback: C_FormBaseInputCB
argument: 0
--------------------
class: FL_CHECKBUTTON
type: PUSH_BUTTON
box: 390 161 30 30
boxtype: FL_NO_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Use babel|#U
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: check_use_babel
callback: C_FormBaseInputCB
argument: 0
--------------------
class: FL_CHECKBUTTON
type: PUSH_BUTTON
box: 390 187 30 30
boxtype: FL_NO_BOX
colors: FL_COL1 FL_YELLOW
alignment: FL_ALIGN_LEFT
style: FL_NORMAL_STYLE
size: FL_NORMAL_SIZE
lcol: FL_BLACK
label: Global|#G
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: check_global_options
callback: C_FormBaseInputCB
argument: 0
=============== FORM ===============
Name: form_colors
Width: 450

View File

@ -227,16 +227,22 @@ void InsetQuotes::Read(Buffer const *, LyXLex & lex)
}
extern bool use_babel;
int InsetQuotes::Latex(Buffer const * buf, ostream & os,
bool /*fragile*/, bool) const
{
string doclang = buf->GetLanguage()->lang();
string const doclang = buf->GetLanguage()->lang();
int quoteind = quote_index[side][language];
string qstr;
if (lyxrc.fontenc == "T1") {
qstr = latex_quote_t1[times][quoteind];
#ifdef DO_USE_DEFAULT_LANGUAGE
} else if (doclang == "default") {
#else
} else if (!use_babel) {
#endif
qstr = latex_quote_ot1[times][quoteind];
} else if (language == InsetQuotes::FrenchQ
&& times == InsetQuotes::DoubleQ

View File

@ -677,8 +677,8 @@ int LyXFont::latexWriteStartChanges(ostream & os, LyXFont const & base,
count += 3;
}
} else {
string tmp = '{' +
subst(lyxrc.language_command_begin,
string tmp =
subst(lyxrc.language_command_local,
"$$lang", language()->babel());
os << tmp;
count += tmp.length();

View File

@ -79,7 +79,10 @@ keyword_item lyxrcTags[] = {
{ "\\language_auto_end", LyXRC::RC_LANGUAGE_AUTO_END },
{ "\\language_command_begin", LyXRC::RC_LANGUAGE_COMMAND_BEGIN },
{ "\\language_command_end", LyXRC::RC_LANGUAGE_COMMAND_END },
{ "\\language_command_local", LyXRC::RC_LANGUAGE_COMMAND_LOCAL },
{ "\\language_global_options", LyXRC::RC_LANGUAGE_GLOBAL_OPTIONS },
{ "\\language_package", LyXRC::RC_LANGUAGE_PACKAGE },
{ "\\language_use_babel", LyXRC::RC_LANGUAGE_USE_BABEL },
{ "\\lastfiles", LyXRC::RC_LASTFILES },
{ "\\make_backup", LyXRC::RC_MAKE_BACKUP },
{ "\\mark_foreign_language", LyXRC::RC_MARK_FOREIGN_LANGUAGE },
@ -220,11 +223,14 @@ void LyXRC::setDefaults() {
rtl_support = false;
auto_number = true;
mark_foreign_language = true;
language_package = "\\usepackage{babel}";
language_auto_begin = true;
language_auto_end = true;
language_global_options = true;
language_use_babel = true;
language_package = "\\usepackage{babel}";
language_command_begin = "\\selectlanguage{$$lang}";
language_command_end = "\\selectlanguage{$$lang}";
language_command_local = "\\foreignlanguage{$$lang}{";
default_language = "english";
//
new_ask_filename = false;
@ -800,6 +806,14 @@ int LyXRC::read(string const & filename)
if (lexrc.next())
language_auto_end = lexrc.GetBool();
break;
case RC_LANGUAGE_GLOBAL_OPTIONS:
if (lexrc.next())
language_global_options = lexrc.GetBool();
break;
case RC_LANGUAGE_USE_BABEL:
if (lexrc.next())
language_use_babel = lexrc.GetBool();
break;
case RC_LANGUAGE_COMMAND_BEGIN:
if (lexrc.next())
language_command_begin = lexrc.GetString();
@ -808,6 +822,10 @@ int LyXRC::read(string const & filename)
if (lexrc.next())
language_command_end = lexrc.GetString();
break;
case RC_LANGUAGE_COMMAND_LOCAL:
if (lexrc.next())
language_command_local = lexrc.GetString();
break;
case RC_RTL_SUPPORT:
if (lexrc.next())
rtl_support = lexrc.GetBool();
@ -1413,6 +1431,19 @@ void LyXRC::output(ostream & os) const
os << "\\language_package \"" << language_package
<< "\"\n";
}
case RC_LANGUAGE_GLOBAL_OPTIONS:
if (language_global_options
!= system_lyxrc.language_global_options) {
os << "\\language_global_options \""
<< tostr(language_global_options)
<< "\"\n";
}
case RC_LANGUAGE_USE_BABEL:
if (language_use_babel != system_lyxrc.language_use_babel) {
os << "\\language_use_babel \""
<< tostr(language_use_babel)
<< "\"\n";
}
case RC_LANGUAGE_COMMAND_BEGIN:
if (language_command_begin
!= system_lyxrc.language_command_begin) {
@ -1426,6 +1457,13 @@ void LyXRC::output(ostream & os) const
os << "\\language_command_end \"" << language_command_end
<< "\"\n";
}
case RC_LANGUAGE_COMMAND_LOCAL:
if (language_command_local
!= system_lyxrc.language_command_local) {
os << "\\language_command_local \""
<< language_command_local
<< "\"\n";
}
case RC_LANGUAGE_AUTO_BEGIN:
if (language_auto_begin != system_lyxrc.language_auto_begin) {
os << "\\language_auto_begin "
@ -1815,6 +1853,14 @@ string const LyXRC::getDescription(LyXRCTags tag)
case RC_LANGUAGE_PACKAGE:
str = N_("The latex command for loading the language package. E.g. \"\\usepackage{babel}\", \"\\usepackage{omega}\".");
break;
case RC_LANGUAGE_GLOBAL_OPTIONS:
str = N_("De-select if you don't want the language(s) used as an argument to \\documentclass.");
break;
case RC_LANGUAGE_USE_BABEL:
str = N_("De-select if you don't want babel to be used when the language of the document is the default language.");
break;
case RC_LANGUAGE_AUTO_BEGIN:
str = N_("Select if a language switching command is needed at the beginning of the document.");
@ -1831,7 +1877,11 @@ string const LyXRC::getDescription(LyXRCTags tag)
case RC_LANGUAGE_COMMAND_END:
str = N_("The latex command for changing back to the language of the document.");
break;
case RC_LANGUAGE_COMMAND_LOCAL:
str = N_("The latex command for local changing of the language.");
break;
case RC_DATE_INSERT_FORMAT:
//xgettext:no-c-format
str = N_("This accepts the normal strftime formats; see man strftime for full details. E.g.\"%A, %e. %B %Y\".");

View File

@ -105,6 +105,9 @@ enum LyXRCTags {
RC_LANGUAGE_AUTO_END,
RC_LANGUAGE_COMMAND_BEGIN,
RC_LANGUAGE_COMMAND_END,
RC_LANGUAGE_COMMAND_LOCAL,
RC_LANGUAGE_GLOBAL_OPTIONS,
RC_LANGUAGE_USE_BABEL,
RC_DATE_INSERT_FORMAT,
RC_SHOW_BANNER,
RC_WHEEL_JUMP,
@ -302,6 +305,12 @@ enum LyXRCTags {
///
string language_command_end;
///
string language_command_local;
///
bool language_global_options;
///
bool language_use_babel;
///
bool rtl_support;
///
bool auto_number;