commit 766eb3f02c69ef3fea1845b53a153bfbe9e5f55a
Author: Juergen Spitzmueller <[email protected]>
Date:   Fri Aug 24 08:50:32 2018 +0200

    tex2lyx: support rotated longtable
---
 src/tex2lyx/Context.cpp |    2 +-
 src/tex2lyx/Context.h   |    2 +
 src/tex2lyx/TODO.txt    |    1 -
 src/tex2lyx/table.cpp   |    5 +++-
 src/tex2lyx/text.cpp    |   48 +++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/src/tex2lyx/Context.cpp b/src/tex2lyx/Context.cpp
index cc95a1f..5112401 100644
--- a/src/tex2lyx/Context.cpp
+++ b/src/tex2lyx/Context.cpp
@@ -85,7 +85,7 @@ Context::Context(bool need_layout_,
          new_layout_allowed(true), merging_hyphens_allowed(true),
          textclass(textclass_),
          layout(layout_), parent_layout(parent_layout_),
-         font(font_)
+         font(font_), rotlongtable(false)
 {
        if (!layout)
                layout = &textclass.defaultLayout();
diff --git a/src/tex2lyx/Context.h b/src/tex2lyx/Context.h
index e48bdf3..4fd1ff2 100644
--- a/src/tex2lyx/Context.h
+++ b/src/tex2lyx/Context.h
@@ -165,6 +165,8 @@ public:
        TeXFont font;
        /// font attributes of normal text
        static TeXFont normalfont;
+       /// A rotated longtable
+       bool rotlongtable;
 
 private:
        void begin_layout(std::ostream & os, Layout const * const & l);
diff --git a/src/tex2lyx/TODO.txt b/src/tex2lyx/TODO.txt
index b348b29..dc76136 100644
--- a/src/tex2lyx/TODO.txt
+++ b/src/tex2lyx/TODO.txt
@@ -39,7 +39,6 @@ Format LaTeX feature                        LyX feature
 526    Plural and capitalized refstyles     InsetRef
 546    Landscape support
        \begin{landscape}...\end{landscape}  \begin_inset Flex Landscape (see 
#11259)
-       with longtable content:              <features rotate ="90"...>
 555    V column type (varwidth package)     Automatically detected with 
newlines, paragraph breaks and environment content in cells of rows
 563    InsetArgument listpreamble:<nr>      All content between \begin{env} 
and first \item of a list 
 
diff --git a/src/tex2lyx/table.cpp b/src/tex2lyx/table.cpp
index 2007c1c..c432a2c 100644
--- a/src/tex2lyx/table.cpp
+++ b/src/tex2lyx/table.cpp
@@ -16,6 +16,7 @@
 
 #include "tex2lyx.h"
 
+#include "Context.h"
 #include "Preamble.h"
 
 #include "support/lassert.h"
@@ -1415,7 +1416,9 @@ void handle_tabular(Parser & p, ostream & os, string 
const & name,
 
        //cerr << "// output what we have\n";
        // output what we have
-       string const rotate = "0";
+       string rotate = "0";
+       if (is_long_tabular && context.rotlongtable)
+               rotate = "90";
        os << "\n<lyxtabular version=\"3\" rows=\"" << rowinfo.size()
           << "\" columns=\"" << colinfo.size() << "\">\n";
        os << "<features"
diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp
index fcea027..3533a50 100644
--- a/src/tex2lyx/text.cpp
+++ b/src/tex2lyx/text.cpp
@@ -1955,6 +1955,54 @@ void parse_environment(Parser & p, ostream & os, bool 
outer,
                        break;
                }
 
+               // This is only attempted at landscape environments that 
consists only
+               // of a longtable (this is how longtables in LyX are rotated by 
90 degs).
+               // Other landscape environment is handled via the landscape 
module, thus
+               // we will fall through in that case.
+               if (name == "landscape") {
+                       // We check if the next thing is a longtable
+                       p.pushPosition();
+                       bool found_end = false;
+                       bool only_longtable = false;
+                       bool end_longtable = false;
+                       p.get_token();
+                       p.get_token();
+                       string envname = p.getArg('{', '}');
+                       if (envname == "longtable") {
+                               // Now we check if the longtable is the only 
content
+                               // of the landscape environment
+                               while (!found_end && !end_longtable && 
p.good()) {
+                                       envname = p.next_token().cat() == 
catBegin
+                                                       ? p.getArg('{', '}') : 
string();
+                                       Token const & t = p.get_token();
+                                       p.skip_spaces();
+                                       end_longtable = t.asInput() != "\\end"
+                                                       && envname == 
"longtable";
+                                       found_end = t.asInput() == "\\end"
+                                                       && envname == 
"landscape";
+                               }
+                               if (end_longtable) {
+                                       p.get_token();
+                                       envname = p.getArg('{', '}');
+                                       only_longtable = 
p.next_next_token().asInput() == "\\end"
+                                                       && envname == 
"landscape";
+                               }
+                               if (only_longtable) {
+                                       p.popPosition();
+                                       p.skip_spaces();
+                                       bool const save_rotlongtable = 
parent_context.rotlongtable;
+                                       parent_context.rotlongtable = true;
+                                       parse_text(p, os, FLAG_END, outer, 
parent_context);
+                                       parent_context.rotlongtable = 
save_rotlongtable;
+                                       p.skip_spaces();
+                                       break;
+                               }
+                               // fall through
+                       }
+                       // fall through
+                       p.popPosition();
+               }
+
                if (name == "framed" || name == "shaded") {
                        eat_whitespace(p, os, parent_context, false);
                        parse_outer_box(p, os, FLAG_END, outer, parent_context, 
name, "");

Reply via email to