From: Georg Baum Date: Sun, 12 Dec 2010 11:45:09 +0000 (+0000) Subject: Fix bug #5716. X-Git-Tag: 2.0.0~1407 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=e693a60c340ff8c9f18b7b25303f211e55d0442d;p=features.git Fix bug #5716. Since separators are not allowed by the current .lyx version written by tex2lyx, an empty note is used instead. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36838 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/tex2lyx/preamble.cpp b/src/tex2lyx/preamble.cpp index aabba0009c..fc76051a75 100644 --- a/src/tex2lyx/preamble.cpp +++ b/src/tex2lyx/preamble.cpp @@ -489,7 +489,7 @@ void end_preamble(ostream & os, TextClass const & /*textclass*/) // output the LyX file settings os << "#LyX file created by tex2lyx " << PACKAGE_VERSION << "\n" - << "\\lyxformat 264\n" + << "\\lyxformat " << LYX_FORMAT << '\n' << "\\begin_document\n" << "\\begin_header\n" << "\\textclass " << h_textclass << "\n"; diff --git a/src/tex2lyx/test/test-structure.tex b/src/tex2lyx/test/test-structure.tex index 35a6c0ff5a..69a49351f7 100644 --- a/src/tex2lyx/test/test-structure.tex +++ b/src/tex2lyx/test/test-structure.tex @@ -91,6 +91,15 @@ We can also nest enumerations \end{enumerate} \item Item2 \end{enumerate} +\begin{enumerate} +\item Item1 (appears as Item3 with bug 5716) + +Normal paragraph in Item1 + +\begin{enumerate} +\item Item1.a +\end{enumerate} +\end{enumerate} Let's see what happens when normal paragraphs are inserted in lists: diff --git a/src/tex2lyx/tex2lyx.h b/src/tex2lyx/tex2lyx.h index 52cf2c6ffe..0d7444319f 100644 --- a/src/tex2lyx/tex2lyx.h +++ b/src/tex2lyx/tex2lyx.h @@ -113,6 +113,8 @@ extern CommandMap known_environments; extern CommandMap known_math_environments; /// extern bool noweb_mode; +/// LyX format that is created by tex2lyx +int const LYX_FORMAT = 264; /// path of the master .tex file extern std::string getMasterFilePath(); diff --git a/src/tex2lyx/text.cpp b/src/tex2lyx/text.cpp index 7473091c51..632be575d1 100644 --- a/src/tex2lyx/text.cpp +++ b/src/tex2lyx/text.cpp @@ -715,7 +715,7 @@ void parse_unknown_environment(Parser & p, string const & name, ostream & os, void parse_environment(Parser & p, ostream & os, bool outer, - Context & parent_context) + string & last_env, Context & parent_context) { Layout const * newlayout; string const name = p.getArg('{', '}'); @@ -862,6 +862,28 @@ void parse_environment(Parser & p, ostream & os, bool outer, context.need_end_deeper = true; } parent_context.check_end_layout(os); + if (last_env == name) { + // we need to output a separator since LyX would export + // the two environments as one otherwise (bug 5716) + docstring const sep = from_ascii("--Separator--"); + TeX2LyXDocClass const & textclass(parent_context.textclass); + if (LYX_FORMAT >= 273 && textclass.hasLayout(sep)) { + Context newcontext(parent_context); + newcontext.layout = &(textclass[sep]); + newcontext.check_layout(os); + newcontext.check_end_layout(os); + } else { + parent_context.check_layout(os); + begin_inset(os, "Note Note\n"); + os << "status closed\n"; + Context newcontext(true, textclass, + &(textclass.defaultLayout())); + newcontext.check_layout(os); + newcontext.check_end_layout(os); + end_inset(os); + parent_context.check_end_layout(os); + } + } switch (context.layout->latextype) { case LATEX_LIST_ENVIRONMENT: context.add_par_extra_stuff("\\labelwidthstring " @@ -936,6 +958,7 @@ void parse_environment(Parser & p, ostream & os, bool outer, parse_unknown_environment(p, name, os, FLAG_END, outer, parent_context); + last_env = name; active_environments.pop_back(); } @@ -1145,6 +1168,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, string bibliographystyle; bool const use_natbib = used_packages.find("natbib") != used_packages.end(); bool const use_jurabib = used_packages.find("jurabib") != used_packages.end(); + string last_env; while (p.good()) { Token const & t = p.get_token(); @@ -1173,6 +1197,12 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, if (t.character() == '}' && (flags & FLAG_BRACE_LAST)) return; + // If there is anything between \end{env} and \begin{env} we + // don't need to output a separator. + if (t.cat() != catSpace && t.cat() != catNewline && + t.asInput() != "\\begin") + last_env = ""; + // // cat codes // @@ -1417,7 +1447,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, } else if (t.cs() == "begin") - parse_environment(p, os, outer, context); + parse_environment(p, os, outer, last_env, context); else if (t.cs() == "end") { if (flags & FLAG_END) {