[LyX/master] Add tag to select specific language package for languages
Juergen Spitzmueller <[email protected]> Sat, 02 May 2026 05:41:01 +0000
| Newsgroups | gmane.editors.lyx.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit 2e6b989b69873d124add5b883233497d31415e22 Author: Juergen Spitzmueller <[email protected]> Date: Sat May 2 07:38:48 2026 +0200 Add tag to select specific language package for languages This is only for non-TeX-fonts, used by Japanese. In document setting, provide a new setting "Polyglossia if possible" which overrides this. File format change --- development/FORMAT | 5 +++++ lib/doc/UserGuide.lyx | 33 +++++++++++++++++++++++++++++++++ lib/doc/de/UserGuide.lyx | 23 ++++++++++++++++++++++- lib/languages | 5 +++++ lib/lyx2lyx/lyx_2_6.py | 11 ++++++++++- src/BufferParams.cpp | 24 ++++++++++++++++-------- src/Font.cpp | 4 ++-- src/LaTeXFeatures.cpp | 28 +++++++++++++++++++++++----- src/LaTeXFeatures.h | 8 +++++--- src/Language.cpp | 5 +++++ src/Language.h | 4 ++++ src/frontends/qt/GuiDocument.cpp | 4 +++- src/frontends/qt/GuiPrefs.cpp | 2 ++ src/version.h | 4 ++-- 14 files changed, 137 insertions(+), 23 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index 36c75337c8..7b77fbe937 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -7,6 +7,11 @@ changes happened in particular if possible. A good example would be ----------------------- +2026-04-24 Jürgen Spitzmüller <[email protected]> + * Format incremented to 650: + New \language_package value "polyglossia" which uses polyglossia whenever + possible (independent of the new language flag PreferLangPack). + 2026-02-18 Jürgen Spitzmüller <[email protected]> * Format incremented to 649: New (language-specific) SpecialChars gendermark, abbrvdot, diff --git a/lib/doc/UserGuide.lyx b/lib/doc/UserGuide.lyx index 6ed4fff6e1..6a7c81bd8a 100644 --- a/lib/doc/UserGuide.lyx +++ b/lib/doc/UserGuide.lyx @@ -185,6 +185,7 @@ logicalmkup \docbook_table_output 0 \docbook_mathml_prefix 1 \docbook_mathml_version 0 +\author -712698321 "Jürgen Spitzmüller" \end_header \begin_body @@ -51267,8 +51268,15 @@ polyglossia this package will be used instead of \series bold babel +\change_inserted -712698321 1777472602 + \series default +, + except for cases where a different package (or no package) is predefined as preferred for a specific language. +\change_deleted -712698321 1777472570 . +\change_unchanged + \end_layout \begin_layout Description @@ -51285,6 +51293,31 @@ babel polyglossia \series default would be more appropriate. +\change_inserted -712698321 1777472607 + +\end_layout + +\begin_layout Description + +\change_inserted -712698321 1777472679 +Polyglossia +\begin_inset space ~ +\end_inset + +if +\begin_inset space ~ +\end_inset + +Possible uses +\series bold +polyglossia +\series default + when using Xe\SpecialChar TeX + or Lua\SpecialChar TeX + and non-\SpecialChar TeX + fonts even for languages with different preferences. +\change_unchanged + \end_layout \begin_layout Description diff --git a/lib/doc/de/UserGuide.lyx b/lib/doc/de/UserGuide.lyx index 9ff98f0425..fa2d86774a 100644 --- a/lib/doc/de/UserGuide.lyx +++ b/lib/doc/de/UserGuide.lyx @@ -50073,7 +50073,9 @@ polyglossia \series bold babel \series default - verwendet. + verwendet, + außer in Fällen, + in denen für eine bestimmte Sprache ein anderes (oder kein) Paket als Präferenz festgelegt wurde. \end_layout \begin_layout Description @@ -50093,6 +50095,25 @@ polyglossia besser geeignet wäre. \end_layout +\begin_layout Description +Polyglossia +\begin_inset space ~ +\end_inset + +wenn +\begin_inset space ~ +\end_inset + +möglich verwendet +\series bold +polyglossia +\series default + mit Xe\SpecialChar TeX + oder Lua\SpecialChar TeX + und Nicht-TeX-Schriften auch dann, + wenn für eine bestimmte Sprache andere Präferenzen festgelegt wurden. +\end_layout + \begin_layout Description Benutzerdefiniert erlaubt es, einen Befehl für ein Sprachpaket ihrer Wahl festzulegen. 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..f7a0c50c43 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"; + // These need fontspec features + bool const 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")) @@ -3042,7 +3046,11 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, os << "\\setotherlanguage"; os << "{" << from_ascii(pl) << "}\n"; } - } + } else if (useNonTeXFonts && features.isRequired("japanese") + && features.usePrefTULangPack() + && features.runparams().flavor != Flavor::XeTeX + && !features.isProvided("luatexja")) + os << "\\usepackage{luatexja}\n"; // ... but before biblatex (see #7065) if ((features.mustProvide("biblatex") 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 -- lyx-cvs mailing list [email protected] https://lists.lyx.org/mailman/listinfo/lyx-cvs