]> git.lyx.org Git - lyx.git/commitdiff
Fix bug #7468 (at least for standard environments).
authorGeorg Baum <georg.baum@post.rwth-aachen.de>
Sun, 16 Oct 2011 19:57:10 +0000 (19:57 +0000)
committerGeorg Baum <georg.baum@post.rwth-aachen.de>
Sun, 16 Oct 2011 19:57:10 +0000 (19:57 +0000)
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.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39871 a592a061-630c-0410-9148-cb99ea01b6c8

src/tex2lyx/text.cpp

index 27625c0df250d47037f2e57e5e0ddf08cd7cd0a4..2c4aac4059884bb2667510f823b60beb7f2c4158 100644 (file)
@@ -683,7 +683,7 @@ void parse_arguments(string const & command,
                        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 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                        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) {