[LyX/master] Amend 9716e79624a4d

Juergen Spitzmueller spitz at lyx.org
Mon Dec 19 06:05:14 UTC 2022


commit c2a324e2422880c3125f61487b10f2fb0c98759a
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Mon Dec 19 08:00:06 2022 +0100

    Amend 9716e79624a4d
    
    If the main language does not require the inputenc package, but a
    secondary language does, inputenc needs to be loaded as well
    (without options)
    
    Also simplify the code a bit.
---
 src/BufferParams.cpp |   58 ++++++++++++++++++++++++++++++-------------------
 1 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp
index 71390d7..d94af3a 100644
--- a/src/BufferParams.cpp
+++ b/src/BufferParams.cpp
@@ -3388,28 +3388,44 @@ void BufferParams::writeEncodingPreamble(otexstream & os,
 	if (useNonTeXFonts)
 		return;
 
-	if (inputenc == "auto-legacy") {
-		string const doc_encoding =
-			language->encoding()->latexName();
-		Encoding::Package const package =
-			language->encoding()->package();
+	string const doc_encoding = encoding().latexName();
+	Encoding::Package const package = encoding().package();
+	// (dvi)lualatex uses luainputenc rather than inputenc
+	string const inputenc_package = 
+		(features.runparams().flavor == Flavor::LuaTeX
+		 || features.runparams().flavor == Flavor::DviLuaTeX)
+		? "luainputenc" : "inputenc";
 
-		// The "japanese" babel-language requires  the pLaTeX engine
+	if (inputenc == "auto-legacy") {
+		// The "japanese" babel language requires the pLaTeX engine
 		// which conflicts with "inputenc".
 		// See http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg129680.html
-		if (package == Encoding::inputenc
-		    && !features.isRequired("japanese")
+		if (!features.isRequired("japanese")
 		    && !features.isProvided("inputenc")) {
-			os << "\\usepackage["
-			   << from_ascii(doc_encoding);
-			if (features.runparams().flavor == Flavor::LuaTeX
-			    || features.runparams().flavor == Flavor::DviLuaTeX)
-				os << "]{luainputenc}\n";
-			else
-				os << "]{inputenc}\n";
+			if (package == Encoding::inputenc) {
+				// Main language requires (lua)inputenc
+				os << "\\usepackage["
+				   << from_ascii(doc_encoding);
+				os << "]{" << inputenc_package << "}\n";
+			} else {
+				// We might have an additional language that requires inputenc
+				set<string> encoding_set = features.getEncodingSet(doc_encoding);
+				bool inputenc = false;
+				for (auto const & enc : encoding_set) {
+					if (encodings.fromLaTeXName(enc)
+					    && encodings.fromLaTeXName(enc)->package() == Encoding::inputenc) {
+						inputenc = true;
+						break;
+					}
+				}
+				if (inputenc)
+					// load (lua)inputenc without options
+					// (the encoding is loaded later)
+					os << "\\usepackage{" << inputenc_package << "}\n";
+			}
 		}
 	} else if (inputenc != "auto-legacy-plain") {
-		switch (encoding().package()) {
+		switch (package) {
 		case Encoding::none:
 		case Encoding::CJK:
 		case Encoding::japanese:
@@ -3425,7 +3441,6 @@ void BufferParams::writeEncodingPreamble(otexstream & os,
 			if (features.isRequired("japanese")
 			    || features.isProvided("inputenc"))
 				break;
-			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.
@@ -3437,12 +3452,9 @@ void BufferParams::writeEncodingPreamble(otexstream & os,
 			    && 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
-				os << "]{inputenc}\n";
+			os << "\\usepackage["
+			   << from_ascii(doc_encoding)
+			   << "]{" << inputenc_package << "}\n";
 			break;
 		}
 	}


More information about the lyx-cvs mailing list