Re: Number of Japanese tests fails now
"Jürgen Spitzmüller" <[email protected]>
| Newsgroups | gmane.editors.lyx.devel |
|---|---|
| Message-ID | <[email protected]> |
Am Donnerstag, dem 26.02.2026 um 19:03 +0900 schrieb Koji Yokota: > > For cases which use a different approach than polyglossia or babel > > (such as Japanese if I understand correctly), there would probably > > need > > to be a special case. > > > That’ll be nice. At this moment, the problem is confined to > polyglossia with XeTeX or LuaTeX. > > Similar treatments should go with other languages that Latin Modern > font (in most of cases) does not cover. Qt classifies fonts by > writing system here though I’m not sure it’s > complete: https://doc.qt.io/qt-6/qfontdatabase.html#WritingSystem-enu > m > > > But what if I use German passages in a Japanese document? This even > > happens if I load the Japanese User Guide in a German l7n (due to > > info > > insets being localized to German then). > > > In that case, we can simply use polyglossia. It actually works fine, > just lacking an appropriate default font settings in use with XeTeX > and LuaTeX. Attached an attempt to address this (file format and prefs format change not yet included). It introduces a new language param PreferLangPack where you can specific a preferable language package that is used if this language is the main and only language of the document. I set it for Japanese to PreferLangPack none which should do what you suggested above. There is also a new language package option "Polyglossia if Possible" which would use polyglossia also in this case (as opposed to "Auto"). Could you test that? -- Jürgen -- lyx-devel mailing list [email protected] https://lists.lyx.org/mailman/listinfo/lyx-devel
plang.diff
(text/x-patch, 10.1 KB)
diff --git a/lib/languages b/lib/languages
index 00eba40919..2fb7c20f06 100644
--- a/lib/languages
+++ b/lib/languages
@@ -13,6 +13,7 @@
# BabelOptFormat <format of option specification>
# PolyglossiaName <polyglossianame>
# PolyglossiaOpts "<language-specific options>"
+# PreferLangPack <string>
# XindyName <xindyname>
# ActiveChars <activated characters>
# QuoteStyle <british|danish|english|french|frenchin|
@@ -159,6 +160,9 @@
# requirement specified in "AltLangIfNot <requirement>" is not met.
# AltLanguage inherits the settings of the corresponding Language if the
# latter is defined first.
+# * PreferLangPack might be used to define a language package that is used
+# if this language is used alone and general language package setting is
+# "auto".
#
##########################################################################
@@ -1780,6 +1784,7 @@ Language japanese
BabelName japanese
BabelOptFormat \languageattribute{$lang$}{$opts$}
PolyglossiaName japanese
+ PreferLangPack none
Encoding jis-platex
WordWrap false
ImOffInMath true
diff --git a/src/Font.cpp b/src/Font.cpp
index bb5543d58c..1001bde4a1 100644
--- a/src/Font.cpp
+++ b/src/Font.cpp
@@ -822,8 +822,8 @@ void Font::validate(LaTeXFeatures & features) const
// FIXME: Do something for background and soul package?
- if (((features.usePolyglossia() && lang_->polyglossia() != doc_language->polyglossia())
- || (features.useBabel() && lang_->babel() != doc_language->babel())
+ if (((features.usePolyglossia(true) && lang_->polyglossia() != doc_language->polyglossia())
+ || (features.useBabel(true) && lang_->babel() != doc_language->babel())
|| (doc_language->encoding()->package() == Encoding::CJK && lang_ != doc_language))
&& lang_ != ignore_language
&& lang_ != latex_language)
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index 4bc7f7af4e..e6af5b2771 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -577,14 +577,24 @@ LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p,
{}
-LaTeXFeatures::LangPackage LaTeXFeatures::langPackage() const
-{
- string const local_lp = bufferParams().lang_package;
+LaTeXFeatures::LangPackage LaTeXFeatures::langPackage(bool const ignore_prefs) const
+{
+ // monolingual documents with PreferLangPack use that if the local
+ // or global setting is "auto"
+ string const local_lp = (!ignore_prefs
+ && (bufferParams().lang_package == "auto"
+ || (bufferParams().lang_package == "default"
+ && lyxrc.language_package_selection == LyXRC::LP_AUTO))
+ && !hasLanguages()
+ && !params_.language->preferLangPack().empty())
+ ? params_.language->preferLangPack()
+ : bufferParams().lang_package;
// Locally, custom is just stored as a string
// in bufferParams().lang_package.
if (local_lp != "auto"
&& local_lp != "babel"
+ && local_lp != "polyglossia"
&& local_lp != "default"
&& local_lp != "none")
return LANG_PACK_CUSTOM;
@@ -592,7 +602,7 @@ LaTeXFeatures::LangPackage LaTeXFeatures::langPackage() const
if (local_lp == "none")
return LANG_PACK_NONE;
- /* If "auto" is selected, we load polyglossia with non-TeX fonts,
+ /* If "auto" or "polyglossia" is selected, we load polyglossia with non-TeX fonts,
* else we select babel.
* If babel is selected (either directly or via the "auto"
* mechanism), we really do only require it if we have
@@ -607,7 +617,7 @@ LaTeXFeatures::LangPackage LaTeXFeatures::langPackage() const
!bufferParams().language->babel().empty()
|| !this->getBabelLanguages().empty();
- if (local_lp == "auto") {
+ if (local_lp == "auto" || local_lp == "polyglossia") {
// polyglossia requirement has priority over babel
if (polyglossia_required)
return LANG_PACK_POLYGLOSSIA;
@@ -623,6 +633,7 @@ LaTeXFeatures::LangPackage LaTeXFeatures::langPackage() const
if (local_lp == "default") {
switch (lyxrc.language_package_selection) {
case LyXRC::LP_AUTO:
+ case LyXRC::LP_POLYGLOSSIA:
// polyglossia requirement has priority over babel
if (polyglossia_required)
return LANG_PACK_POLYGLOSSIA;
diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h
index 2e5b61db79..f794f76596 100644
--- a/src/LaTeXFeatures.h
+++ b/src/LaTeXFeatures.h
@@ -185,11 +185,11 @@ public:
/** Which language package do we require? \p englishbabel determines
* if we require babel even if English is the only language.
*/
- LangPackage langPackage() const;
+ LangPackage langPackage(bool const ignore_prefs = false) const;
/// Convenience function to test if we use babel
- bool useBabel() const { return langPackage() == LANG_PACK_BABEL; }
+ bool useBabel(bool const ignore_prefs = false) const { return langPackage(ignore_prefs) == LANG_PACK_BABEL; }
/// Convenience function to test if we use polyglossia
- bool usePolyglossia() const { return langPackage() == LANG_PACK_POLYGLOSSIA; }
+ bool usePolyglossia(bool const ignore_prefs = false) const { return langPackage(ignore_prefs) == LANG_PACK_POLYGLOSSIA; }
/// are we in a float?
bool inFloat() const { return in_float_; }
/// are we in a float?
diff --git a/src/Language.cpp b/src/Language.cpp
index 718031218b..68f2adb6bd 100644
--- a/src/Language.cpp
+++ b/src/Language.cpp
@@ -157,6 +157,7 @@ bool Language::readLanguage(Lexer & lex)
LA_LANG_VARIETY,
LA_POLYGLOSSIANAME,
LA_POLYGLOSSIAOPTS,
+ LA_PREFERLANGPACK,
LA_XINDYNAME,
LA_POSTBABELPREAMBLE,
LA_PREBABELPREAMBLE,
@@ -195,6 +196,7 @@ bool Language::readLanguage(Lexer & lex)
{ "polyglossiaopts", LA_POLYGLOSSIAOPTS },
{ "postbabelpreamble", LA_POSTBABELPREAMBLE },
{ "prebabelpreamble", LA_PREBABELPREAMBLE },
+ { "preferlangpack", LA_PREFERLANGPACK },
{ "provides", LA_PROVIDES },
{ "quotestyle", LA_QUOTESTYLE },
{ "requires", LA_REQUIRES },
@@ -246,6 +248,9 @@ bool Language::readLanguage(Lexer & lex)
case LA_POLYGLOSSIAOPTS:
lex >> polyglossia_opts_;
break;
+ case LA_PREFERLANGPACK:
+ lex >> prefer_lang_pack_;
+ break;
case LA_XINDYNAME:
lex >> xindy_;
break;
diff --git a/src/Language.h b/src/Language.h
index 80f56198db..203d326d2c 100644
--- a/src/Language.h
+++ b/src/Language.h
@@ -59,6 +59,8 @@ public:
/// polyglossia language options
std::string const polyglossiaOpts() const { return polyglossia_opts_; }
/// polyglossia language options
+ std::string const preferLangPack() const { return prefer_lang_pack_; }
+ /// polyglossia language options
std::string const xindy() const { return xindy_; }
/// Is this language only supported by polyglossia?
bool isPolyglossiaExclusive() const;
@@ -149,6 +151,8 @@ private:
///
trivstring polyglossia_opts_;
///
+ trivstring prefer_lang_pack_;
+ ///
trivstring xindy_;
///
trivstring quote_style_;
diff --git a/src/LyXRC.cpp b/src/LyXRC.cpp
index 3adc55a119..34db0775a1 100644
--- a/src/LyXRC.cpp
+++ b/src/LyXRC.cpp
@@ -838,10 +838,13 @@ LyXRC::ReturnValues LyXRC::read(Lexer & lexrc, bool check_format)
case 1:
language_package_selection = LP_BABEL;
break;
- case 2:
+ case 3:
+ language_package_selection = LP_POLYGLOSSIA;
+ break;
+ case 4:
language_package_selection = LP_CUSTOM;
break;
- case 3:
+ case 5:
language_package_selection = LP_NONE;
break;
}
@@ -2594,12 +2597,15 @@ void LyXRC::write(ostream & os, bool ignore_system_lyxrc, string const & name) c
case LP_BABEL:
os << "1\n";
break;
- case LP_CUSTOM:
+ case LP_POLYGLOSSIA:
os << "2\n";
break;
- case LP_NONE:
+ case LP_CUSTOM:
os << "3\n";
break;
+ case LP_NONE:
+ os << "4\n";
+ break;
}
}
if (tag != RC_LAST)
diff --git a/src/LyXRC.h b/src/LyXRC.h
index 01b5e99b52..445c8e2f74 100644
--- a/src/LyXRC.h
+++ b/src/LyXRC.h
@@ -409,6 +409,7 @@ public:
enum LangPackageSelection {
LP_AUTO = 0,
LP_BABEL,
+ LP_POLYGLOSSIA,
LP_CUSTOM,
LP_NONE
};
diff --git a/src/frontends/qt/GuiDocument.cpp b/src/frontends/qt/GuiDocument.cpp
index c4dcc782e2..ea19171bf3 100644
--- a/src/frontends/qt/GuiDocument.cpp
+++ b/src/frontends/qt/GuiDocument.cpp
@@ -1107,6 +1107,8 @@ GuiDocument::GuiDocument(GuiView & lv)
qt_("Automatic"), toqstr("auto"));
langModule->languagePackageCO->addItem(
qt_("Always Babel"), toqstr("babel"));
+ langModule->languagePackageCO->addItem(
+ qt_("Polyglossia if Possible"), toqstr("polyglossia"));
langModule->languagePackageCO->addItem(
qt_("Custom"), toqstr("custom"));
langModule->languagePackageCO->addItem(
@@ -4352,7 +4354,7 @@ void GuiDocument::paramsToDialog()
if (extern_babel)
p = langModule->languagePackageCO->findData(toqstr("babel"));
else if (extern_polyglossia)
- p = langModule->languagePackageCO->findData(toqstr("auto"));
+ p = langModule->languagePackageCO->findData(toqstr("polyglossia"));
else
p = langModule->languagePackageCO->findData(toqstr(bp_.lang_package));
diff --git a/src/frontends/qt/GuiPrefs.cpp b/src/frontends/qt/GuiPrefs.cpp
index f41ade621e..3e6627818d 100644
--- a/src/frontends/qt/GuiPrefs.cpp
+++ b/src/frontends/qt/GuiPrefs.cpp
@@ -3338,8 +3338,10 @@ void PrefLanguage::applyRC(LyXRC & rc) const
else if (p == 1)
rc.language_package_selection = LyXRC::LP_BABEL;
else if (p == 2)
- rc.language_package_selection = LyXRC::LP_CUSTOM;
+ rc.language_package_selection = LyXRC::LP_POLYGLOSSIA;
else if (p == 3)
+ rc.language_package_selection = LyXRC::LP_CUSTOM;
+ else if (p == 4)
rc.language_package_selection = LyXRC::LP_NONE;
rc.language_custom_package = fromqstr(languagePackageED->text());
rc.language_global_options = globalCB->isChecked();
diff --git a/src/frontends/qt/ui/PrefLanguageUi.ui b/src/frontends/qt/ui/PrefLanguageUi.ui
index 4bc6e39f60..c601d06adf 100644
--- a/src/frontends/qt/ui/PrefLanguageUi.ui
+++ b/src/frontends/qt/ui/PrefLanguageUi.ui
@@ -82,6 +82,11 @@
<string>Always Babel</string>
</property>
</item>
+ <item>
+ <property name="text">
+ <string>Polyglossia if Possible</string>
+ </property>
+ </item>
<item>
<property name="text">
<string>Custom</string>