[LyX/master] tex2lyx support for parfillskip

Juergen Spitzmueller <[email protected]> Sun, 02 Aug 2026 16:26:09 +0000
Newsgroups gmane.editors.lyx.cvs
Message-ID <[email protected]>
commit 2766e7ef00461bb7f5068a25a8b11bfdcacaf6c0
Author: Juergen Spitzmueller <[email protected]>
Date:   Sun Aug 2 18:25:48 2026 +0200

    tex2lyx support for parfillskip
---
 src/tex2lyx/Preamble.cpp | 74 +++++++++++++++++++++++++++++++++++-------------
 src/tex2lyx/Preamble.h   |  2 ++
 2 files changed, 56 insertions(+), 20 deletions(-)

diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index 61dac99ac9..7ce1014e3f 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -971,6 +971,8 @@ Preamble::Preamble() : one_language(true), default_language("english"),
 	h_cite_engine_type        = "default";
 	h_color                   = "#008000";
 	h_defskip                 = "medskip";
+	h_parfillskip_type        = "default";
+	h_parfillskip_value       = "";
 	h_dynamic_quotes          = false;
 	//h_float_placement;
 	//h_fontcolor;
@@ -2212,27 +2214,47 @@ void Preamble::handle_package(Parser &p, string const & name,
 		delete_opt(options, o);
 	}
 
-	else if (name == "parskip" && options.size() < 2 && (opts.empty() || prefixIs(opts, "skip="))) {
-		if (opts.empty())
-			h_paragraph_separation = "halfline";
-		else {
-			if (opts == "skip=\\smallskipamount")
-				h_defskip = "smallskip";
-			else if (opts == "skip=\\medskipamount")
-				h_defskip = "medskip";
-			else if (opts == "skip=\\bigskipamount")
-				h_defskip = "bigskip";
-			else if (opts == "skip=\\baselineskip")
-				h_defskip = "fullline";
-			else {
-				// get value, unbraced
-				string length = rtrim(ltrim(token(opts, '=', 1), "{"), "}");
-				// transform glue length if we have one
-				is_glue_length(length);
-				h_defskip = length;
+	else if (name == "parskip"
+		 && (opts.empty()
+		     || (options.size() == 1 && (prefixIs(opts, "skip=") || (prefixIs(opts, "parfill="))))
+		     || (options.size() == 2 && contains(opts, "skip=") && (contains(opts, "parfill="))))) {
+		h_paragraph_separation = "skip";
+		h_defskip = "halfline";
+		if (!opts.empty()) {
+			vector<string> ps_options = getVectorFromString(opts);
+			for (auto const & o : ps_options) {
+				if (o == "skip=\\smallskipamount")
+					h_defskip = "smallskip";
+				else if (o == "skip=\\medskipamount")
+					h_defskip = "medskip";
+				else if (o == "skip=\\bigskipamount")
+					h_defskip = "bigskip";
+				else if (o == "skip=\\baselineskip")
+					h_defskip = "fullline";
+				else if (prefixIs(o, "skip=")) {
+					// get value, unbraced
+					string length = rtrim(ltrim(token(o, '=', 1), "{"), "}");
+					// transform glue length if we have one
+					is_glue_length(length);
+					h_defskip = length;
+				}
+				if (prefixIs(o, "parfill=")) {
+					// get value, unbraced
+					string const content = rtrim(ltrim(token(o, '=', 1), "{"), "}");
+					if (content == "\\z@ plus 1fil")
+						h_parfillskip_type = "none";
+					else if (content == ".3333\\linewidth plus 1fil")
+						h_parfillskip_type = "thirdline";
+					else if (content == ".25\\linewidth plus 1fil")
+						h_parfillskip_type = "quarterline";
+					else {
+						h_parfillskip_type = "custom";
+						h_parfillskip_value = translate_len(content);
+					}
+				}
 			}
-			h_paragraph_separation = "skip";
 		}
+		options.clear();
 	}
 
 	else if (is_known(name, known_lyx_packages) && options.empty()) {
@@ -2694,7 +2716,8 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc, string const & outfiled
 	os << h_margins
 	   << "\\secnumdepth " << h_secnumdepth << "\n"
 	   << "\\tocdepth " << h_tocdepth << "\n"
-	   << "\\paragraph_separation " << h_paragraph_separation << "\n";
+	   << "\\paragraph_separation " << h_paragraph_separation << "\n"
+	   << "\\parfillskip \"" << h_parfillskip_type << "\" \"" << h_parfillskip_value << "\"\n";
 	if (h_paragraph_separation == "skip")
 		os << "\\defskip " << h_defskip << "\n";
 	else
@@ -3513,6 +3536,17 @@ void Preamble::parse(Parser & p, string const & forceclass,
 					h_defskip = "fullline";
 				else
 					h_defskip = translate_len(content);
+			} else if (name == "\\parfillskip") {
+				if (content == "\\z@ plus 1fil")
+					h_parfillskip_type = "none";
+				else if (content == ".3333\\linewidth plus 1fil")
+					h_parfillskip_type = "thirdline";
+				else if (content == ".25\\linewidth plus 1fil")
+					h_parfillskip_type = "quarterline";
+				else {
+					h_parfillskip_type = "custom";
+					h_parfillskip_value = translate_len(content);
+				}
 			} else if (name == "\\mathindent") {
 				h_mathindentation = translate_len(content);
 			} else
diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h
index 3b3011478c..61a8a4f8b5 100644
--- a/src/tex2lyx/Preamble.h
+++ b/src/tex2lyx/Preamble.h
@@ -178,6 +178,8 @@ private:
 	std::map<std::string, std::string> h_custom_colors;
 	std::string h_color;
 	std::string h_defskip;
+	std::string h_parfillskip_type;
+	std::string h_parfillskip_value;
 	bool h_dynamic_quotes;
 	std::string h_float_placement;
 	std::string h_fontcolor;
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs