From: Jean-Marc Lasgouttes Date: Mon, 28 Jul 2003 14:06:04 +0000 (+0000) Subject: * text.C (parse_text): read environment from layout file too. Now, X-Git-Tag: 1.6.10~16414 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=34215d69bc293059e10357424ba7e3e5d344592c;p=features.git * text.C (parse_text): read environment from layout file too. Now, all layout entries are supported (but many hacks remain); note that the nesting support is broken and will have to be completely redone * table.C (handle_tabular): make the output more similar to LyX and fix a little * text.C (output_layout): fix handling of optional argument (parse_text): small tweaks to make output format closer to lyx format; support \tableofcontents; fix/improve support for various special characters git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7417 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/tex2lyx/ChangeLog b/src/tex2lyx/ChangeLog index b3cbeec33d..81c7d1614f 100644 --- a/src/tex2lyx/ChangeLog +++ b/src/tex2lyx/ChangeLog @@ -1,7 +1,15 @@ -2003-07-27 Jean-Marc Lasgouttes +2003-07-28 Jean-Marc Lasgouttes + + * text.C (parse_text): read environment from layout file too. Now, + all layout entries are supported (but many hacks remain) + + * table.C (handle_tabular): make the output more similar to LyX + and fix a little * text.C (output_layout): fix handling of optional argument - (parse_text): small tweaks to make output format closer to lyx format + (parse_text): small tweaks to make output format closer to lyx + format; support \tableofcontents; fix/improve support for various + special characters 2003-07-27 Angus Leeming diff --git a/src/tex2lyx/table.C b/src/tex2lyx/table.C index 773741005b..0d00c8e4fb 100644 --- a/src/tex2lyx/table.C +++ b/src/tex2lyx/table.C @@ -415,6 +415,9 @@ void handle_tabular(Parser & p, ostream & os, } else { // FLAG_END is a hack, we need to read all of it + cellinfo[row][col].leftline = colinfo[col].leftline; + cellinfo[row][col].rightline = colinfo[col].rightline; + cellinfo[row][col].align = colinfo[col].align; cellinfo[row][col].content = parse_text(p, FLAG_END, false, textclass); } } @@ -435,21 +438,23 @@ void handle_tabular(Parser & p, ostream & os, //cerr << "// output what we have\n"; // output what we have - os << "\n" << "\n"; //cerr << "// after header\n"; for (size_t col = 0; col < colinfo.size(); ++col) { - os << "\n"; } //cerr << "// after cols\n"; @@ -466,27 +471,28 @@ void handle_tabular(Parser & p, ostream & os, os << "" + os << " usebox=\"none\"" + << ">" << "\n\\begin_inset Text" << "\n\n\\layout Standard\n\n" << cell.content - << "\n\\end_inset\n\n" + << "\n\\end_inset \n" << "\n"; } os << "\n"; diff --git a/src/tex2lyx/text.C b/src/tex2lyx/text.C index 7d15c4304c..22a0c570b0 100644 --- a/src/tex2lyx/text.C +++ b/src/tex2lyx/text.C @@ -103,7 +103,7 @@ void handle_ert(ostream & os, string const & s) os << "\nstatus Collapsed\n\n\\layout Standard\n\n"; for (string::const_iterator it = s.begin(), et = s.end(); it != et; ++it) { if (*it == '\\') - os << "\n\\backslash\n"; + os << "\n\\backslash \n"; else os << *it; } @@ -250,8 +250,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, if (t.character() == '~') { if (active_environment() == "lyxcode") os << ' '; - else - os << "\\SpecialChar ~\n"; + else + os << "\\InsetSpace ~\n"; } else os << t.character(); } @@ -288,11 +288,6 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, // control sequences // - else if (t.cs() == "ldots") { - skip_braces(p); - os << "\n\\SpecialChar \\ldots{}\n"; - } - else if (t.cs() == "(") { begin_inset(os, "Formula"); os << " \\("; @@ -340,25 +335,32 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, handle_par(os); parse_text(p, os, FLAG_END, outer, textclass); - } else if (name == "enumerate" || name == "itemize" - || name == "lyxlist") { - size_t const n = active_environments.size(); - string const s = active_environments[n - 2]; - bool const deeper = s == "enumerate" || s == "itemize" - || s == "lyxlist"; - if (deeper) - os << "\n\\begin_deeper"; - os << "\n\\layout " << cap(name) << "\n\n"; - if (name == "lyxlist") + // The single '=' is meant here. + } else if ((layout_ptr = findLayout(textclass, t.cs())).get() && + layout_ptr->isEnvironment()) { + size_t const n = active_environments.size(); + string const s = active_environments[n - 2]; + bool const deeper = s == "enumerate" || s == "itemize" + || s == "lyxlist"; + if (deeper) + os << "\n\\begin_deeper"; + os << "\n\\layout " << layout_ptr->name() + << "\n\n"; + switch (layout_ptr->latextype) { + case LATEX_LIST_ENVIRONMENT: + os << "\\labelwidthstring " + << p.verbatim_item() << '\n'; + break; + case LATEX_BIB_ENVIRONMENT: p.verbatim_item(); // swallow next arg + break; + default: + break; + } parse_text(p, os, FLAG_END, outer, textclass); - if (deeper) - os << "\n\\end_deeper\n"; + if (deeper) + os << "\n\\end_deeper\n"; handle_par(os); - } else if (name == "thebibliography") { - p.verbatim_item(); // swallow next arg - parse_text(p, os, FLAG_END, outer, textclass); - os << "\n\\layout Bibliography\n\n"; } else { handle_par(os); parse_text(p, os, FLAG_END, outer, textclass); @@ -388,7 +390,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, s = parse_text(p, FLAG_BRACK_LAST, outer, textclass); } handle_par(os); - os << s << ' '; + if (s.size()) + os << s << ' '; } else if (t.cs() == "def") { @@ -463,8 +466,13 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, else if (t.cs() == "makeindex" || t.cs() == "maketitle") skip_braces(p); // swallow this - else if (t.cs() == "tableofcontents") + else if (t.cs() == "tableofcontents") { + begin_inset(os, "LatexCommand "); + os << '\\' << t.cs() << "{}\n"; + end_inset(os); skip_braces(p); // swallow this + } + else if (t.cs() == "textrm") { os << "\n\\family roman \n"; @@ -517,7 +525,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, else if (t.cs() == "bibitem") { os << "\n\\layout Bibliography\n\\bibitem "; os << p.getOpt(); - os << '{' << p.verbatim_item() << '}' << "\n\n"; + os << '{' << p.verbatim_item() << '}' << "\n"; } else if (is_known(t.cs(), known_latex_commands)) { @@ -553,6 +561,11 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, skip_braces(p); // eat {} } + else if (t.cs() == "ldots") { + skip_braces(p); + os << "\\SpecialChar \\ldots{}\n"; + } + else if (t.cs() == "lyxarrow") { os << "\\SpecialChar \\menuseparator\n"; skip_braces(p); @@ -563,11 +576,14 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, skip_braces(p); } - else if (t.cs() == "@") { - os << "\\SpecialChar \\@"; - skip_braces(p); + else if (t.cs() == "@" && p.next_token().asInput() == ".") { + os << "\\SpecialChar \\@.\n"; + p.get_token(); } + else if (t.cs() == "-") + os << "\\SpecialChar \\-\n"; + else if (t.cs() == "textasciitilde") { os << '~'; skip_braces(p); @@ -579,12 +595,13 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, } else if (t.cs() == "textbackslash") { - os << "\n\\backslash\n"; + os << "\n\\backslash \n"; skip_braces(p); } - else if (t.cs() == "_" || t.cs() == "&" || t.cs() == "#" || t.cs() == "$" - || t.cs() == "{" || t.cs() == "}" || t.cs() == "%") + else if (t.cs() == "_" || t.cs() == "&" || t.cs() == "#" + || t.cs() == "$" || t.cs() == "{" || t.cs() == "}" + || t.cs() == "%") os << t.cs(); else if (t.cs() == "char") { @@ -626,11 +643,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer, else if (t.cs() == "i" || t.cs() == "j") os << "\\" << t.cs() << ' '; - else if (t.cs() == "-") - os << "\\SpecialChar \\-\n"; - else if (t.cs() == "\\") - os << "\n\\newline\n"; + os << "\n\\newline \n"; else if (t.cs() == "input") handle_ert(os, "\\input{" + p.verbatim_item() + "}\n");