Author: baum
Date: Sun Oct 16 21:57:10 2011
New Revision: 39871
URL: http://www.lyx.org/trac/changeset/39871

Log:
Fix bug #7468 (at least for standard environments).
List environments (as the one in the bug report) can't
be handled correctly in tex2lyx as long as LyX does not allow contents
after the environment start but before the first \item.

Modified:
   lyx-devel/trunk/src/tex2lyx/text.cpp

Modified: lyx-devel/trunk/src/tex2lyx/text.cpp
==============================================================================
--- lyx-devel/trunk/src/tex2lyx/text.cpp        Sun Oct 16 10:22:20 2011        
(r39870)
+++ lyx-devel/trunk/src/tex2lyx/text.cpp        Sun Oct 16 21:57:10 2011        
(r39871)
@@ -683,7 +683,7 @@
                        break;
                case optional:
                        // true because we must not eat whitespace
-                       // if an optional arg follows me must not strip the
+                       // if an optional arg follows we must not strip the
                        // brackets from this one
                        if (i < no_arguments - 1 &&
                            template_arguments[i+1] == optional)
@@ -1201,6 +1201,49 @@
                        break;
                }
                context.check_deeper(os);
+               // handle known optional and required arguments
+               // layouts require all optional arguments before the required 
ones
+               // Unfortunately LyX can't handle arguments of list arguments 
(bug 7468):
+               // It is impossible to place anything after the environment 
name,
+               // but before the first \\item.
+               if (context.layout->latextype == LATEX_ENVIRONMENT) {
+                       bool need_layout = true;
+                       unsigned int optargs = 0;
+                       while (optargs < context.layout->optargs) {
+                               eat_whitespace(p, os, context, false);
+                               if (p.next_token().cat() == catEscape ||
+                                   p.next_token().character() != '[') 
+                                       break;
+                               p.get_token(); // eat '['
+                               if (need_layout) {
+                                       context.check_layout(os);
+                                       need_layout = false;
+                               }
+                               begin_inset(os, "OptArg\n");
+                               os << "status collapsed\n\n";
+                               parse_text_in_inset(p, os, FLAG_BRACK_LAST, 
outer, context);
+                               end_inset(os);
+                               eat_whitespace(p, os, context, false);
+                               ++optargs;
+                       }
+                       unsigned int reqargs = 0;
+                       while (LYX_FORMAT >= 392 && reqargs < 
context.layout->reqargs) {
+                               eat_whitespace(p, os, context, false);
+                               if (p.next_token().cat() != catBegin)
+                                       break;
+                               p.get_token(); // eat '{'
+                               if (need_layout) {
+                                       context.check_layout(os);
+                                       need_layout = false;
+                               }
+                               begin_inset(os, "OptArg\n");
+                               os << "status collapsed\n\n";
+                               parse_text_in_inset(p, os, FLAG_BRACE_LAST, 
outer, context);
+                               end_inset(os);
+                               eat_whitespace(p, os, context, false);
+                               ++reqargs;
+                       }
+               }
                parse_text(p, os, FLAG_END, outer, context);
                context.check_end_layout(os);
                if (parent_context.deeper_paragraph) {

Reply via email to