make nesting work in tex2lyx

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7509 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jean-Marc Lasgouttes 2003-08-05 21:46:51 +00:00
parent 9a747c4130
commit 1c601f2477
6 changed files with 76 additions and 53 deletions

View 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:

View File

@ -24,39 +24,14 @@ Context::Context(bool need_layout_,
}
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)
{
if (need_layout) {
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);
check_end_layout(os);
os << "\n\\begin_layout " << layout->name() << "\n\n";
need_end_layout = true;
need_layout=false;
need_end_layout = true;
if (!extra_stuff.empty()) {
os << extra_stuff;
extra_stuff.erase();
@ -65,9 +40,43 @@ void Context::check_layout(ostream & os)
}
void Context::check_end_layout(ostream & os)
{
if (need_end_layout) {
os << "\n\\end_layout\n";
need_end_layout = false;
}
}
void Context::check_deeper(ostream & os)
{
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;
} 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)

View 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

View 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

View 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}

View 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".