commit 69bc0db8fe5beb7185c982e177c48ec0c3c753b2
Author: Juergen Spitzmueller <sp...@lyx.org>
Date:   Sun Mar 2 04:24:59 2025 +0100

    tex2lyx: support for \arrayrulecolor and \columncolors
---
 src/tex2lyx/Context.h    |  9 +++++++++
 src/tex2lyx/Preamble.cpp | 34 +++++++++++++++++++++++++++++++++-
 src/tex2lyx/Preamble.h   |  4 ++++
 src/tex2lyx/table.cpp    |  4 ++++
 src/tex2lyx/text.cpp     | 24 ++++++++++++++++++++++++
 5 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/src/tex2lyx/Context.h b/src/tex2lyx/Context.h
index 427e4020a8..4211ef9f51 100644
--- a/src/tex2lyx/Context.h
+++ b/src/tex2lyx/Context.h
@@ -180,6 +180,15 @@ public:
        bool in_table_cell;
        ///
        char cell_align;
+       ///
+       std::string current_table_bordercolor;
+       ///
+       std::string current_table_odd_row_color;
+       ///
+       std::string current_table_even_row_color;
+       ///
+       int current_table_alt_row_colors_start = 1;
+       
 
 private:
        void begin_layout(std::ostream & os, Layout const * const & l);
diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp
index 4991912cd5..e9aabd2bbb 100644
--- a/src/tex2lyx/Preamble.cpp
+++ b/src/tex2lyx/Preamble.cpp
@@ -352,7 +352,7 @@ const char * const known_xetex_packages[] = {"arabxetex", 
"fixlatvian",
 
 /// packages that are automatically skipped if loaded by LyX
 const char * const known_lyx_packages[] = {"amsbsy", "amsmath", "amssymb",
-"amstext", "amsthm", "array", "babel", "booktabs", "calc", "CJK", "color",
+"amstext", "amsthm", "array", "babel", "booktabs", "calc", "CJK", "color", 
"colortbl",
 "float", "fontspec", "framed", "graphicx", "hhline", "ifthen", "longtable",
 "makeidx", "minted", "multirow", "nomencl", "parskip", "pdfpages", 
"prettyref", "refstyle",
 "rotating", "rotfloat", "splitidx", "setspace", "subscript", 
"tabularx","textcomp", "tipa",
@@ -2544,6 +2544,14 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc, 
string const & outfiled
                os << "\\backgroundcolor " << h_backgroundcolor << '\n';
        if (!h_boxbgcolor.empty())
                os << "\\boxbgcolor " << h_boxbgcolor << '\n';
+       if (!h_table_bordercolor.empty())
+               os << "\\table_border_color " << h_table_bordercolor << '\n';
+       if (!h_table_odd_row_color.empty())
+               os << "\\table_odd_row_color " << h_table_odd_row_color << '\n';
+       if (!h_table_even_row_color.empty())
+               os << "\\table_even_row_color " << h_table_even_row_color << 
'\n';
+       if (h_table_alt_row_colors_start != 0)
+               os << "\\table_alt_row_colors_start " << 
h_table_alt_row_colors_start << '\n';
        if (index_number != 0)
                for (int i = 0; i < index_number; i++) {
                        os << "\\index " << h_index[i] << '\n'
@@ -3416,6 +3424,30 @@ void Preamble::parse(Parser & p, string const & 
forceclass,
                        continue;
                }
 
+               if (t.cs() == "arrayrulecolor") {
+                       string const color = p.getArg('{', '}');
+                       h_table_bordercolor = getLyXColor(color, true);
+                       if (h_table_bordercolor.empty())
+                               h_preamble << "\\arrayrulecolor{" << color << 
'}';
+               }
+
+               if (t.cs() == "rowcolors") {
+                       string const startrow = p.getArg('{', '}');
+                       string const oddrowcolor = p.getArg('{', '}');
+                       string const evenrowcolor = p.getArg('{', '}');
+                       if (isStrInt(startrow))
+                               h_table_alt_row_colors_start = 
convert<int>(startrow);
+                       else
+                               h_table_alt_row_colors_start = 1;
+                       h_table_odd_row_color = getLyXColor(oddrowcolor, true);
+                       h_table_even_row_color = getLyXColor(evenrowcolor, 
true);
+                       if (h_table_odd_row_color.empty() || 
h_table_even_row_color.empty()) {
+                               h_table_odd_row_color = "default";
+                               h_table_even_row_color = "default";
+                               h_preamble << "\\rowcolors{" << startrow << 
"}{" << oddrowcolor << "}{" << evenrowcolor << '}';
+                       }
+               }
+
                if (t.cs() == "definecolor") {
                        string const color = p.getArg('{', '}');
                        string const space = p.getArg('{', '}');
diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h
index e29684f988..fbd3973fa4 100644
--- a/src/tex2lyx/Preamble.h
+++ b/src/tex2lyx/Preamble.h
@@ -250,6 +250,10 @@ private:
        std::string h_spacing;
        std::string h_suppress_date;
        std::string h_save_transient_properties;
+       std::string h_table_bordercolor;
+       std::string h_table_odd_row_color;
+       std::string h_table_even_row_color;
+       int h_table_alt_row_colors_start;
        std::string h_textclass;
        std::string h_tocdepth;
        std::string h_tracking_changes;
diff --git a/src/tex2lyx/table.cpp b/src/tex2lyx/table.cpp
index 994a0cdc89..03fda173b0 100644
--- a/src/tex2lyx/table.cpp
+++ b/src/tex2lyx/table.cpp
@@ -1575,6 +1575,10 @@ void handle_tabular(Parser & p, ostream & os, string 
const & name,
        os << "<features"
           << write_attribute("rotate", context.tablerotation)
           << write_attribute("booktabs", booktabs)
+          << write_attribute("borderColor", context.current_table_bordercolor)
+          << write_attribute("oddRowsColor", 
context.current_table_odd_row_color)
+          << write_attribute("evenRowsColor", 
context.current_table_even_row_color)
+          << write_attribute("startAltRowColors", 
context.current_table_alt_row_colors_start)
           << write_attribute("islongtable", is_long_tabular);
        if (is_long_tabular) {
                os << write_attribute("firstHeadTopDL", endfirsthead.topDL)
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index e8aab1b68b..0fd2c91127 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -5952,6 +5952,30 @@ void parse_text(Parser & p, ostream & os, unsigned 
flags, bool outer,
                        continue;
                }
 
+               // This accounts for the following table(s)
+               if (t.cs() == "arrayrulecolor") {
+                       string const color = p.getArg('{', '}');
+                       context.current_table_bordercolor = 
preamble.getLyXColor(color);
+                       if (context.current_table_bordercolor.empty())
+                               output_ert_inset(os, t.asInput(), context);
+               }
+
+               // This accounts for the following table(s)
+               if (t.cs() == "rowcolors") {
+                       string const startrow = p.getArg('{', '}');
+                       string const oddrowcolor = p.getArg('{', '}');
+                       string const evenrowcolor = p.getArg('{', '}');
+                       if (isStrInt(startrow))
+                               context.current_table_alt_row_colors_start = 
convert<int>(startrow);
+                       else
+                               context.current_table_alt_row_colors_start = 1;
+                       context.current_table_odd_row_color = 
preamble.getLyXColor(oddrowcolor);
+                       context.current_table_even_row_color = 
preamble.getLyXColor(evenrowcolor);
+                       if (context.current_table_odd_row_color.empty() || 
context.current_table_even_row_color.empty())
+                               output_ert_inset(os, t.asInput(), context);
+               }
+               
+
                if (t.cs() == "DeclareRobustCommand" ||
                         t.cs() == "DeclareRobustCommandx" ||
                         t.cs() == "newcommand" ||
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to