git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6121 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-02-12 13:21:32 +00:00
parent 8a5d04fd84
commit c4b38fc30e
2 changed files with 64 additions and 16 deletions

View File

@ -169,6 +169,7 @@ bool is_math_env(string const & name)
bool is_heading(string const & name) bool is_heading(string const & name)
{ {
return return
name == "caption" ||
name == "title" || name == "title" ||
name == "author" || name == "author" ||
name == "paragraph" || 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) void begin_inset(ostream & os, string const & name)
{ {
os << "\n\\begin_inset " << 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) string wrap(string const & cmd, string const & str)
{ {
return OPEN + cmd + ' ' + str + CLOSE; return OPEN + cmd + ' ' + str + CLOSE;
@ -295,8 +312,7 @@ void end_preamble(ostream & os)
<< "\\papercolumns " << h_papercolumns << "\n" << "\\papercolumns " << h_papercolumns << "\n"
<< "\\papersides " << h_papersides << "\n" << "\\papersides " << h_papersides << "\n"
<< "\\paperpagestyle " << h_paperpagestyle << "\n" << "\\paperpagestyle " << h_paperpagestyle << "\n"
<< "\\tracking_changes " << h_tracking_changes << "\n" << "\\tracking_changes " << h_tracking_changes << "\n";
<< h_preamble.str() << "\n";
} }
@ -475,10 +491,15 @@ void parse(Parser & p, ostream & os, unsigned flags, mode_type mode)
string const body = p.verbatimItem(); string const body = p.verbatimItem();
// only non-lyxspecific stuff // only non-lyxspecific stuff
if (name != "noun" && name != "tabularnewline") { 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()) if (opts.size())
h_preamble << "[" << opts << "]"; out << "[" << opts << "]";
h_preamble << "{" << body << "}\n"; 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") { else if (t.cs() == "begin") {
string const name = p.getArg('{', '}'); string const name = p.getArg('{', '}');
active_environments.push(name); active_environments.push(name);
if (name == "document") if (name == "document") {
end_preamble(os); end_preamble(os);
else if (name == "abstract") parse(p, os, FLAG_END, mode);
} else if (name == "abstract") {
handle_par(os); 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 "); begin_inset(os, "Formula ");
else
os << "\\begin{" << name << "}"; 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") { else if (t.cs() == "end") {
@ -526,9 +559,14 @@ void parse(Parser & p, ostream & os, unsigned flags, mode_type mode)
active_environments.pop(); active_environments.pop();
if (name == "document" || name == "abstract") 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); end_inset(os);
else os << "\\end{" << name << "}";
} else
os << "\\end{" << name << "}"; os << "\\end{" << name << "}";
return; return;
} }
@ -638,14 +676,24 @@ void parse(Parser & p, ostream & os, unsigned flags, mode_type mode)
os << "\n\\emph default\n"; os << "\n\\emph default\n";
} }
else if (t.cs() == "index") { else if (is_latex_command(t.cs()) && mode == TEXT_MODE) {
begin_inset(os, "LatexCommand "); begin_inset(os, "LatexCommand ");
os << '\\' << t.cs() << '{';
parse(p, os, FLAG_ITEM, TEXT_MODE); parse(p, os, FLAG_ITEM, TEXT_MODE);
os << '}';
end_inset(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 else
(in_preamble ? h_preamble : os) << '\\' << t.asInput(); (in_preamble ? h_preamble : os) << t.asInput();
if (flags & FLAG_LEAVE) { if (flags & FLAG_LEAVE) {
flags &= ~FLAG_LEAVE; flags &= ~FLAG_LEAVE;

View File

@ -97,7 +97,7 @@ string Token::asString() const
string Token::asInput() 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() + '}'; res += '{' + verbatimItem() + '}';
} }
else else
res += t.asString(); res += t.asInput();
} }
} }
return res; return res;