Regression on master: zh_CN tutorial.lyx compiles with error

Enrico Forestieri forenr at lyx.org
Wed Aug 12 09:52:45 UTC 2020


On Wed, Aug 12, 2020 at 11:06:07AM +0200, Jürgen Spitzmüller wrote:
> Am Dienstag, den 11.08.2020, 09:19 -0400 schrieb Scott Kostyshak:
> > > I fixed the manual which used odd emphases. There is still a bug in
> > LyX
> > > which I am going to investigate.
> > 
> > Sounds good, thanks. The zh_CN Tutorial.lyx now compiles for me.
> 
> Should be fixed now generally. I'd not be surprised if it broke
> elsewhere now. This is pretty delicate stuff.

Jürgen, I ma not sure what you fixed by 1af67974, however, I was
working on improving the fix for #8384 and this interferes with this
work.

First of all, the fix for #8384 does not work if an inset is not the
first thing in a selection. Secondly, I don't think the inheritFont()
method is the right thing to use in this case. The fix should apply when a
paragraph break can occur, and this has nothing to do with inheritFont().

Please, can you revert 1af67974 and then apply the attached patch to see
whether what you fixed remains fixed? The patch modifies the fix for #8384
so that only a multipar inset is enclosed in a font switch, wherever it
occurs in a selection.

Thank you.

