- correct the conversion of InsetCommand
- code optimization
- support for format 253: nomenclature is now recognized

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@30093 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Uwe Stöhr 2009-06-14 02:16:51 +00:00
parent 6dad0a4cd7
commit 1e4def9460
4 changed files with 58 additions and 19 deletions

View File

@ -334,6 +334,14 @@ string Parser::getOpt()
} }
string Parser::getOptContent()
// the same as getOpt but without the brackets
{
string const res = getArg('[', ']');
return res.empty() ? string() : res;
}
string Parser::getFullParentheseArg() string Parser::getFullParentheseArg()
{ {
Arg arg = getFullArg('(', ')'); Arg arg = getFullArg('(', ')');

View File

@ -158,9 +158,13 @@ public:
*/ */
std::string getOpt(); std::string getOpt();
/*! /*!
* \returns getFullArg('(', ')') including the parentheses or the * \returns getFullArg('[', ']') including the parentheses or the
* empty string if there is no such argument. * empty string if there is no such argument.
*/ */
std::string getOptContent();
/*!
* the same as getOpt but without the brackets
*/
std::string getFullParentheseArg(); std::string getFullParentheseArg();
/*! /*!
* \returns the contents of the environment \p name. * \returns the contents of the environment \p name.

View File

@ -452,7 +452,7 @@ void handle_package(Parser &p, string const & name, string const & opts,
void end_preamble(ostream & os, TextClass const & /*textclass*/) void end_preamble(ostream & os, TextClass const & /*textclass*/)
{ {
os << "#LyX file created by tex2lyx " << PACKAGE_VERSION << "\n" os << "#LyX file created by tex2lyx " << PACKAGE_VERSION << "\n"
<< "\\lyxformat 252\n" << "\\lyxformat 253\n"
<< "\\begin_document\n" << "\\begin_document\n"
<< "\\begin_header\n" << "\\begin_header\n"
<< "\\textclass " << h_textclass << "\n"; << "\\textclass " << h_textclass << "\n";

View File

@ -354,12 +354,13 @@ void begin_inset(ostream & os, string const & name)
os << "\n\\begin_inset " << name; os << "\n\\begin_inset " << name;
} }
/*// use this voi when format 288 is supported
void begin_command_inset(ostream & os, string const & name, void begin_command_inset(ostream & os, string const & name,
string const & latexname) string const & latexname)
{ {
os << "\n\\begin_inset CommandInset " << name; os << "\n\\begin_inset CommandInset " << name;
os << "\nLatexCommand " << latexname << "\n"; os << "\nLatexCommand " << latexname << "\n";
} }*/
void end_inset(ostream & os) void end_inset(ostream & os)
@ -1464,7 +1465,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
else if (t.cs() == "bibitem") { else if (t.cs() == "bibitem") {
context.set_item(); context.set_item();
context.check_layout(os); context.check_layout(os);
begin_command_inset(os, "bibitem", "bibitem"); begin_inset(os, "LatexCommand ");
os << t.cs() << "\n";
os << p.getOpt(); os << p.getOpt();
os << "key " << '"' << p.verbatim_item() << '"' << "\n"; os << "key " << '"' << p.verbatim_item() << '"' << "\n";
end_inset(os); end_inset(os);
@ -1784,7 +1786,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
else if (t.cs() == "tableofcontents") { else if (t.cs() == "tableofcontents") {
p.skip_spaces(); p.skip_spaces();
context.check_layout(os); context.check_layout(os);
begin_command_inset(os, "toc", "tableofcontents"); begin_inset(os, "LatexCommand ");
os << t.cs() << "\n";
end_inset(os); end_inset(os);
skip_braces(p); // swallow this skip_braces(p); // swallow this
} }
@ -1922,7 +1925,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
else if (is_known(t.cs(), known_ref_commands)) { else if (is_known(t.cs(), known_ref_commands)) {
context.check_layout(os); context.check_layout(os);
begin_command_inset(os, "ref", t.cs()); begin_inset(os, "LatexCommand ");
os << t.cs() << "\n";
// lyx cannot handle newlines in a latex command // lyx cannot handle newlines in a latex command
// FIXME: Move the substitution into parser::getOpt()? // FIXME: Move the substitution into parser::getOpt()?
os << subst(p.getOpt(), "\n", " "); os << subst(p.getOpt(), "\n", " ");
@ -1978,7 +1982,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
before.erase(0, 1); before.erase(0, 1);
before.erase(before.length() - 1, 1); before.erase(before.length() - 1, 1);
} }
begin_command_inset(os, "citation", command); begin_inset(os, "LatexCommand ");
os << t.cs() << "\n";
os << "after " << '"' << after << '"' << "\n"; os << "after " << '"' << after << '"' << "\n";
os << "before " << '"' << before << '"' << "\n"; os << "before " << '"' << before << '"' << "\n";
os << "key " << '"' << p.verbatim_item() << '"' << "\n"; os << "key " << '"' << p.verbatim_item() << '"' << "\n";
@ -2022,7 +2027,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
before.erase(0, 1); before.erase(0, 1);
before.erase(before.length() - 1, 1); before.erase(before.length() - 1, 1);
} }
begin_command_inset(os, "citation", command); begin_inset(os, "LatexCommand ");
os << t.cs() << "\n";
os << "after " << '"' << after << '"' << "\n"; os << "after " << '"' << after << '"' << "\n";
os << "before " << '"' << before << '"' << "\n"; os << "before " << '"' << before << '"' << "\n";
os << "key " << '"' << citation << '"' << "\n"; os << "key " << '"' << citation << '"' << "\n";
@ -2032,12 +2038,9 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
else if (t.cs() == "cite") { else if (t.cs() == "cite") {
context.check_layout(os); context.check_layout(os);
// lyx cannot handle newlines in a latex command // lyx cannot handle newlines in a latex command
string after = subst(p.getOpt(), "\n", " "); string after = subst(p.getOptContent(), "\n", " ");
if (!after.empty()) { begin_inset(os, "LatexCommand ");
after.erase(0, 1); os << t.cs() << "\n";
after.erase(after.length() - 1, 1);
}
begin_command_inset(os, "citation", t.cs());
os << "after " << '"' << after << '"' << "\n"; os << "after " << '"' << after << '"' << "\n";
os << "key " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n"; os << "key " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
end_inset(os); end_inset(os);
@ -2046,15 +2049,29 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
else if (t.cs() == "index") { else if (t.cs() == "index") {
context.check_layout(os); context.check_layout(os);
begin_inset(os, "LatexCommand "); begin_inset(os, "LatexCommand ");
os << t.cs() << "\n";; os << t.cs() << "\n";
// lyx cannot handle newlines in a latex command // lyx cannot handle newlines in a latex command
os << "name " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n"; os << "name " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
end_inset(os); end_inset(os);
} }
else if (t.cs() == "nomenclature") {
context.check_layout(os);
begin_inset(os, "LatexCommand ");
os << t.cs() << "\n";
// lyx cannot handle newlines in a latex command
string prefix = subst(p.getOptContent(), "\n", " ");
if (!prefix.empty())
os << "prefix " << '"' << prefix << '"' << "\n";
os << "symbol " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
os << "description " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
end_inset(os);
}
else if (t.cs() == "label") { else if (t.cs() == "label") {
context.check_layout(os); context.check_layout(os);
begin_command_inset(os, t.cs(), t.cs()); begin_inset(os, "LatexCommand ");
os << t.cs() << "\n";
// lyx cannot handle newlines in a latex command // lyx cannot handle newlines in a latex command
os << "name " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n"; os << "name " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
end_inset(os); end_inset(os);
@ -2062,7 +2079,16 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
else if (t.cs() == "printindex") { else if (t.cs() == "printindex") {
context.check_layout(os); context.check_layout(os);
begin_command_inset(os, "index_print", t.cs()); begin_inset(os, "LatexCommand ");
os << t.cs() << "\n";
end_inset(os);
skip_braces(p);
}
else if (t.cs() == "printnomenclature") {
context.check_layout(os);
begin_inset(os, "LatexCommand ");
os << t.cs() << "\n";
end_inset(os); end_inset(os);
skip_braces(p); skip_braces(p);
} }
@ -2070,7 +2096,7 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
else if (t.cs() == "url") { else if (t.cs() == "url") {
context.check_layout(os); context.check_layout(os);
begin_inset(os, "LatexCommand "); begin_inset(os, "LatexCommand ");
os << t.cs() << "\n";; os << t.cs() << "\n";
// lyx cannot handle newlines in a latex command // lyx cannot handle newlines in a latex command
os << "target " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n"; os << "target " << '"' << subst(p.verbatim_item(), "\n", " ") << '"' << "\n";
end_inset(os); end_inset(os);
@ -2401,7 +2427,8 @@ void parse_text(Parser & p, ostream & os, unsigned flags, bool outer,
else if (t.cs() == "bibliography") { else if (t.cs() == "bibliography") {
context.check_layout(os); context.check_layout(os);
begin_command_inset(os, "bibtex", "bibtex"); begin_inset(os, "LatexCommand ");
os << "bibtex" << "\n";
os << "bibfiles " << '"' << p.verbatim_item() << '"' << "\n"; os << "bibfiles " << '"' << p.verbatim_item() << '"' << "\n";
// Do we have a bibliographystyle set? // Do we have a bibliographystyle set?
if (!bibliographystyle.empty()) if (!bibliographystyle.empty())