commit 05fa23682904157223cb3865b57b5ded6eb6208e
Author: Juergen Spitzmueller <[email protected]>
Date: Wed May 14 14:20:48 2025 +0200
tex2lyx: recognize enumitem and fix import of its optional list arguments
(#13185)
---
src/tex2lyx/Context.h | 2 ++
src/tex2lyx/Preamble.cpp | 12 ++++++++++++
src/tex2lyx/text.cpp | 23 +++++++++++++++++++++--
3 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/src/tex2lyx/Context.h b/src/tex2lyx/Context.h
index ea2d04de4a..c6ff034d74 100644
--- a/src/tex2lyx/Context.h
+++ b/src/tex2lyx/Context.h
@@ -132,6 +132,8 @@ 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 eecf54a055..a5263123b9 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -2342,6 +2342,18 @@ void Preamble::handle_package(Parser &p, string const &
name,
}
}
+ else if (name == "enumitem") {
+ // Load "enumitem" module
+ addModule("enumitem");
+ // Add the package options to the global document options
+ if (!options.empty()) {
+ if (h_options.empty())
+ h_options = join(options, ",");
+ else
+ h_options += ',' + join(options, ",");
+ }
+ }
+
else if (name == "changebar")
h_output_changes = "true";
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index 56cf527847..33d69f7f48 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -2607,6 +2607,15 @@ 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()) {
+ // if a list environment has an optional
argument
+ // (e.g., with enumitem), store it to output it
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.
@@ -2626,7 +2635,7 @@ void parse_environment(Parser & p, ostream & os, bool
outer,
newcontext.check_end_layout(os);
}
switch (context.layout->latextype) {
- case LATEX_LIST_ENVIRONMENT:
+ case LATEX_LIST_ENVIRONMENT:
context.in_list_preamble =
!context.layout->listpreamble().empty()
&&
p.hasListPreamble(context.layout->itemcommand());
@@ -2634,7 +2643,7 @@ void parse_environment(Parser & p, ostream & os, bool
outer,
+ p.verbatim_item()
+ '\n');
p.skip_spaces();
break;
- case LATEX_BIB_ENVIRONMENT:
+ case LATEX_BIB_ENVIRONMENT:
p.verbatim_item(); // swallow next arg
p.skip_spaces();
break;
@@ -3695,6 +3704,16 @@ 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