diff --git a/src/tex2lyx/Parser.cpp b/src/tex2lyx/Parser.cpp index 06027e880a..290b7ba7b7 100644 --- a/src/tex2lyx/Parser.cpp +++ b/src/tex2lyx/Parser.cpp @@ -502,6 +502,28 @@ string const Parser::plainEnvironment(string const & name) } +string const Parser::plainCommand(char left, char right, string const & name) +{ + if (!good()) + return string(); + // ceck if first token is really the start character + Token tok = get_token(); + if (tok.character() != left) { + cerr << "first character does not match start character of command \\" << name << endl; + return string(); + } + ostringstream os; + for (Token t = get_token(); good(); t = get_token()) { + if (t.character() == right) { + return os.str(); + } else + os << t.asInput(); + } + cerr << "unexpected end of input" << endl; + return os.str(); +} + + void Parser::tokenize_one() { catInit(); diff --git a/src/tex2lyx/Parser.h b/src/tex2lyx/Parser.h index 2f4e26a587..3b852e1090 100644 --- a/src/tex2lyx/Parser.h +++ b/src/tex2lyx/Parser.h @@ -202,6 +202,13 @@ public: * This function is designed to parse verbatim environments. */ std::string const plainEnvironment(std::string const & name); + /* + * Basically the same as plainEnvironment(std::string const & name) but + * instead of \begin and \end commands the parsing is started/stopped + * at given characters. + * This function is designed to parse verbatim commands. + */ + std::string const plainCommand(char left, char right, std::string const & name); /*! * Returns the character of the current token and increments * the token position. diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 65f4e3ce49..e083e39ec8 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -1118,7 +1118,7 @@ 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"); @@ -1133,11 +1133,20 @@ void parse_listings(Parser & p, ostream & os, Context & parent_context) } os << "lstparams " << '"' << arg << '"' << '\n'; } - os << "inline false\n" - << "status collapsed\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(); - string const s = p.plainEnvironment("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"; @@ -1399,7 +1408,7 @@ void parse_environment(Parser & p, ostream & os, bool outer, eat_whitespace(p, os, parent_context, false); // FIXME handle the automatic color package loading // uwestoehr asks: In what case color is loaded? - parse_listings(p, os, parent_context); + parse_listings(p, os, parent_context, false); p.skip_spaces(); } @@ -2787,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);