]> git.lyx.org Git - features.git/commitdiff
Fix bug #5716.
authorGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 12 Dec 2010 11:45:09 +0000 (11:45 +0000)
committerGeorg Baum <Georg.Baum@post.rwth-aachen.de>
Sun, 12 Dec 2010 11:45:09 +0000 (11:45 +0000)
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

src/tex2lyx/preamble.cpp
src/tex2lyx/test/test-structure.tex
src/tex2lyx/tex2lyx.h
src/tex2lyx/text.cpp

index aabba0009c72b0c2ab06a261c0ea4aa8e473ac1b..fc76051a75f087f3daeb75a2edfbe7746d0a5e5e 100644 (file)
@@ -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";
index 35a6c0ff5a4dd8877fc5e4fa3c2ca2e787d653d9..69a49351f70095d3f30304a8089e67c198444a48 100644 (file)
@@ -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:
 
index 52cf2c6ffebd53d388079be26b5e2817612d2215..0d7444319f00af718892becce5b9415c87f9dcba 100644 (file)
@@ -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();
index 7473091c51ddb3e768052a024a9ea1ae6a855acc..632be575d13b14cf4bb6c767a398dbd6aef1156c 100644 (file)
@@ -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) {