remove hard-wired association LaTeX macro <-> mathed inset

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4599 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2002-07-11 09:34:58 +00:00
parent 26391776f2
commit bd6885433a
8 changed files with 77 additions and 160 deletions

View File

@ -8,6 +8,10 @@
#pragma interface
#endif
//
// used for [pbvV]matrix, psmatrix etc
//
class MathAMSArrayInset : public MathGridInset {
public:

View File

@ -53,112 +53,6 @@ typedef std::map<string, latexkeys> WordList;
WordList theWordList;
struct key_type {
///
string name;
///
string inset;
///
string extra;
};
key_type wordlist_array[] =
{
{"!", "space", ""},
{",", "space", ""},
{":", "space", ""},
{";", "space", ""},
{"Vmatrix", "matrix", ""},
{"acute", "decoration", ""},
{"bar", "decoration", ""},
{"begin", "begin", ""},
{"bf", "oldfont", ""},
{"bmatrix", "matrix", ""},
{"acute", "decoration", ""},
{"breve", "decoration", ""},
{"cal", "oldfont", ""},
{"cdots", "dots", ""},
{"check", "decoration", ""},
{"ddot", "decoration", ""},
{"dddot", "decoration", ""},
{"ddots", "dots", ""},
{"displaystyle", "style", ""},
{"dot", "decoration", ""},
{"dotsb", "dots", ""},
{"dotsc", "dots", ""},
{"dotsi", "dots", ""},
{"dotsm", "dots", ""},
{"dotso", "dots", ""},
{"end", "end", ""},
{"fbox", "fbox", ""},
{"frak", "font", ""},
{"grave", "decoration", ""},
{"hat", "decoration", ""},
{"it", "oldfont", ""},
{"label", "label", ""},
{"ldots", "dots", ""},
{"left", "left", ""},
{"lyxnegspace", "space", ""},
{"lyxposspace", "space", ""},
{"mathbb", "font", ""},
{"mathbf", "font", ""},
{"mathcal", "font", ""},
{"mathfrak", "font", ""},
{"mathit", "font", ""},
{"mathnormal", "font", ""},
{"mathring", "decoration", ""},
{"mathrm", "font", ""},
{"mathsf", "font", ""},
{"mathtt", "font", ""},
{"matrix", "matrix", ""},
{"mbox", "mbox", ""},
{"newcommand", "newcommand", ""},
{"overbrace", "decoration", ""},
{"overleftarrow", "decoration", ""},
{"overline", "decoration", ""},
{"overrightarrow", "decoration", ""},
{"overleftrightarrow", "decoration", ""},
{"pageref", "ref", ""},
{"parbox", "parbox", ""},
{"pmatrix", "matrix", ""},
{"prettyref", "ref", ""},
{"protect", "protect", ""},
{"qquad", "space", ""},
{"quad", "space", ""},
{"ref", "ref", ""},
{"right", "right", ""},
{"rm", "oldfont", ""},
{"scriptscriptstyle", "style", ""},
{"scriptstyle", "style", ""},
{"text", "font", "mathtext"},
{"textbf", "font", "mathtext"},
{"textipa", "font", "mathtext"},
{"textit", "font", "mathtext"},
{"textmd", "font", "mathtext"},
{"textrm", "font", "mathtext"},
{"textsl", "font", "mathtext"},
{"textup", "font", "mathtext"},
{"textstyle", "style", ""},
{"tilde", "decoration", ""},
{"tt", "oldfont", ""},
{"underbar", "decoration", ""},
{"underbrace", "decoration", ""},
{"underleftarrow", "decoration", ""},
{"underline", "decoration", ""},
{"underrightarrow", "decoration", ""},
{"underleftrightarrow", "decoration", ""},
{"underset", "underset", ""},
{"vdots", "dots", ""},
{"vec", "decoration", ""},
{"vmatrix", "matrix", ""},
{"vpageref", "ref", ""},
{"vref", "ref", ""},
{"widehat", "decoration", ""},
{"widetilde", "decoration", ""}
};
bool math_font_available(string & name)
{
LyXFont f;
@ -179,9 +73,15 @@ bool math_font_available(string & name)
}
void readSymbols(string const & filename)
void initSymbols()
{
string const filename = LibFileSearch(string(), "symbols");
lyxerr[Debug::MATHED] << "read symbols from " << filename << "\n";
if (filename.empty()) {
lyxerr << "Could not find symbols file\n";
return;
}
std::ifstream fs(filename.c_str());
while (fs) {
int charid = 0;
@ -189,40 +89,51 @@ void readSymbols(string const & filename)
latexkeys tmp;
string line;
getline(fs, line);
istringstream is(line);
is >> tmp.name
>> tmp.inset
>> charid
>> fallbackid
>> tmp.extra
>> tmp.xmlname;
if (!is)
if (line.size() > 1 && line[0] == '#')
continue;
istringstream is(line);
is >> tmp.name >> tmp.inset;
if (isFontName(tmp.inset))
is >> charid >> fallbackid >> tmp.extra >> tmp.xmlname;
else
is >> tmp.extra;
if (!is) {
lyxerr[Debug::MATHED] << "skipping line '" << line << "'\n";
lyxerr[Debug::MATHED]
<< tmp.name << ' ' << tmp.inset << ' ' << tmp.extra << "\n";
continue;
}
// tmp.inset _is_ the fontname here.
// create fallbacks if necessary
if (tmp.extra == "func" || tmp.extra == "funclim" || tmp.extra=="special") {
lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << "\n";
tmp.draw = tmp.name;
} else if (math_font_available(tmp.inset)) {
lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << "\n";
tmp.draw += char(charid);
} else if (fallbackid) {
if (tmp.inset == "cmex")
tmp.inset = "lyxsymbol";
else
tmp.inset = "lyxboldsymbol";
lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << "\n";
tmp.draw += char(fallbackid);
if (isFontName(tmp.inset)) {
// tmp.inset _is_ the fontname here.
// create fallbacks if necessary
if (tmp.extra=="func" || tmp.extra=="funclim" || tmp.extra=="special") {
lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << "\n";
tmp.draw = tmp.name;
} else if (math_font_available(tmp.inset)) {
lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << "\n";
tmp.draw += char(charid);
} else if (fallbackid) {
if (tmp.inset == "cmex")
tmp.inset = "lyxsymbol";
else
tmp.inset = "lyxboldsymbol";
lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << "\n";
tmp.draw += char(fallbackid);
} else {
lyxerr[Debug::MATHED] << "faking " << tmp.name << "\n";
tmp.draw = tmp.name;
tmp.inset = "lyxtex";
}
} else {
lyxerr[Debug::MATHED] << "faking " << tmp.name << "\n";
tmp.draw = tmp.name;
tmp.inset = "lyxtex";
// it's a proper inset
lyxerr[Debug::MATHED] << "inset " << tmp.inset << " used for "
<< tmp.name << "\n";
}
if (theWordList.find(tmp.name) != theWordList.end())
lyxerr[Debug::MATHED] << "readSymbols: inset " << tmp.name
<< " already exists.\n";
<< " already exists.\n";
else
theWordList[tmp.name] = tmp;
lyxerr[Debug::MATHED] << "read symbol '" << tmp.name
@ -234,26 +145,6 @@ void readSymbols(string const & filename)
}
void initSymbols()
{
unsigned const n = sizeof(wordlist_array) / sizeof(wordlist_array[0]);
for (key_type * p = wordlist_array; p != wordlist_array + n; ++p) {
latexkeys tmp;
tmp.name = p->name;
tmp.inset = p->inset;
tmp.draw = p->name;
theWordList[p->name] = tmp;
}
lyxerr[Debug::MATHED] << "reading symbols file\n";
string const file = LibFileSearch(string(), "symbols");
if (file.empty())
lyxerr << "Could not find symbols file\n";
else
readSymbols(file);
}
} // namespace anon

View File

@ -259,6 +259,7 @@ string MathHullInset::label(row_type row) const
void MathHullInset::label(row_type row, string const & label)
{
lyxerr << "setting label '" << label << "' for row " << row << endl;
label_[row] = label;
}

View File

@ -233,6 +233,13 @@ NormalStream & operator<<(NormalStream & ns, char c)
}
NormalStream & operator<<(NormalStream & ns, int i)
{
ns.os() << i;
return ns;
}
//////////////////////////////////////////////////////////////////////

View File

@ -93,6 +93,8 @@ NormalStream & operator<<(NormalStream &, MathArray const &);
NormalStream & operator<<(NormalStream &, char const *);
///
NormalStream & operator<<(NormalStream &, char);
///
NormalStream & operator<<(NormalStream &, int);

View File

@ -249,8 +249,6 @@ private:
void error(string const & msg);
/// dump contents to screen
void dump() const;
private:
///
void tokenize(istream & is);
///
@ -656,7 +654,7 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags,
if (flags & FLAG_OPTION) {
if (t.cat() == catOther && t.character() == '[') {
// skip the bracket and collect everything to the clsing bracket
// skip the bracket and collect everything to the closing bracket
flags |= FLAG_BRACK_LAST;
continue;
}

View File

@ -589,21 +589,34 @@ fontinfo fontinfos[] = {
};
fontinfo * searchFont(string const & name)
fontinfo * lookupFont(string const & name)
{
int const n = sizeof(fontinfos) / sizeof(fontinfo);
//lyxerr << "searching font '" << name << "'\n";
int const n = sizeof(fontinfos) / sizeof(fontinfo);
for (int i = 0; i < n; ++i)
if (fontinfos[i].cmd_ == name) {
//lyxerr << "found '" << i << "'\n";
return fontinfos + i;
}
return 0;
}
fontinfo * searchFont(string const & name)
{
fontinfo * f = lookupFont(name);
return f ? f : fontinfos;
// this should be mathnormal
return fontinfos;
//return searchFont("mathnormal");
}
bool isFontName(string const & name)
{
return lookupFont(name);
}
LyXFont getFont(string const & name)
{
LyXFont font;

View File

@ -41,5 +41,6 @@ void math_font_max_dim(LyXFont const &, int & asc, int & desc);
void augmentFont(LyXFont & f, string const & cmd);
bool isFontName(string const & name);
#endif