]> git.lyx.org Git - features.git/commitdiff
tex2lyx: support rotated longtable
authorJuergen Spitzmueller <spitz@lyx.org>
Fri, 24 Aug 2018 06:50:32 +0000 (08:50 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Fri, 24 Aug 2018 06:50:32 +0000 (08:50 +0200)
src/tex2lyx/Context.cpp
src/tex2lyx/Context.h
src/tex2lyx/TODO.txt
src/tex2lyx/table.cpp
src/tex2lyx/text.cpp

index cc95a1fc6d0cb3a29e4ed0fe13028c9044257a0a..5112401b08ad408fa0dafdf6b72bc72875282f0e 100644 (file)
@@ -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();
index e48bdf35d67b4bf118ef9fb71f1bfce7a0e8f85d..4fd1ff28bb793200ec1881bc8a1787467a73ae75 100644 (file)
@@ -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);
index b348b29e8e6f6b21dfc6c201aa7c255cf51aef85..dc761361a89383d5198c2ca73a8f8fdcdbace7c9 100644 (file)
@@ -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 
 
index 2007c1c5394dd25ff0236b56991638131e20e88e..c432a2c35f2bff792d07c8f8ee59cdb3b607fb71 100644 (file)
@@ -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"
index fcea02760166275d4a079ae133dc694a033d828a..3533a505c880b212971493a87d9e18b8afb746d9 100644 (file)
@@ -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, "");