-- 
Enrico
-------------- next part --------------
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index 133ddd15b8..8a43f8d40c 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -1043,7 +1043,7 @@ void Paragraph::Private::latexInset(BufferParams const & bparams,
 		bool needPar = false;
 		bool closeLanguage = arabtex
 			|| basefont.isRightToLeft() == running_font.isRightToLeft();
-		// We pass non_inherit_inset = true here since size switches
+		// We pass multipar_inset = true here since size switches
 		// ought not to be terminated here (#8384).
 		unsigned int count = running_font.latexWriteEndChanges(os,
 					bparams, runparams, basefont, basefont,
@@ -2443,10 +2443,12 @@ void Paragraph::latex(BufferParams const & bparams,
 	// Yes if greater than 0. This has to be static.
 	THREAD_LOCAL_STATIC int parInline = 0;
 
+	bool multipar_inset = false;
+
 	for (pos_type i = 0; i < size(); ++i) {
 		// First char in paragraph or after label?
-		if (i == body_pos) {
-			if (body_pos > 0) {
+		if (i == body_pos || multipar_inset) {
+			if (body_pos > 0 || multipar_inset) {
 				if (open_font) {
 					bool needPar = false;
 					column += running_font.latexWriteEndChanges(
@@ -2462,8 +2464,10 @@ void Paragraph::latex(BufferParams const & bparams,
 						runparams);
 				runningChange = Change(Change::UNCHANGED);
 
-				os << "}] ";
-				column +=3;
+				if (body_pos > 0) {
+					os << "}] ";
+					column +=3;
+				}
 			}
 			// For InTitle commands, we have already opened a group
 			// in output_latex::TeXOnePar.
@@ -2480,6 +2484,7 @@ void Paragraph::latex(BufferParams const & bparams,
 			if (allowcust)
 				column += d->startTeXParParams(bparams, os,
 							    runparams);
+			multipar_inset = false;
 		}
 
 		runparams.wasDisplayMath = runparams.inDisplayMath;
@@ -2490,12 +2495,12 @@ void Paragraph::latex(BufferParams const & bparams,
 
 		char_type const c = d->text_[i];
 
-		// Check whether a display math inset follows
+		// Check whether a multipar or display math inset follows
 		if (c == META_INSET
 		    && i >= start_pos && (end_pos == -1 || i < end_pos)) {
 			if (isDeleted(i))
 				runparams.ctObject = getInset(i)->CtObject(runparams);
-	
+			multipar_inset = getInset(i)->allowMultiPar();
 			InsetMath const * im = getInset(i)->asInsetMath();
 			if (im && im->asHullInset()
 			    && im->asHullInset()->outerDisplay()) {
@@ -2568,9 +2573,9 @@ void Paragraph::latex(BufferParams const & bparams,
 					     && !os.afterParbreak());
 
 		// Do we need to close the previous font?
-		if (open_font &&
+		if (open_font && (multipar_inset ||
 		    (current_font != running_font ||
-		     current_font.language() != running_font.language()))
+		     current_font.language() != running_font.language())))
 		{
 			// ensure there is no open script-wrapper
 			if (!alien_script.empty()) {
@@ -2640,7 +2645,7 @@ void Paragraph::latex(BufferParams const & bparams,
 		}
 
 		// Do we need to change font?
-		if ((current_font != running_font ||
+		if ((multipar_inset || current_font != running_font ||
 		     current_font.language() != running_font.language())
 		    && i != body_pos - 1)
 		{
@@ -2656,10 +2661,9 @@ void Paragraph::latex(BufferParams const & bparams,
 				column += 1;
 			}
 			otexstringstream ots;
-			bool const non_inherit_inset = (c == META_INSET && getInset(i) && !getInset(i)->inheritFont());
 			column += current_font.latexWriteStartChanges(ots, bparams,
 							      runparams, basefont,
-							      last_font, non_inherit_inset);
+							      last_font, multipar_inset);
 			// Check again for display math in ulem commands as a
 			// font change may also occur just before a math inset.
 			if (runparams.inDisplayMath && !deleted_display_math
diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index 4ef73db0ac..922d1cd743 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -592,6 +592,8 @@ public:
 	virtual bool asciiOnly() const { return false; }
 	/// returns whether this inset is allowed in other insets of given mode
 	virtual bool allowedIn(mode_type) const { return true; }
+	/// returns whether paragraph breaks can occur inside this inset
+	virtual bool allowMultiPar() const  { return false; }
 	/**
 	 * The font is inherited from the parent for LaTeX export if this
 	 * method returns true. No open font changes are closed in front of
diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
index b449ab392e..8458ce4728 100644
--- a/src/insets/InsetTabular.cpp
+++ b/src/insets/InsetTabular.cpp
@@ -4366,6 +4366,18 @@ bool InsetTabular::insetAllowed(InsetCode code) const
 }
 
 
+bool InsetTabular::allowMultiPar() const
+{
+	for (Tabular::col_type c = 0; c < tabular.ncols(); ++c) {
+		for (Tabular::row_type r = 0; r < tabular.nrows(); ++r) {
+			if (tabular.cellInset(r,c)->allowMultiPar())
+				return true;
+		}
+	}
+	return false;
+}
+
+
 bool InsetTabular::allowsCaptionVariation(std::string const & newtype) const
 {
 	return tabular.is_long_tabular &&
diff --git a/src/insets/InsetTabular.h b/src/insets/InsetTabular.h
index 028da97969..fd942049ba 100644
--- a/src/insets/InsetTabular.h
+++ b/src/insets/InsetTabular.h
@@ -83,6 +83,8 @@ public:
 	void metrics(MetricsInfo &, Dimension &) const;
 	/// Needs to be same as InsetTabular
 	bool inheritFont() const { return false; }
+	/// Can the cell contain several paragraphs?
+	bool allowMultiPar() const { return !isMultiRow && (!isMultiColumn || isFixedWidth); }
 private:
 	/// unimplemented
 	InsetTableCell();
@@ -135,8 +137,6 @@ private:
 	virtual bool forceLocalFontSwitch() const;
 	/// Is the width forced to some value?
 	bool hasFixedWidth() const { return isFixedWidth; }
-	/// Can the cell contain several paragraphs?
-	bool allowMultiPar() const { return !isMultiRow && (!isMultiColumn || isFixedWidth); }
 };
 
 
@@ -979,6 +979,8 @@ public:
 	    insets that may contain several paragraphs */
 	bool inheritFont() const { return false; }
 	///
+	bool allowMultiPar() const;
+	///
 	bool allowsCaptionVariation(std::string const &) const;
 	//
 	bool isTable() const { return true; }
diff --git a/src/insets/InsetText.h b/src/insets/InsetText.h
index d86bfb75d3..ca09a683c3 100644
--- a/src/insets/InsetText.h
+++ b/src/insets/InsetText.h
@@ -161,7 +161,7 @@ public:
 	///
 	virtual bool isMacroScope() const { return false; }
 	///
-	virtual bool allowMultiPar() const { return getLayout().isMultiPar(); }
+	bool allowMultiPar() const { return getLayout().isMultiPar(); }
 	///
 	bool isInTitle() const { return intitle_context_; }
 	///


More information about the lyx-devel mailing list