]> git.lyx.org Git - features.git/commitdiff
tex2lyx: More work on beamer support
authorJuergen Spitzmueller <spitz@lyx.org>
Wed, 14 Mar 2018 07:40:47 +0000 (08:40 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Sat, 17 Mar 2018 12:49:13 +0000 (13:49 +0100)
* Implement list item overlay support (\item<arg>)
* Implement itemcommand support (e.g., \overprint<arg>)
* Fix general list argument placement

Part of: #11068

(cherry picked from commit e51265b5f3c7765ad185303ac147792c7599386f)

src/tex2lyx/Context.cpp
src/tex2lyx/Context.h
src/tex2lyx/test/test-structure.lyx.lyx
src/tex2lyx/text.cpp

index 61685180bdd074b1f5e7f38e8b464f31432d85bc..cc95a1fc6d0cb3a29e4ed0fe13028c9044257a0a 100644 (file)
@@ -247,6 +247,8 @@ void Context::dump(ostream & os, string const & desc) const
                os << "extrastuff=[" << extra_stuff << "] ";
        if (!par_extra_stuff.empty())
                os << "parextrastuff=[" << par_extra_stuff << "] ";
+       if (!list_extra_stuff.empty())
+               os << "listextrastuff=[" << list_extra_stuff << "] ";
        os << "textclass=" << textclass.name()
           << " layout=" << to_utf8(layout->name())
           << " parent_layout=" << to_utf8(parent_layout->name()) << "] font=["
index b88a921f33e6c0ac8466e6912cd56c18d8bf5aa0..47b39fc37c1f8d43e89f9b5d63cdef0da85ddd11 100644 (file)
@@ -128,6 +128,8 @@ public:
        std::string extra_stuff;
        /// We may need to add something after this \\begin_layout command
        std::string par_extra_stuff;
+       /// We may need to add something at the beginning of a list.
+       std::string list_extra_stuff;
        /// If there has been an \\begin_deeper, we'll need a matching
        /// \\end_deeper
        bool need_end_deeper;
index 52f4e11882791202600882529b793501548e2948..87d9f6b0d2e192b8ce7a6fc3a295659d928cccee 100644 (file)
@@ -892,9 +892,10 @@ the second item
 \begin_layout Itemize
 
 \begin_inset Argument item:1
-status open
+status collapsed
 
-\begin_layout Plain Layout
+
+\begin_layout Standard
 custom label
 \end_layout
 
index a36b7558f1489d99c48fab3f2c5d1415c9fee23a..ac2bed15120962fedff59dba47f6b80e50046b29 100644 (file)
@@ -47,7 +47,7 @@ namespace lyx {
 
 namespace {
 
-void output_arguments(ostream &, Parser &, bool, bool, bool, Context &,
+void output_arguments(ostream &, Parser &, bool, bool, string, Context &,
                       Layout::LaTeXArgMap const &);
 
 }
@@ -65,11 +65,11 @@ void parse_text_in_inset(Parser & p, ostream & os, unsigned flags, bool outer,
        else
                newcontext.font = context.font;
        if (layout)
-               output_arguments(os, p, outer, false, false, newcontext,
+               output_arguments(os, p, outer, false, string(), newcontext,
                                 layout->latexargs());
        parse_text(p, os, flags, outer, newcontext, rdelim);
        if (layout)
-               output_arguments(os, p, outer, false, true, newcontext,
+               output_arguments(os, p, outer, false, "post", newcontext,
                                 layout->postcommandargs());
        newcontext.check_end_layout(os);
 }
@@ -749,14 +749,16 @@ void skip_spaces_braces(Parser & p, bool keepws = false)
 }
 
 
-void output_arguments(ostream & os, Parser & p, bool outer, bool need_layout, bool post,
+void output_arguments(ostream & os, Parser & p, bool outer, bool need_layout, string const prefix,
                       Context & context, Layout::LaTeXArgMap const & latexargs)
 {
-       if (need_layout) {
-               context.check_layout(os);
-               need_layout = false;
-       } else
-               need_layout = true;
+       if (context.layout->latextype != LATEX_ITEM_ENVIRONMENT || !prefix.empty()) {
+               if (need_layout) {
+                       context.check_layout(os);
+                       need_layout = false;
+               } else
+                       need_layout = true;
+       }
        int i = 0;
        Layout::LaTeXArgMap::const_iterator lait = latexargs.begin();
        Layout::LaTeXArgMap::const_iterator const laend = latexargs.end();
@@ -780,8 +782,8 @@ void output_arguments(ostream & os, Parser & p, bool outer, bool need_layout, bo
                                need_layout = false;
                        }
                        begin_inset(os, "Argument ");
-                       if (post)
-                               os << "post:";
+                       if (!prefix.empty())
+                               os << prefix << ':';
                        os << i << "\nstatus collapsed\n\n";
                        parse_text_in_inset(p, os, FLAG_RDELIM, outer, context, 0, rdelim);
                        end_inset(os);
@@ -806,8 +808,8 @@ void output_arguments(ostream & os, Parser & p, bool outer, bool need_layout, bo
                                need_layout = false;
                        }
                        begin_inset(os, "Argument ");
-                       if (post)
-                               os << "post:";
+                       if (!prefix.empty())
+                               os << prefix << ':';
                        os << i << "\nstatus collapsed\n\n";
                        parse_text_in_inset(p, os, FLAG_RDELIM, outer, context, 0, rdelim);
                        end_inset(os);
@@ -840,10 +842,10 @@ void output_command_layout(ostream & os, Parser & p, bool outer,
                context.need_end_deeper = true;
        }
        context.check_deeper(os);
-       output_arguments(os, p, outer, true, false, context,
+       output_arguments(os, p, outer, true, string(), context,
                         context.layout->latexargs());
        parse_text(p, os, FLAG_ITEM, outer, context);
-       output_arguments(os, p, outer, false, true, context,
+       output_arguments(os, p, outer, false, "post", context,
                         context.layout->postcommandargs());
        context.check_end_layout(os);
        if (parent_context.deeper_paragraph) {
@@ -2081,16 +2083,18 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                }
                context.check_deeper(os);
                // handle known optional and required arguments
-               // FIXME: for item environments, this is currently
-               // placed wrongly (in an empty paragraph). It has to go to
-               // the first \item par instead.
-               if (context.layout->latextype == LATEX_ENVIRONMENT
-                   || context.layout->latextype == LATEX_ITEM_ENVIRONMENT)
-                       output_arguments(os, p, outer, false, false, context,
+               if (context.layout->latextype == LATEX_ENVIRONMENT)
+                       output_arguments(os, p, outer, false, string(), context,
                                         context.layout->latexargs());
+               else if (context.layout->latextype == LATEX_ITEM_ENVIRONMENT) {
+                       ostringstream oss;
+                       output_arguments(oss, p, outer, false, string(), context,
+                                        context.layout->latexargs());
+                       context.list_extra_stuff = oss.str();
+               }
                parse_text(p, os, FLAG_END, outer, context);
                if (context.layout->latextype == LATEX_ENVIRONMENT)
-                       output_arguments(os, p, outer, false, true, context,
+                       output_arguments(os, p, outer, false, "post", context,
                                         context.layout->postcommandargs());
                context.check_end_layout(os);
                if (parent_context.deeper_paragraph) {
@@ -3074,10 +3078,10 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        continue;
                }
 
-               if (t.cs() == "item") {
+               // "item" by default, but could be something else
+               if (t.cs() == context.layout->itemcommand()) {
                        string s;
-                       bool const optarg = p.hasOpt();
-                       if (optarg) {
+                       if (context.layout->labeltype == LABEL_MANUAL) {
                                // FIXME: This swallows comments, but we cannot use
                                //        eat_whitespace() since we must not output
                                //        anything before the item.
@@ -3091,26 +3095,19 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                // An item in an unknown list-like environment
                                // FIXME: Do this in check_layout()!
                                context.has_item = false;
-                               if (optarg)
-                                       output_ert_inset(os, "\\item", context);
-                               else
-                                       output_ert_inset(os, "\\item ", context);
+                               string item = "\\" + context.layout->itemcommand();
+                               if (!p.hasOpt())
+                                       item += " ";
+                               output_ert_inset(os, item, context);
                        }
-                       if (optarg) {
-                               if (context.layout->labeltype != LABEL_MANUAL) {
-                                       // handle option of itemize item
-                                       begin_inset(os, "Argument item:1\n");
-                                       os << "status open\n";
-                                       os << "\n\\begin_layout Plain Layout\n";
-                                       Parser p2(s + ']');
-                                       os << parse_text_snippet(p2,
-                                               FLAG_BRACK_LAST, outer, context);
-                                       // we must not use context.check_end_layout(os)
-                                       // because that would close the outer itemize layout
-                                       os << "\n\\end_layout\n";
-                                       end_inset(os);
-                                       eat_whitespace(p, os, context, false);
-                               } else if (!s.empty()) {
+                       if (context.layout->labeltype != LABEL_MANUAL)
+                               output_arguments(os, p, outer, false, "item", context,
+                                                context.layout->itemargs());
+                       if (!context.list_extra_stuff.empty()) {
+                               os << context.list_extra_stuff;
+                               context.list_extra_stuff.clear();
+                       }
+                       else if (!s.empty()) {
                                        // LyX adds braces around the argument,
                                        // so we need to remove them here.
                                        if (s.size() > 2 && s[0] == '{' &&
@@ -3132,7 +3129,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                        os << ' ';
                                        eat_whitespace(p, os, context, false);
                                }
-                       }
                        continue;
                }