From d267511d42acfce007bbb2e54df0df352f351ae9 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sun, 16 Oct 2011 19:57:10 +0000 Subject: [PATCH] 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. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39871 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/tex2lyx/text.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 27625c0df2..2c4aac4059 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -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) {