From: Jean-Marc Lasgouttes Date: Tue, 5 Aug 2003 21:46:51 +0000 (+0000) Subject: make nesting work in tex2lyx X-Git-Tag: 1.6.10~16325 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=1c601f24776e2f63b783eabd2fe043f19c34a511;p=features.git make nesting work in tex2lyx git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7509 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/tex2lyx/ChangeLog b/src/tex2lyx/ChangeLog index 0775b5c695..a116d446db 100644 --- a/src/tex2lyx/ChangeLog +++ b/src/tex2lyx/ChangeLog @@ -1,3 +1,15 @@ +2003-08-05 Jean-Marc Lasgouttes + + * 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 * text.C: update to use Context struct, and more notably: diff --git a/src/tex2lyx/context.C b/src/tex2lyx/context.C index 93431edda8..7bb967d111 100644 --- a/src/tex2lyx/context.C +++ b/src/tex2lyx/context.C @@ -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) diff --git a/src/tex2lyx/context.h b/src/tex2lyx/context.h index 2b5faa88aa..e7bdbbcd66 100644 --- a/src/tex2lyx/context.h +++ b/src/tex2lyx/context.h @@ -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 diff --git a/src/tex2lyx/preamble.C b/src/tex2lyx/preamble.C index 5bbb11e9a6..e0ed8fdf02 100644 --- a/src/tex2lyx/preamble.C +++ b/src/tex2lyx/preamble.C @@ -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 diff --git a/src/tex2lyx/test-structure.tex b/src/tex2lyx/test-structure.tex index 5d6e0fc879..d48767b953 100644 --- a/src/tex2lyx/test-structure.tex +++ b/src/tex2lyx/test-structure.tex @@ -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} diff --git a/src/tex2lyx/text.C b/src/tex2lyx/text.C index 28e53c184c..5c4b3fba6c 100644 --- a/src/tex2lyx/text.C +++ b/src/tex2lyx/text.C @@ -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".