Re: Number of Japanese tests fails now
"Jürgen Spitzmüller" <[email protected]>
| Newsgroups | gmane.editors.lyx.devel |
|---|---|
| Message-ID | <[email protected]> |
Am Freitag, dem 24.04.2026 um 13:20 +0200 schrieb Jürgen Spitzmüller: > Am Freitag, dem 24.04.2026 um 11:16 +0200 schrieb Jürgen Spitzmüller: > > Attached an attempt to address this (file format and prefs format > > change not yet included). > > Please use this one instead after d525f108a1a (which prepares the > prefs with a change that was sensible anyway). Third iteration attached. This one only considers Xe/LuaTeX and it does not load fontspec if not needed (after all, it is fontspec, not polyglossia, setting LatinModern as default). -- Jürgen -- lyx-devel mailing list [email protected] https://lists.lyx.org/mailman/listinfo/lyx-devel
plang3.diff
(text/x-patch, 11.6 KB)
diff --git a/lib/languages b/lib/languages
index 00eba40919..494705637a 100644
--- a/lib/languages
+++ b/lib/languages
@@ -13,6 +13,7 @@
# BabelOptFormat <format of option specification>
# PolyglossiaName <polyglossianame>
# PolyglossiaOpts "<language-specific options>"
+# PreferTULangPack <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.
+# * PreferTULangPack might be used to define a language package that is used
+# if this language is used alone and general language package setting is
+# "auto", in TU encoding (i.e., with Xe- or LuaTeX).
#
##########################################################################
@@ -1780,6 +1784,7 @@ Language japanese
BabelName japanese
BabelOptFormat \languageattribute{$lang$}{$opts$}
PolyglossiaName japanese
+ PreferTULangPack none
Encoding jis-platex
WordWrap false
ImOffInMath true
diff --git a/lib/lyx2lyx/lyx_2_6.py b/lib/lyx2lyx/lyx_2_6.py
index 507086648f..9aacfb75bf 100644
--- a/lib/lyx2lyx/lyx_2_6.py
+++ b/lib/lyx2lyx/lyx_2_6.py
@@ -886,6 +886,13 @@ def revert_shorthands2(document):
i += 1
continue
+
+def revert_lp_polyglossia(document):
+ """Revert language package polyglossia to auto"""
+ i = find_token(document.header, "\\language_package polyglossia", 0)
+ if i != -1:
+ document.header[i] = "\\language_package auto"
+
##
# Conversion hub
#
@@ -897,11 +904,13 @@ convert = [
[646, []],
[647, [convert_textbreaks]],
[648, []],
- [649, []]
+ [649, []],
+ [650, []]
]
revert = [
+ [649, [revert_lp_polyglossia]],
[648, [revert_shorthands2]],
[647, [revert_hyphen_shorthands]],
[646, [revert_textbreaks]],
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index bb862e90b2..8808d6a1f1 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -2351,19 +2351,23 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
os << from_ascii(ams);
if (useNonTeXFonts) {
+ // We need fontspec if a non-default font or quotes are requested
+ bool const default_fonts = fontsRoman() == "default"
+ && fontsSans() == "default"
+ && fontsTypewriter() == "default";
+ bool const fontspec_features =
+ // these need fontspec features
+ features.isRequired("textquotesinglep")
+ || features.isRequired("textquotedblp");
// Babel (as of 2017/11/03) loads fontspec itself
// However, it does so only if a non-default font is requested via \babelfont
// Thus load fontspec if this is not the case and we need fontspec features
bool const babel_needfontspec =
!features.isAvailableAtLeastFrom("babel", 2017, 11, 3)
- || (fontsRoman() == "default"
- && fontsSans() == "default"
- && fontsTypewriter() == "default"
- // these need fontspec features
- && (features.isRequired("textquotesinglep")
- || features.isRequired("textquotedblp")));
+ || (default_fonts && fontspec_features);
if (!features.isProvided("fontspec")
- && (!features.useBabel() || babel_needfontspec))
+ && (!features.useBabel() || babel_needfontspec)
+ && (!features.usePrefTULangPack() || !default_fonts || fontspec_features))
os << "\\usepackage{fontspec}\n";
if (features.mustProvide("unicode-math")
&& features.isAvailable("unicode-math"))
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 69341eaf9c..308951bd7d 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -577,14 +577,31 @@ LaTeXFeatures::LaTeXFeatures(Buffer const & b, BufferParams const & p,
{}
-LaTeXFeatures::LangPackage LaTeXFeatures::langPackage() const
+bool LaTeXFeatures::usePrefTULangPack() const
{
- string const local_lp = bufferParams().lang_package;
+ return (bufferParams().lang_package == "auto"
+ || (bufferParams().lang_package == "default"
+ && lyxrc.language_package_selection == "auto"))
+ && !hasLanguages()
+ && !params_.language->preferTULangPack().empty();
+}
+
+
+LaTeXFeatures::LangPackage LaTeXFeatures::langPackage(bool const ignore_prefs) const
+{
+ // monolingual documents with PreferTULangPack use that if the local
+ // or global setting is "auto"
+ string const local_lp = !ignore_prefs
+ && params_.useNonTeXFonts
+ && usePrefTULangPack()
+ ? params_.language->preferTULangPack()
+ : 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 +609,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 +624,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;
@@ -621,7 +638,8 @@ LaTeXFeatures::LangPackage LaTeXFeatures::langPackage() const
}
if (local_lp == "default") {
- if (lyxrc.language_package_selection == "auto") {
+ if (lyxrc.language_package_selection == "auto"
+ || lyxrc.language_package_selection == "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 acbfaba62c..ccba1cdfae 100644
--- a/src/LaTeXFeatures.h
+++ b/src/LaTeXFeatures.h
@@ -182,14 +182,16 @@ public:
void setBuffer(Buffer const &);
///
BufferParams const & bufferParams() const;
+ ///
+ bool usePrefTULangPack() const;
/** 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..748ddd92b0 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_PREFERTULANGPACK,
LA_XINDYNAME,
LA_POSTBABELPREAMBLE,
LA_PREBABELPREAMBLE,
@@ -195,6 +196,7 @@ bool Language::readLanguage(Lexer & lex)
{ "polyglossiaopts", LA_POLYGLOSSIAOPTS },
{ "postbabelpreamble", LA_POSTBABELPREAMBLE },
{ "prebabelpreamble", LA_PREBABELPREAMBLE },
+ { "prefertulangpack", LA_PREFERTULANGPACK },
{ "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_PREFERTULANGPACK:
+ lex >> prefer_TU_lang_pack_;
+ break;
case LA_XINDYNAME:
lex >> xindy_;
break;
diff --git a/src/Language.h b/src/Language.h
index 80f56198db..2e1ac3a235 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 preferTULangPack() const { return prefer_TU_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_TU_lang_pack_;
+ ///
trivstring xindy_;
///
trivstring quote_style_;
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 f3dbcb827e..1290556215 100644
--- a/src/frontends/qt/GuiPrefs.cpp
+++ b/src/frontends/qt/GuiPrefs.cpp
@@ -3274,6 +3274,8 @@ PrefLanguage::PrefLanguage(GuiPreferences * form)
qt_("Automatic"), toqstr("auto"));
languagePackageCO->addItem(
qt_("Always Babel"), toqstr("babel"));
+ languagePackageCO->addItem(
+ qt_("Polyglossia if Possible"), toqstr("polyglossia"));
languagePackageCO->addItem(
qt_("Custom"), toqstr("custom"));
languagePackageCO->addItem(
diff --git a/src/version.h b/src/version.h
index a97dda20e0..1c0ba33986 100644
--- a/src/version.h
+++ b/src/version.h
@@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 649 // spitz: more shorthands
-#define LYX_FORMAT_TEX2LYX 649
+#define LYX_FORMAT_LYX 650 // spitz: language package polyglossia
+#define LYX_FORMAT_TEX2LYX 650
#if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
#ifndef _MSC_VER