commit ebd6df5167c2a4adba7ea48257c3b83e4bd88838
Author: Juergen Spitzmueller <[email protected]>
Date:   Sun May 4 12:11:34 2025 +0200

    Prevent conflicting theorem definitions
    
    Provide a way to omit automatic definition and use this in
    lyx2lyx if definition is not in LyX preamble.
---
 src/LaTeXFeatures.cpp    |  2 ++
 src/tex2lyx/Preamble.cpp | 23 ++++++++++++++++++++++-
 src/tex2lyx/Preamble.h   |  4 ++++
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/LaTeXFeatures.cpp b/src/LaTeXFeatures.cpp
index 8b3452ebf1..6085cc3c13 100644
--- a/src/LaTeXFeatures.cpp
+++ b/src/LaTeXFeatures.cpp
@@ -1949,6 +1949,8 @@ string const LaTeXFeatures::getThmDefinitions() const
 
        string laststyle;
        for (auto const & thm : usedTheorems_) {
+               if (isProvided("newtheorem:" + thm.name))
+                       continue;
                if (thm.style != laststyle) {
                        tmp << "\\theoremstyle{" << thm.style << "}\n";
                        laststyle = thm.style;
diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index dd1dcfeea0..6252b99ab6 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -757,6 +757,16 @@ void Preamble::addModule(string const & module)
 }
 
 
+void Preamble::addLocalLayout(string const & s)
+{
+       for (auto const & l : local_layout) {
+               if (l == s)
+                       return;
+       }
+       local_layout.push_back(s);
+}
+
+
 void Preamble::suppressDate(bool suppress)
 {
        if (suppress)
@@ -2429,6 +2439,14 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc, 
string const & outfiled
        if (!h_options.empty())
                os << "\\options " << h_options << "\n";
        os << "\\use_default_options " << h_use_default_options << "\n";
+       if (!local_layout.empty()) {
+               os << "\\begin_local_layout\n";
+               vector<string>::const_iterator const end = local_layout.end();
+               vector<string>::const_iterator it = local_layout.begin();
+               for (; it != end; ++it)
+                       os << *it << '\n';
+               os << "\\end_local_layout\n";
+       }
        if (!used_modules.empty()) {
                os << "\\begin_modules\n";
                vector<string>::const_iterator const end = used_modules.end();
@@ -3313,8 +3331,11 @@ void Preamble::parse(Parser & p, string const & 
forceclass,
 
                        add_known_theorem(name, opt1, !opt2.empty(), 
from_utf8(complete));
 
-                       if (!in_lyx_preamble)
+                       if (!in_lyx_preamble) {
                                h_preamble << complete;
+                               // Prevent LyX from adding its own definitions
+                               addLocalLayout("Provides newtheorem:" + name + 
" 1");
+                       }
                        continue;
                }
 
diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h
index 74f77c6eaa..999498b09e 100644
--- a/src/tex2lyx/Preamble.h
+++ b/src/tex2lyx/Preamble.h
@@ -84,6 +84,8 @@ public:
        ///
        void addModule(std::string const & module);
        ///
+       void addLocalLayout(std::string const & s);
+       ///
        void suppressDate(bool suppress);
        ///
        std::string citeEngine() const { return h_cite_engine; }
@@ -141,6 +143,8 @@ private:
        std::set<std::string> auto_packages;
        ///
        std::vector<std::string> used_modules;
+       ///
+       std::vector<std::string> local_layout;
 
        /// needed to handle encodings with babel
        bool one_language;
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to