[LyX/master] Load ucs before utf8x inputenc with recent ucs versions

Juergen Spitzmueller spitz at lyx.org
Tue Aug 16 15:10:08 UTC 2022


commit e6b93f7489fc0738b6097d49cb7b16eed2b4fb1e
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Tue Aug 16 17:56:07 2022 +0200

    Load ucs before utf8x inputenc with recent ucs versions
    
    Otherwise inputenc falls back to utf8 option, which breaks documents
---
 lib/chkconfig.ltx    |    3 +++
 src/BufferParams.cpp |   16 ++++++++++++++--
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/lib/chkconfig.ltx b/lib/chkconfig.ltx
index d2613e9..3f5427c 100644
--- a/lib/chkconfig.ltx
+++ b/lib/chkconfig.ltx
@@ -591,6 +591,9 @@
 % With this version, hyperref option unicode is true
 % by default
 \TestPackageVersion{hyperref}{2021/02/04}
+% As of this version, the ucs package must be explicitly
+% loaded to get utf8x (rather than utf8) encoding tables
+\TestPackageVersion{ucs}{2022/08/07}
 
 %%% Document classes
 % The list of layout files has been put in this file here by the
diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 3bb9445..d25dd05 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -3440,8 +3440,20 @@ void BufferParams::writeEncodingPreamble(otexstream & os,
 			if (features.isRequired("japanese")
 			    || features.isProvided("inputenc"))
 				break;
-			os << "\\usepackage[" << from_ascii(encoding().latexName());
-		   	if (features.runparams().flavor == Flavor::LuaTeX
+			string const doc_encoding = encoding().latexName();
+			// The 2022 release of ucs.sty uses the default utf8
+			// inputenc encoding with 'utf8x' inputenc if the ucs
+			// package is not loaded before inputenc.
+			// This breaks existing documents that use utf8x
+			// and also makes utf8x redundant.
+			// Thus we load ucs.sty in order to keep functionality
+			// that would otherwise be silently dropped.
+			if (doc_encoding == "utf8x"
+			    && features.isAvailable("ucs-2022/08/07")
+			    && !features.isProvided("ucs"))
+				os << "\\usepackage{ucs}\n";
+			os << "\\usepackage[" << from_ascii(doc_encoding);
+			if (features.runparams().flavor == Flavor::LuaTeX
 			    || features.runparams().flavor == Flavor::DviLuaTeX)
 				os << "]{luainputenc}\n";
 			else


More information about the lyx-cvs mailing list