]> git.lyx.org Git - features.git/commitdiff
make nesting work in tex2lyx
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 5 Aug 2003 21:46:51 +0000 (21:46 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 5 Aug 2003 21:46:51 +0000 (21:46 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7509 a592a061-630c-0410-9148-cb99ea01b6c8

src/tex2lyx/ChangeLog
src/tex2lyx/context.C
src/tex2lyx/context.h
src/tex2lyx/preamble.C
src/tex2lyx/test-structure.tex
src/tex2lyx/text.C

index 0775b5c69598890e4dd22e0d03f4e4cb5c7347c4..a116d446db8e2b903cda3e2b862fc5d6773ec1d1 100644 (file)
@@ -1,3 +1,15 @@
+2003-08-05  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * text.C: some tweaks to make nesting work. What still does not
+       work is nesting a standard paragraph in a list.
+
+       * test-structure.tex: update a bit
+
+       * context.C (check_deeper, check_end_deeper): new methods to
+       handle the *_deeper stuff
+
+       * preamble.C (end_preamble): small tweaks
+
 2003-08-03  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
 
        * text.C: update to use Context struct, and more notably:
index 93431edda8a7ffedff54362c2f81696ba3fdb87d..7bb967d1113f5d8aeda62eab3a3564b48374178f 100644 (file)
@@ -24,50 +24,59 @@ Context::Context(bool need_layout_,
 }
 
 
+void Context::check_layout(ostream & os)
+{
+       if (need_layout) {
+               check_end_layout(os);
+               
+               os << "\n\\begin_layout " << layout->name() << "\n\n";
+               need_layout=false;
+               need_end_layout = true;
+               if (!extra_stuff.empty()) {
+                       os << extra_stuff;
+                       extra_stuff.erase();
+               }
+       }
+}
+
+
 void Context::check_end_layout(ostream & os) 
 {
        if (need_end_layout) {
                os << "\n\\end_layout\n";
                need_end_layout = false;
        }
-       if (need_end_deeper) {
-               os << "\n\\end_deeper\n";
-               need_end_deeper = false;
-       }
 }
 
 
-void Context::check_layout(ostream & os)
+void Context::check_deeper(ostream & os)
 {
-       if (need_layout) {
-               if (parent_layout->isEnvironment()) {
-                       if (need_end_deeper) {
+       if (parent_layout->isEnvironment()) {
+               if (need_end_deeper) {
                                // no need to have \end_deeper \begin_deeper
 // FIXME: This does not work because \par already calls check_end_layout
-                               need_end_deeper = false;
-                               check_end_layout(os);
-                       } else {
-                               check_end_layout(os);
-                               os << "\n\\begin_deeper\n";
-                               need_end_deeper = true;
-                       }
-               } else 
-                       check_end_layout(os);
-               
-               os << "\n\\begin_layout " << layout->name() << "\n\n";
-               need_end_layout = true;
-               need_layout=false;
-               if (!extra_stuff.empty()) {
-                       os << extra_stuff;
-                       extra_stuff.erase();
+                       need_end_deeper = false;
+               } else {
+                       os << "\n\\begin_deeper \n";
+                       need_end_deeper = true;
                }
+       } else
+               check_end_deeper(os);
+}
+
+
+void Context::check_end_deeper(ostream & os) 
+{
+       if (need_end_deeper) {
+               os << "\n\\end_deeper \n";
+               need_end_deeper = false;
        }
 }
 
 
 void Context::dump(ostream & os, string const & desc) const
 {
-       os << desc <<" [";
+       os << "\n" << desc <<" [";
        if (need_layout)
                os << "need_layout ";
        if (need_end_layout)
index 2b5faa88aa3c429c495d9adc6b0bf4b7e50edfdb..e7bdbbcd66a3b894c52745391016b8f6dee73519 100644 (file)
@@ -17,7 +17,14 @@ struct Context {
        // Output a \end_layout if needed
        void check_end_layout(std::ostream & os);
 
-       // dump content on standard error (for debugging purpose)
+       // Output a \begin_deeper if needed
+       void check_deeper(ostream & os);
+
+       // Output a \end_deeper if needed
+       void check_end_deeper(ostream & os);
+       
+       // dump content on stream (for debugging purpose), with
+       // description \c desc.
        void dump(std::ostream &, std::string const & desc = "context") const;
 
        // Do we need to output some \begin_layout command before the
index 5bbb11e9a62407b7947c4f6e0396fdc7289f1734..e0ed8fdf02c910a92ddc307111865f3783926743 100644 (file)
@@ -137,7 +137,7 @@ void handle_package(string const & name, string const & options)
 
 void end_preamble(ostream & os, LyXTextClass const & /*textclass*/)
 {
-       os << "# tex2lyx 0.1.0 created this file\n"
+       os << "#LyX file created by  tex2lyx 0.1.2 \n"
           << "\\lyxformat 225\n"
           << "\\textclass " << h_textclass << "\n"
           << "\\begin_preamble\n" << h_preamble.str() << "\n\\end_preamble\n";
@@ -166,7 +166,7 @@ void end_preamble(ostream & os, LyXTextClass const & /*textclass*/)
           << "\\papersides " << h_papersides << "\n"
           << "\\paperpagestyle " << h_paperpagestyle << "\n"
           << "\\tracking_changes " << h_tracking_changes << "\n"
-          << "\\end_header";
+          << "\\end_header\n";
 }
 
 } // anonymous namespace
index 5d6e0fc8795772be9341b7d945c6e44e018333ab..d48767b953e975bd1f257a5c06041b5c5c09eb58 100644 (file)
@@ -59,28 +59,29 @@ An environment
 \end{quotation}
 
 \begin{quotation}
-An environment
+Another environment
 
 \begin{quotation}
-and the one inside it
+With another one inside it (with same layout)
 
-actually with several paragraphs
+[this one even has several paragraphs!]
 \end{quotation}
 
 \end{quotation}
 
-We can also nest enumerations (does not work quite yet)
+We can also nest enumerations
 
 \begin{enumerate}
 \item Item1
 \begin{enumerate}
 \item Item1.a
-\item Item1.b
-\end{enumerate}
+
+\item Item1.b (there is  a paragraph break in front of this)
 \begin{itemize}
-\item Item1.*
-\item Item1.*
+\item Item1.b.*
+\item Item1.b.*
 \end{itemize}
+\end{enumerate}
 \item Item2
 \end{enumerate}
 
index 28e53c184c3134043f0d4dd17686343299748e88..5c4b3fba6ccb7f10b1c832424b398feefd237805 100644 (file)
@@ -160,10 +160,10 @@ void output_command_layout(ostream & os, Parser & p, bool outer,
                           Context & parent_context,
                           LyXLayout_ptr newlayout)
 {
-//     parent_context.dump(os, "#parent_context before output_command_layout");
        parent_context.check_end_layout(os);
        Context context(true, parent_context.textclass, newlayout,
                        parent_context.layout);
+       context.check_deeper(os);
        context.check_layout(os);
        if (context.layout->optionalargs > 0) {
                string s; 
@@ -176,16 +176,14 @@ void output_command_layout(ostream & os, Parser & p, bool outer,
                }
        }
        parse_text_snippet(p, os, FLAG_ITEM, outer, context);
-       context.check_end_layout(os);   
-//     context.dump(os, "#context after output_command_layout");
-//     parent_context.dump(os, "#parent_context after output_command_layout");
+       context.check_end_layout(os);
+       context.check_end_deeper(os);
 }
 
 
 void parse_environment(Parser & p, ostream & os, bool outer,
                       Context & parent_context)
 {
-//     parent_context.dump(os, "#parent_context before parse_environment");
        LyXLayout_ptr newlayout;
        string const name = p.getArg('{', '}');
        const bool is_starred = suffixIs(name, '*');
@@ -221,7 +219,6 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                Context context(true, parent_context.textclass, newlayout,
                                parent_context.layout);
                parent_context.check_end_layout(os);
-//             context.dump(os, "#context in parse_environment");
                switch (context.layout->latextype) {
                case  LATEX_LIST_ENVIRONMENT:
                        context.extra_stuff = "\\labelwidthstring "
@@ -233,10 +230,10 @@ void parse_environment(Parser & p, ostream & os, bool outer,
                default:
                        break;
                }
-               //context.check_layout(os);
+               context.check_deeper(os);
                parse_text(p, os, FLAG_END, outer, context);
-//             context.dump(os, "#context after parse_environment");
                context.check_end_layout(os);
+               context.check_end_deeper(os);
        } else {
                parent_context.check_layout(os);
                handle_ert(os, "\\begin{" + name + "}", parent_context);
@@ -342,10 +339,11 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
 
                else if (t.cat() == catNewline) {
                        if (p.next_token().cat() == catNewline) {
+                               // this should have been be done by
+                               // the parser already
+                               cerr << "what are we doing here?" << endl;
                                p.get_token();
                                context.need_layout = true;
-                               // this should be done by the parser already
-                               cerr << "what are we doing here?" << endl;
                        } else {
                                os << " "; // note the space
                        }
@@ -427,7 +425,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                                        cerr << "\\end{" + name + "} does not match \\begin{"
                                                + active_environment() + "}\n";
                                active_environments.pop_back();
-                               context.check_end_layout(os);
                                return;
                        }
                        p.error("found 'end' unexpectedly");
@@ -459,9 +456,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
                        p.skip_spaces();
                        context.check_end_layout(os);
                        context.need_layout = true;
-//                     if (p.next_token().cs() != "\\begin")
-//                             handle_par(os);
-                       //cerr << "next token: '" << p.next_token().cs() << "'\n";
                }
 
                // Must attempt to parse "Section*" before "Section".