some small improvements

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6306 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-02-28 13:37:43 +00:00
parent f566e7c604
commit 9887588cfb
3 changed files with 126 additions and 31 deletions

View File

@ -75,11 +75,11 @@ const char * known_languages[] = { "austrian", "babel", "bahasa", "basque",
char const * known_fontsizes[] = { "10pt", "11pt", "12pt", 0 }; char const * known_fontsizes[] = { "10pt", "11pt", "12pt", 0 };
char const * known_headings[] = { "caption", "title", "author", char const * known_headings[] = { "caption", "title", "author", "date",
"paragraph", "chapter", "section", "subsection", "subsubsection", 0 }; "paragraph", "chapter", "section", "subsection", "subsubsection", 0 };
char const * known_math_envs[] = { "equation", "eqnarray", "eqnarray*", char const * known_math_envs[] = { "equation", "equation*",
"align", "align*", 0}; "eqnarray", "eqnarray*", "align", "align*", 0};
char const * known_latex_commands[] = { "ref", "cite", "label", "index", char const * known_latex_commands[] = { "ref", "cite", "label", "index",
"printindex", 0 }; "printindex", 0 };
@ -217,7 +217,7 @@ void begin_inset(ostream & os, string const & name)
void end_inset(ostream & os) void end_inset(ostream & os)
{ {
os << "\n\\end_inset\n"; os << "\n\\end_inset\n\n";
} }
@ -241,6 +241,16 @@ void handle_ert(ostream & os, string const & s)
} }
void handle_tex(ostream & os, string const & s)
{
//os << "handle_tex(" << s << ")\n";
if (in_preamble)
h_preamble << s;
else
handle_ert(os, s);
}
void handle_par(ostream & os) void handle_par(ostream & os)
{ {
if (active_environments.empty()) if (active_environments.empty())
@ -353,7 +363,8 @@ void handle_tabular(Parser & p, ostream & os, mode_type mode)
<< ">"; << ">";
begin_inset(os, "Text"); begin_inset(os, "Text");
os << "\n\n\\layout Standard\n\n"; os << "\n\n\\layout Standard\n\n";
os << parts.back(); if (parts.size())
os << parts.back();
end_inset(os); end_inset(os);
os << "</cell>\n"; os << "</cell>\n";
} }
@ -525,7 +536,7 @@ void parse(Parser & p, ostream & os, unsigned flags, mode_type mode)
if (mode == MATH_MODE) if (mode == MATH_MODE)
os << '{'; os << '{';
else else
handle_ert(os, "{"); handle_tex(os, "{");
} }
else if (t.cat() == catEnd) { else if (t.cat() == catEnd) {
@ -534,7 +545,7 @@ void parse(Parser & p, ostream & os, unsigned flags, mode_type mode)
if (mode == MATH_MODE) if (mode == MATH_MODE)
os << '}'; os << '}';
else else
handle_ert(os, "}"); handle_tex(os, "}");
} }
else if (t.cat() == catAlign) { else if (t.cat() == catAlign) {
@ -584,24 +595,44 @@ void parse(Parser & p, ostream & os, unsigned flags, mode_type mode)
else if (t.cs() == "lyxlock") else if (t.cs() == "lyxlock")
; // ignored ; // ignored
else if (t.cs() == "newcommand" || t.cs() == "providecommand") { else if (t.cs() == "makeatletter") {
p.setCatCode('@', catLetter);
handle_tex(os, "\\makeatletter\n");
}
else if (t.cs() == "makeatother") {
p.setCatCode('@', catOther);
handle_tex(os, "\\makeatother\n");
}
else if (t.cs() == "newcommand" || t.cs() == "renewcommand"
|| t.cs() == "providecommand") {
string const name = p.verbatimItem(); string const name = p.verbatimItem();
string const opts = p.getArg('[', ']'); string const opts = p.getOpt();
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 ") {
ostream & out = in_preamble ? h_preamble : os; ostream & out = in_preamble ? h_preamble : os;
if (!in_preamble) if (!in_preamble)
begin_inset(os, "FormulaMacro\n"); begin_inset(os, "FormulaMacro\n");
out << "\\" << t.cs() << "{" << name << "}"; out << "\\" << t.cs() << "{" << name << "}"
if (opts.size()) << opts << "{" << body << "}\n";
out << "[" << opts << "]";
out << "{" << body << "}";
if (!in_preamble) if (!in_preamble)
end_inset(os); end_inset(os);
} }
} }
else if (t.cs() == "newtheorem") {
ostringstream ss;
ss << "\\newtheorem";
ss << '{' << p.verbatimItem() << '}';
ss << p.getOpt();
ss << '{' << p.verbatimItem() << '}';
ss << p.getOpt();
ss << '\n';
handle_tex(os, ss.str());
}
else if (t.cs() == "(") { else if (t.cs() == "(") {
begin_inset(os, "Formula"); begin_inset(os, "Formula");
os << " \\("; os << " \\(";
@ -638,7 +669,13 @@ void parse(Parser & p, ostream & os, unsigned flags, mode_type mode)
os << "\\end{" << name << "}"; os << "\\end{" << name << "}";
end_inset(os); end_inset(os);
} else if (name == "tabular") { } else if (name == "tabular") {
handle_tabular(p, os, mode); if (mode == TEXT_MODE)
handle_tabular(p, os, mode);
else {
os << "\\begin{" << name << "}";
parse(p, os, FLAG_END, MATHTEXT_MODE);
os << "\\end{" << name << "}";
}
} else if (name == "table") { } else if (name == "table") {
begin_inset(os, "Float table\n"); begin_inset(os, "Float table\n");
os << "wide false\n" os << "wide false\n"
@ -716,13 +753,34 @@ void parse(Parser & p, ostream & os, unsigned flags, mode_type mode)
else if (t.cs() == "newenvironment") { else if (t.cs() == "newenvironment") {
string const name = p.getArg('{', '}'); string const name = p.getArg('{', '}');
p.skipSpaces(); if (name != "lyxcode") {
string const begin = p.verbatimItem(); ostringstream ss;
p.skipSpaces(); ss << "\\newenvironment{" << name << "}";
string const end = p.verbatimItem(); ss << p.getOpt();
// ignore out mess ss << p.getOpt();
if (name != "lyxcode") ss << '{' << p.verbatimItem() << '}';
os << wrap("newenvironment", begin + end); ss << '{' << p.verbatimItem() << '}';
ss << '\n';
handle_tex(os, ss.str());
}
}
else if (t.cs() == "newfont") {
ostringstream ss;
ss << "\\newfont";
ss << '{' << p.verbatimItem() << '}';
ss << '{' << p.verbatimItem() << '}';
ss << '\n';
handle_tex(os, ss.str());
}
else if (t.cs() == "newcounter") {
ostringstream ss;
ss << "\\newcounter";
ss << '{' << p.verbatimItem() << '}';
ss << p.getOpt();
ss << '\n';
handle_tex(os, ss.str());
} }
else if (t.cs() == "def") { else if (t.cs() == "def") {
@ -744,14 +802,14 @@ void parse(Parser & p, ostream & os, unsigned flags, mode_type mode)
} }
else if (t.cs() == "setlength") { else if (t.cs() == "setlength") {
string const name = p.getToken().cs(); string const name = p.verbatimItem();
string const content = p.getArg('{', '}'); string const content = p.verbatimItem();
if (name == "parskip") if (in_preamble && name == "parskip")
h_paragraph_separation = "skip"; h_paragraph_separation = "skip";
else if (name == "parindent") else if (in_preamble && name == "parindent")
h_paragraph_separation = "skip"; h_paragraph_separation = "skip";
else else
h_preamble << "\\setlength{" << name << "}{" << content << "}\n"; handle_tex(os, "\\setlength{" + name + "}{" + content + "}\n");
} }
else if (t.cs() == "par") else if (t.cs() == "par")
@ -763,7 +821,7 @@ void parse(Parser & p, ostream & os, unsigned flags, mode_type mode)
p.getToken(); p.getToken();
name += "*"; name += "*";
} }
os << "\\layout " << cap(name) << "\n\n"; os << "\n\n\\layout " << cap(name) << "\n\n";
parse(p, os, FLAG_ITEM, mode); parse(p, os, FLAG_ITEM, mode);
} }
@ -825,9 +883,20 @@ void parse(Parser & p, ostream & os, unsigned flags, mode_type mode)
else if (t.cs() == "&" && mode == TEXT_MODE) else if (t.cs() == "&" && mode == TEXT_MODE)
os << '&'; os << '&';
else if (t.cs() == "input")
handle_tex(os, "\\input{" + p.verbatimItem() + "}\n");
else if (t.cs() == "pagestyle" && in_preamble) else if (t.cs() == "pagestyle" && in_preamble)
h_paperpagestyle == p.getArg('{','}'); h_paperpagestyle == p.getArg('{','}');
else if (t.cs() == "fancyhead") {
ostringstream ss;
ss << "\\fancyhead";
ss << p.getOpt();
ss << '{' << p.verbatimItem() << "}\n";
handle_tex(os, ss.str());
}
else { else {
if (mode == MATH_MODE) if (mode == MATH_MODE)
os << t.asInput(); os << t.asInput();

View File

@ -39,14 +39,14 @@ void catInit()
theCatcode['}'] = catEnd; theCatcode['}'] = catEnd;
theCatcode['$'] = catMath; theCatcode['$'] = catMath;
theCatcode['&'] = catAlign; theCatcode['&'] = catAlign;
theCatcode['\n'] = catNewline; theCatcode[10] = catNewline;
theCatcode['#'] = catParameter; theCatcode['#'] = catParameter;
theCatcode['^'] = catSuper; theCatcode['^'] = catSuper;
theCatcode['_'] = catSub; theCatcode['_'] = catSub;
theCatcode[''] = catIgnore; theCatcode[''] = catIgnore;
theCatcode[' '] = catSpace; theCatcode[' '] = catSpace;
theCatcode['\t'] = catSpace; theCatcode['\t'] = catSpace;
theCatcode['\r'] = catNewline; theCatcode[13] = catIgnore;
theCatcode['~'] = catActive; theCatcode['~'] = catActive;
theCatcode['%'] = catComment; theCatcode['%'] = catComment;
} }
@ -191,6 +191,13 @@ string Parser::getArg(char left, char right)
} }
string Parser::getOpt()
{
string res = getArg('[', ']');
return res.size() ? '[' + res + ']' : string();
}
void Parser::tokenize(istream & is) void Parser::tokenize(istream & is)
{ {
static bool init_done = false; static bool init_done = false;
@ -252,7 +259,8 @@ void Parser::tokenize(istream & is)
} }
case catIgnore: { case catIgnore: {
cerr << "ignoring a char: " << int(c) << "\n"; if (c != 13)
cerr << "ignoring a char: " << int(c) << "\n";
break; break;
} }
@ -320,3 +328,14 @@ string Parser::verbatimItem()
return getToken().asInput(); return getToken().asInput();
} }
void Parser::setCatCode(char c, CatCode cat)
{
theCatcode[c] = cat;
}
CatCode Parser::getCatCode(char c) const
{
return theCatcode[c];
}

View File

@ -106,6 +106,8 @@ public:
/// ///
string getArg(char left, char right); string getArg(char left, char right);
/// getArg('[', ']') including the brackets
string getOpt();
/// ///
char getChar(); char getChar();
/// ///
@ -133,6 +135,11 @@ public:
/// ///
string verbatimOption(); string verbatimOption();
///
void setCatCode(char c, CatCode cat);
///
CatCode getCatCode(char c) const;
//private: //private:
/// ///
int lineno_; int lineno_;