X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftex2lyx%2Ftext.cpp;h=e083e39ec8a147e8104186f1e8167e3e31103722;hb=d09f87c3ca895e53ff77ca47918778e257826806;hp=e57784fc0782f7963716993b14b0be2076528ef1;hpb=05446b232f7716fecdea26af61b3fa1de0274c4d;p=lyx.git diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index e57784fc07..e083e39ec8 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -1118,16 +1118,35 @@ void parse_outer_box(Parser & p, ostream & os, unsigned flags, bool outer, } -void parse_listings(Parser & p, ostream & os, Context & parent_context) +void parse_listings(Parser & p, ostream & os, Context & parent_context, bool in_line) { parent_context.check_layout(os); begin_inset(os, "listings\n"); - os << "inline false\n" - << "status collapsed\n"; + if (p.hasOpt()) { + // there can be a [] pair inside the argument for the language + string arg = p.getArg('[', ']'); + if (arg.find("language={[") != string::npos) { + char start = p.next_token().character(); + arg += ']'; + arg += start; + arg += p.getArg(start, ']'); + } + os << "lstparams " << '"' << arg << '"' << '\n'; + } + if (in_line) + os << "inline true\n"; + else + os << "inline false\n"; + os << "status collapsed\n"; Context context(true, parent_context.textclass); context.layout = &parent_context.textclass.plainLayout(); - context.check_layout(os); - string const s = p.verbatimEnvironment("lstlisting"); + string s; + if (in_line) { + s = p.plainCommand('!', '!', "lstinline"); + context.new_paragraph(os); + context.check_layout(os); + } else + s = p.plainEnvironment("lstlisting"); for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) { if (*it == '\\') os << "\n\\backslash\n"; @@ -1267,7 +1286,7 @@ void parse_environment(Parser & p, ostream & os, bool outer, // we must make sure that the next item gets a \begin_layout. parent_context.new_paragraph(os); p.skip_spaces(); - preamble.registerAutomaticallyLoadedPackage("rotfloat"); + preamble.registerAutomaticallyLoadedPackage("rotfloat"); } else if (name == "wrapfigure" || name == "wraptable") { @@ -1300,7 +1319,7 @@ void parse_environment(Parser & p, ostream & os, bool outer, // we must make sure that the next item gets a \begin_layout. parent_context.new_paragraph(os); p.skip_spaces(); - preamble.registerAutomaticallyLoadedPackage("wrapfig"); + preamble.registerAutomaticallyLoadedPackage("wrapfig"); } else if (name == "minipage") { @@ -1344,24 +1363,25 @@ void parse_environment(Parser & p, ostream & os, bool outer, } else if (name == "verbatim") { - eat_whitespace(p, os, parent_context, false); - os << "\n\\begin_layout Verbatim\n"; - string const s = p.verbatimEnvironment("verbatim"); + os << "\n\\end_layout\n\n\\begin_layout Verbatim\n"; + string const s = p.plainEnvironment("verbatim"); string::const_iterator it2 = s.begin(); for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) { - if (*it == '\n') { + if (*it == '\\') + os << "\\backslash "; + else if (*it == '\n') { it2 = it + 1; // avoid adding an empty paragraph at the end - // if there are 2 consecutive spaces at the end ignore it + // FIXME: if there are 2 consecutive spaces at the end ignore it // because LyX will re-add a \n + // This hack must be removed once bug 8049 is fixed! if ((it + 1 != et) && (it + 2 != et || *it2 != '\n')) os << "\n\\end_layout\n\\begin_layout Verbatim\n"; - } else + } else os << *it; } os << "\n\\end_layout\n\n"; p.skip_spaces(); - skip_braces(p); // eat {} that might by set by LyX behind comments // reset to Standard layout os << "\n\\begin_layout Standard\n"; } @@ -1386,14 +1406,9 @@ void parse_environment(Parser & p, ostream & os, bool outer, else if (name == "lstlisting") { eat_whitespace(p, os, parent_context, false); - // FIXME handle listings with parameters - // If this is added, don't forgot to handle the - // automatic color package loading - if (p.hasOpt()) - parse_unknown_environment(p, name, os, FLAG_END, - outer, parent_context); - else - parse_listings(p, os, parent_context); + // FIXME handle the automatic color package loading + // uwestoehr asks: In what case color is loaded? + parse_listings(p, os, parent_context, false); p.skip_spaces(); } @@ -2781,6 +2796,11 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, end_inset(os); } + else if (t.cs() == "lstinline") { + p.skip_spaces(); + parse_listings(p, os, context, true); + } + else if (t.cs() == "ensuremath") { p.skip_spaces(); context.check_layout(os); @@ -3201,12 +3221,18 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, btprint = key; } - else if (t.cs() == "index") { + else if (t.cs() == "index" || + (t.cs() == "sindex" && preamble.use_indices() == "true")) { context.check_layout(os); - begin_inset(os, "Index idx\n"); - os << "status collapsed\n"; + string const arg = (t.cs() == "sindex" && p.hasOpt()) ? + p.getArg('[', ']') : ""; + string const kind = arg.empty() ? "idx" : arg; + begin_inset(os, "Index "); + os << kind << "\nstatus collapsed\n"; parse_text_in_inset(p, os, FLAG_ITEM, false, context, "Index"); end_inset(os); + if (kind != "idx") + preamble.registerAutomaticallyLoadedPackage("splitidx"); } else if (t.cs() == "nomenclature") {