commit f8b0462f904ca7c41bd239e5aef8bade5ba8faf0
Author: Juergen Spitzmueller <[email protected]>
Date:   Thu May 15 09:09:53 2025 +0200

    tex2lyx: fix enumitem handling at the core
    
    Rather than working around the non-known arguments, make these
    arguments known to tex2lyx by re-reading the layouts after the
    module has been added.
---
 src/tex2lyx/Context.h    |  2 --
 src/tex2lyx/Preamble.cpp | 16 +++++++++++++---
 src/tex2lyx/Preamble.h   |  2 +-
 src/tex2lyx/text.cpp     | 26 --------------------------
 4 files changed, 14 insertions(+), 32 deletions(-)

diff --git a/src/tex2lyx/Context.h b/src/tex2lyx/Context.h
index c6ff034d74..ea2d04de4a 100644
--- a/src/tex2lyx/Context.h
+++ b/src/tex2lyx/Context.h
@@ -132,8 +132,6 @@ public:
        std::string list_extra_stuff;
        /// Stuff between list begin and first item
        std::string list_preamble;
-       /// Optional argument of list environments
-       std::string list_options;
        /// A LaTeXParam to be ignored in parsing.
        std::string latexparam;
        /// If there has been an \\begin_deeper, we'll need a matching
diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index a5263123b9..e6b2c3d793 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -1178,7 +1178,7 @@ void Preamble::handle_geometry(vector<string> & options)
 
 void Preamble::handle_package(Parser &p, string const & name,
                               string const & opts, bool in_lyx_preamble,
-                              bool detectEncoding)
+                              bool detectEncoding, TeX2LyXDocClass & tc)
 {
        vector<string> options = split_options(opts);
        add_package(name, options);
@@ -2343,8 +2343,18 @@ void Preamble::handle_package(Parser &p, string const & 
name,
        }
 
        else if (name == "enumitem") {
-               // Load "enumitem" module
+               // We need to load "enumitem" module explicitly.
+               // LyX will not load it automatically since the layout
+               // it provides are also provided by the class.
+               // But of course we want enumitem's versions here.
                addModule("enumitem");
+               // Also we need to re-read the layout file since enumitem adds 
options
+               // to already existing layouts.
+               FileName layout_file = libFileSearch("layouts", "enumitem", 
"module");
+               if (layout_file.empty())
+                       warning_message("Module enumitem not found!");
+               else
+                       tc.read(layout_file, TextClass::MODULE);
                // Add the package options to the global document options
                if (!options.empty()) {
                        if (h_options.empty())
@@ -3308,7 +3318,7 @@ void Preamble::parse(Parser & p, string const & 
forceclass,
                        vector<string>::const_iterator end = vecnames.end();
                        for (; it != end; ++it)
                                handle_package(p, trimSpaceAndEol(*it), options,
-                                              in_lyx_preamble, detectEncoding);
+                                              in_lyx_preamble, detectEncoding, 
tc);
                        continue;
                }
 
diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h
index 999498b09e..5a0efa25ad 100644
--- a/src/tex2lyx/Preamble.h
+++ b/src/tex2lyx/Preamble.h
@@ -287,7 +287,7 @@ private:
        ///
        void handle_package(Parser &p, std::string const & name,
                            std::string const & opts, bool in_lyx_preamble,
-                           bool detectEncoding);
+                           bool detectEncoding, TeX2LyXDocClass & tc);
        ///
        void handle_if(Parser & p, bool in_lyx_preamble);
 
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index 5ee3e7bf59..4bfba4182c 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -2607,22 +2607,6 @@ void parse_environment(Parser & p, ostream & os, bool 
outer,
                        eat_whitespace(p, os, parent_context, false);
                        Context context(true, parent_context.textclass, 
newlayout,
                                        parent_context.layout, 
parent_context.font);
-                       if ((context.layout->latextype == LATEX_LIST_ENVIRONMENT
-                            || context.layout->latextype == 
LATEX_ITEM_ENVIRONMENT)
-                            && p.hasOpt()
-                            && context.layout->latexargs().empty()) {
-                               // FIXME: findLayout() looks for layouts in the 
class
-                               // first and only in modules if a layout is not 
found.
-                               // So if a module adds arguments to existing 
layouts
-                               // (e.g., enumitem to itemize), they wont't be 
recognized (#13185).
-                               // Workaround: If a list environment has an 
optional argument,
-                               // and the document class layout does not 
provide for
-                               // an optional argument (some, e.g. beamer, 
do!),
-                               // store it here to output it manually later
-                               // in the first list paragraph.
-                               context.list_options = p.getArg('[', ']');
-                               p.skip_spaces(true);
-                       }
                        if (parent_context.deeper_paragraph) {
                                // We are beginning a nested environment after a
                                // deeper paragraph inside the outer list 
environment.
@@ -3711,16 +3695,6 @@ void parse_text(Parser & p, ostream & os, unsigned 
flags, bool outer,
                        if (context.layout->labeltype != LABEL_MANUAL)
                                output_arguments(os, p, outer, false, "item", 
context,
                                                 context.layout->itemargs());
-                       if (!context.list_options.empty()) {
-                               // We have an optional list argument. Output it 
here.
-                               begin_inset(os, "Argument 1");
-                               os << "\nstatus collapsed\n\n"
-                                  << "\\begin_layout Plain Layout\n\n";
-                               output_ert_inset(os, 
rtrim(context.list_options), context);
-                               os << "\n\\end_layout";
-                               end_inset(os);
-                               context.list_options.clear();
-                       }
                        if (!context.list_preamble.empty()) {
                                // We have a list preamble. Output it here.
                                begin_inset(os, "Argument listpreamble:1");
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to