[LyX/master] Prevent duplicate theorem definitions (#13302)

Juergen Spitzmueller <[email protected]>
Newsgroups gmane.editors.lyx.cvs
Message-ID <[email protected]>
commit e2baf31523f55b163bf79bdaeaa82ba090c47118
Author: Juergen Spitzmueller <[email protected]>
Date:   Thu Apr 23 10:27:34 2026 +0200

    Prevent duplicate theorem definitions (#13302)
    
    If theorems are multiply defined, use the last definition.
---
 lib/layouts/theorems-starred-equivalents.inc | 24 ------------------------
 src/LaTeXFeatures.cpp                        |  8 ++++----
 src/LaTeXFeatures.h                          |  2 +-
 3 files changed, 5 insertions(+), 29 deletions(-)

diff --git a/lib/layouts/theorems-starred-equivalents.inc b/lib/layouts/theorems-starred-equivalents.inc
index 881b6a0363..5c613ddc03 100644
--- a/lib/layouts/theorems-starred-equivalents.inc
+++ b/lib/layouts/theorems-starred-equivalents.inc
@@ -6,83 +6,59 @@ Format 116
 Style Theorem
 	CopyStyle	Theorem*
 	DependsOn	Theorem*
-	Preamble
-	EndPreamble
 End
 
 Style Corollary
 	CopyStyle	Corollary*
 	DependsOn	Corollary*
-	Preamble
-	EndPreamble
 End
 
 Style Lemma
 	CopyStyle	Lemma*
 	DependsOn	Lemma*
-	Preamble
-	EndPreamble
 End
 
 Style Proposition
 	CopyStyle	Proposition*
 	DependsOn	Proposition*
-	Preamble
-	EndPreamble
 End
 
 Style Conjecture
 	CopyStyle	Conjecture*
 	DependsOn	Conjecture*
-	Preamble
-	EndPreamble
 End
 
 Style Definition
 	CopyStyle	Definition*
 	DependsOn	Definition*
-	Preamble
-	EndPreamble
 End
 
 Style Example
 	CopyStyle	Example*
 	DependsOn	Example*
-	Preamble
-	EndPreamble
 End
 
 Style Solution
 	CopyStyle	Solution*
 	DependsOn	Solution*
-	Preamble
-	EndPreamble
 End
 
 Style Problem
 	CopyStyle	Problem*
 	DependsOn	Problem*
-	Preamble
-	EndPreamble
 End
 
 Style Exercise
 	CopyStyle	Exercise*
 	DependsOn	Exercise*
-	Preamble
-	EndPreamble
 End
 
 Style Remark
 	CopyStyle	Remark*
 	DependsOn	Remark*
-	Preamble
-	EndPreamble
 End
 
 Style Claim
 	CopyStyle	Claim*
 	DependsOn	Claim*
-	Preamble
-	EndPreamble
 End
diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index de7086b251..4bc7f7af4e 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -702,7 +702,7 @@ void LaTeXFeatures::useLayout(docstring const & layoutname, int level)
 			thm.style = layout.thmStyle();
 			thm.zrefname = layout.thmZRefName();
 			thm.refprefix = to_ascii(layout.refprefix);
-			usedTheorems_.push_back(thm);
+			usedTheorems_[thm.name] = thm;
 			require("amsthm");
 		}
 		usedLayouts_.push_back(layoutname);
@@ -2045,8 +2045,8 @@ string const LaTeXFeatures::getThmDefinitions() const
 	ostringstream tmp;
 
 	string laststyle;
-	for (auto const & thm : usedTheorems_) {
-		if (isProvided("newtheorem:" + thm.name))
+	for (auto const & [name, thm] : usedTheorems_) {
+		if (isProvided("newtheorem:" + name))
 			continue;
 		if (thm.style != laststyle) {
 			tmp << "\\theoremstyle{" << thm.style << "}\n";
@@ -2077,7 +2077,7 @@ string const LaTeXFeatures::getThmExtraDefinitions() const
 {
 	ostringstream tmp;
 
-	for (auto const & thm : usedTheorems_) {
+	for (auto const & [name, thm] : usedTheorems_) {
 		if (thm.counter == "none" || !refPrefixUsed(from_ascii(thm.refprefix)))
 			continue;
 
diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h
index acbfaba62c..2e5b61db79 100644
--- a/src/LaTeXFeatures.h
+++ b/src/LaTeXFeatures.h
@@ -263,7 +263,7 @@ private:
 	///
 	UsedFloats usedFloats_;
 	///
-	std::list<ThmInfo> usedTheorems_;
+	std::map<std::string, ThmInfo> usedTheorems_;
 	///
 	std::set<docstring> usedRefPrefixes_;
 	///
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.