From c4b38fc30e4b6fc9729adb6c5cbdd9658622a490 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 12 Feb 2003 13:21:32 +0000 Subject: [PATCH] ... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6121 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/tex2lyx/tex2lyx.C | 76 +++++++++++++++++++++++++++++++++-------- src/tex2lyx/texparser.C | 4 +-- 2 files changed, 64 insertions(+), 16 deletions(-) diff --git a/src/tex2lyx/tex2lyx.C b/src/tex2lyx/tex2lyx.C index da1fc118a1..2e9cc232bc 100644 --- a/src/tex2lyx/tex2lyx.C +++ b/src/tex2lyx/tex2lyx.C @@ -169,6 +169,7 @@ bool is_math_env(string const & name) bool is_heading(string const & name) { return + name == "caption" || name == "title" || name == "author" || name == "paragraph" || @@ -183,6 +184,15 @@ bool is_heading(string const & name) } +bool is_latex_command(string const & name) +{ + return + name == "label" || + name == "index" || + name == "printindex"; +} + + void begin_inset(ostream & os, string const & name) { os << "\n\\begin_inset " << name; @@ -259,6 +269,13 @@ void handle_package(string const & name, string const & options) } +void handle_table(Parser & p, ostream & os) +{ + // \begin{table} has been read + //parse(end +} + + string wrap(string const & cmd, string const & str) { return OPEN + cmd + ' ' + str + CLOSE; @@ -295,8 +312,7 @@ void end_preamble(ostream & os) << "\\papercolumns " << h_papercolumns << "\n" << "\\papersides " << h_papersides << "\n" << "\\paperpagestyle " << h_paperpagestyle << "\n" - << "\\tracking_changes " << h_tracking_changes << "\n" - << h_preamble.str() << "\n"; + << "\\tracking_changes " << h_tracking_changes << "\n"; } @@ -475,10 +491,15 @@ void parse(Parser & p, ostream & os, unsigned flags, mode_type mode) string const body = p.verbatimItem(); // only non-lyxspecific stuff if (name != "noun" && name != "tabularnewline") { - h_preamble << "\\" << t.cs() << "{" << name << "}"; + ostream & out = in_preamble ? h_preamble : os; + if (!in_preamble) + begin_inset(os, "FormulaMacro\n"); + out << "\\" << t.cs() << "{" << name << "}"; if (opts.size()) - h_preamble << "[" << opts << "]"; - h_preamble << "{" << body << "}\n"; + out << "[" << opts << "]"; + out << "{" << body << "}"; + if (!in_preamble) + end_inset(os); } } @@ -505,15 +526,27 @@ void parse(Parser & p, ostream & os, unsigned flags, mode_type mode) else if (t.cs() == "begin") { string const name = p.getArg('{', '}'); active_environments.push(name); - if (name == "document") + if (name == "document") { end_preamble(os); - else if (name == "abstract") + parse(p, os, FLAG_END, mode); + } else if (name == "abstract") { handle_par(os); - else if (is_math_env(name)) + parse(p, os, FLAG_END, mode); + } else if (is_math_env(name)) { begin_inset(os, "Formula "); - else os << "\\begin{" << name << "}"; - parse(p, os, FLAG_END, mode); + parse(p, os, FLAG_END, MATH_MODE); + } else if (name == "table") { + handle_table(p, os); + parse(p, os, FLAG_END, mode); + } else if (name == "thebibliography") { + p.verbatimItem(); // swallow next arg + handle_table(p, os); + parse(p, os, FLAG_END, mode); + } else { + os << "\\begin{" << name << "}"; + parse(p, os, FLAG_END, mode); + } } else if (t.cs() == "end") { @@ -526,9 +559,14 @@ void parse(Parser & p, ostream & os, unsigned flags, mode_type mode) active_environments.pop(); if (name == "document" || name == "abstract") ; - else if (is_math_env(name)) + else if (name == "table") + ; + else if (name == "thebibliography") + ; + else if (is_math_env(name)) { end_inset(os); - else + os << "\\end{" << name << "}"; + } else os << "\\end{" << name << "}"; return; } @@ -638,14 +676,24 @@ void parse(Parser & p, ostream & os, unsigned flags, mode_type mode) os << "\n\\emph default\n"; } - else if (t.cs() == "index") { + else if (is_latex_command(t.cs()) && mode == TEXT_MODE) { begin_inset(os, "LatexCommand "); + os << '\\' << t.cs() << '{'; parse(p, os, FLAG_ITEM, TEXT_MODE); + os << '}'; end_inset(os); } + else if (t.cs() == "bibitem") { + os << "\n\\layout Bibliography\n\\bibitem "; + string opt = p.getArg('[',']'); + if (opt.size()) + os << '[' << opt << ']'; + os << '{' << p.getArg('{','}') << '}' << "\n\n"; + } + else - (in_preamble ? h_preamble : os) << '\\' << t.asInput(); + (in_preamble ? h_preamble : os) << t.asInput(); if (flags & FLAG_LEAVE) { flags &= ~FLAG_LEAVE; diff --git a/src/tex2lyx/texparser.C b/src/tex2lyx/texparser.C index aa3bff8639..3226a83039 100644 --- a/src/tex2lyx/texparser.C +++ b/src/tex2lyx/texparser.C @@ -97,7 +97,7 @@ string Token::asString() const string Token::asInput() const { - return cs_.size() ? cs_ + ' ' : string(1, char_); + return char_ ? string(1, char_) : '\\' + cs_ + ' '; } @@ -311,7 +311,7 @@ string Parser::verbatimItem() res += '{' + verbatimItem() + '}'; } else - res += t.asString(); + res += t.asInput(); } } return res; -- 2.39.5