1999-09-27 18:44:28 +00:00
|
|
|
#include <config.h>
|
2001-04-25 15:43:57 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "math_parser.h"
|
2001-08-30 22:42:26 +00:00
|
|
|
#include "lyxlex.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "support/filetools.h" // LibFileSearch
|
|
|
|
|
2001-09-03 13:18:28 +00:00
|
|
|
#include <map>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-08-10 14:08:00 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2001-08-30 22:42:26 +00:00
|
|
|
struct latexkeys_a {
|
|
|
|
///
|
|
|
|
char const * name;
|
|
|
|
///
|
|
|
|
short token;
|
|
|
|
///
|
|
|
|
unsigned int id;
|
|
|
|
};
|
|
|
|
|
|
|
|
latexkeys_a wordlist_array[] =
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-08-31 21:15:57 +00:00
|
|
|
{"!", LM_TK_SPACE, 0},
|
|
|
|
{"#", LM_TK_SPECIAL, '#'},
|
|
|
|
{"$", LM_TK_SPECIAL, '$'},
|
|
|
|
{"%", LM_TK_SPECIAL, '%'},
|
|
|
|
{"&", LM_TK_SPECIAL, '&'},
|
|
|
|
{"(", LM_TK_BEGIN, LM_OT_SIMPLE},
|
|
|
|
{")", LM_TK_END, LM_OT_SIMPLE},
|
|
|
|
{",", LM_TK_SPACE, 1},
|
|
|
|
{".", LM_TK_SPECIAL, '.'},
|
|
|
|
{":", LM_TK_SPACE, 2},
|
|
|
|
{";", LM_TK_SPACE, 3},
|
|
|
|
{"Pr", LM_TK_FUNCLIM, 0},
|
|
|
|
{"[", LM_TK_BEGIN, LM_OT_EQUATION},
|
|
|
|
{"\\", LM_TK_NEWLINE, static_cast<unsigned>(-1)}, // -1 needed in mathed_parse_lines!
|
|
|
|
{"]", LM_TK_END, LM_OT_EQUATION},
|
|
|
|
{"_", LM_TK_SPECIAL, '_'},
|
2001-09-03 15:22:55 +00:00
|
|
|
{"acute", LM_TK_DECORATION, 0},
|
2001-08-31 21:15:57 +00:00
|
|
|
{"arccos", LM_TK_FUNC, 0},
|
|
|
|
{"arcsin", LM_TK_FUNC, 0},
|
|
|
|
{"arctan", LM_TK_FUNC, 0},
|
|
|
|
{"arg", LM_TK_FUNC, 0},
|
|
|
|
{"atop", LM_TK_ATOP, 0},
|
2001-09-03 15:22:55 +00:00
|
|
|
{"bar", LM_TK_DECORATION, 0},
|
2001-08-31 21:15:57 +00:00
|
|
|
{"begin", LM_TK_BEGIN, 0},
|
|
|
|
{"binom", LM_TK_BINOM, 0},
|
|
|
|
{"bmod", LM_TK_FUNC, 0},
|
2001-09-03 15:22:55 +00:00
|
|
|
{"breve", LM_TK_DECORATION, 0},
|
2001-08-31 21:15:57 +00:00
|
|
|
{"cal", LM_TK_OLDFONT, LM_TC_CAL},
|
2001-09-03 15:22:55 +00:00
|
|
|
{"cdots", LM_TK_DOTS, 0},
|
|
|
|
{"check", LM_TK_DECORATION, 0},
|
2001-08-31 21:15:57 +00:00
|
|
|
{"choose", LM_TK_CHOOSE, 0},
|
|
|
|
{"cos", LM_TK_FUNC, 0},
|
|
|
|
{"cosh", LM_TK_FUNC, 0},
|
|
|
|
{"cot", LM_TK_FUNC, 0},
|
|
|
|
{"coth", LM_TK_FUNC, 0},
|
|
|
|
{"csc", LM_TK_FUNC, 0},
|
2001-09-03 15:22:55 +00:00
|
|
|
{"ddot", LM_TK_DECORATION, 0},
|
|
|
|
{"ddots", LM_TK_DOTS, 0},
|
2001-08-31 21:15:57 +00:00
|
|
|
{"deg", LM_TK_FUNC, 0},
|
|
|
|
{"det", LM_TK_FUNCLIM, 0},
|
|
|
|
{"dim", LM_TK_FUNC, 0},
|
|
|
|
//{"displaystyle", LM_TK_STY, LM_ST_DISPLAY},
|
2001-09-03 15:22:55 +00:00
|
|
|
{"dot", LM_TK_DECORATION, 0},
|
2001-08-31 21:15:57 +00:00
|
|
|
{"end", LM_TK_END, 0},
|
|
|
|
{"exp", LM_TK_FUNC, 0},
|
|
|
|
{"frac", LM_TK_FRAC, 0},
|
|
|
|
{"gcd", LM_TK_FUNCLIM, 0},
|
2001-09-03 15:22:55 +00:00
|
|
|
{"grave", LM_TK_DECORATION, 0},
|
|
|
|
{"hat", LM_TK_DECORATION, 0},
|
2001-08-31 21:15:57 +00:00
|
|
|
{"hom", LM_TK_FUNC, 0},
|
|
|
|
{"inf", LM_TK_FUNCLIM, 0},
|
|
|
|
{"ker", LM_TK_FUNC, 0},
|
|
|
|
{"kern", LM_TK_KERN, 0},
|
|
|
|
{"label", LM_TK_LABEL, 0},
|
2001-09-03 15:22:55 +00:00
|
|
|
{"ldots", LM_TK_DOTS, 0},
|
2001-08-31 21:15:57 +00:00
|
|
|
{"left", LM_TK_LEFT, 0},
|
|
|
|
{"lg", LM_TK_FUNC, 0},
|
|
|
|
{"lim", LM_TK_FUNCLIM, 0},
|
|
|
|
{"liminf", LM_TK_FUNCLIM, 0},
|
|
|
|
{"limits", LM_TK_LIMIT, 1 },
|
|
|
|
{"limsup", LM_TK_FUNCLIM, 0},
|
|
|
|
{"ln", LM_TK_FUNC, 0},
|
|
|
|
{"log", LM_TK_FUNC, 0},
|
|
|
|
{"mathbb", LM_TK_FONT, LM_TC_BB},
|
|
|
|
{"mathbf", LM_TK_FONT, LM_TC_BF},
|
|
|
|
{"mathcal", LM_TK_FONT, LM_TC_CAL},
|
|
|
|
{"mathit", LM_TK_FONT, LM_TC_IT},
|
|
|
|
{"mathnormal", LM_TK_FONT, LM_TC_VAR},
|
|
|
|
{"mathrm", LM_TK_FONT, LM_TC_RM},
|
|
|
|
{"mathsf", LM_TK_FONT, LM_TC_SF},
|
|
|
|
{"mathtt", LM_TK_FONT, LM_TC_TT},
|
|
|
|
{"max", LM_TK_FUNCLIM, 0},
|
|
|
|
{"min", LM_TK_FUNCLIM, 0},
|
|
|
|
{"newcommand", LM_TK_NEWCOMMAND, 0 },
|
|
|
|
{"nolimits", LM_TK_LIMIT, static_cast<unsigned>(-1)},
|
|
|
|
{"nonumber", LM_TK_NONUM, 0},
|
2001-09-03 15:22:55 +00:00
|
|
|
{"not", LM_TK_NOT, 0},
|
2001-08-31 21:15:57 +00:00
|
|
|
{"over", LM_TK_OVER, 0},
|
2001-09-03 15:22:55 +00:00
|
|
|
{"overbrace", LM_TK_DECORATION, 0},
|
|
|
|
{"overleftarrow", LM_TK_DECORATION, 0},
|
|
|
|
{"overline", LM_TK_DECORATION, 0},
|
|
|
|
{"overrightarrow", LM_TK_DECORATION, 0},
|
2001-08-31 21:15:57 +00:00
|
|
|
{"protect", LM_TK_PROTECT, 0},
|
|
|
|
{"qquad", LM_TK_SPACE, 5},
|
|
|
|
{"quad", LM_TK_SPACE, 4},
|
|
|
|
{"right", LM_TK_RIGHT, 0},
|
|
|
|
{"root", LM_TK_ROOT, 0},
|
|
|
|
//{"scriptscriptstyle", LM_TK_STY, LM_ST_SCRIPTSCRIPT},
|
|
|
|
//{"scriptstyle", LM_TK_STY, LM_ST_SCRIPT},
|
|
|
|
{"sec", LM_TK_FUNC, 0},
|
|
|
|
{"sin", LM_TK_FUNC, 0},
|
|
|
|
{"sinh", LM_TK_FUNC, 0},
|
|
|
|
{"sqrt", LM_TK_SQRT, 0},
|
|
|
|
{"stackrel", LM_TK_STACK, 0},
|
|
|
|
{"sup", LM_TK_FUNCLIM, 0},
|
|
|
|
{"tan", LM_TK_FUNC, 0},
|
|
|
|
{"tanh", LM_TK_FUNC, 0},
|
|
|
|
{"textrm", LM_TK_FONT, LM_TC_TEXTRM},
|
|
|
|
//{"textstyle", LM_TK_STY, LM_ST_TEXT},
|
2001-09-03 15:22:55 +00:00
|
|
|
{"tilde", LM_TK_DECORATION, 0},
|
|
|
|
{"underbrace", LM_TK_DECORATION, 0},
|
|
|
|
{"underline", LM_TK_DECORATION, 0},
|
|
|
|
{"vdots", LM_TK_DOTS, 0},
|
|
|
|
{"vec", LM_TK_DECORATION, 0},
|
|
|
|
{"widehat", LM_TK_DECORATION, 0},
|
|
|
|
{"widetilde", LM_TK_DECORATION, 0},
|
2001-08-31 21:15:57 +00:00
|
|
|
{"{", LM_TK_SPECIAL, '{'},
|
2001-09-03 16:46:28 +00:00
|
|
|
{"}", LM_TK_SPECIAL, '}'}
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
2001-02-28 11:56:36 +00:00
|
|
|
|
2001-09-03 13:18:28 +00:00
|
|
|
std::map<string, latexkeys> wordlist;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MathTokenEnum tokenEnum(const string & font)
|
|
|
|
{
|
|
|
|
if (font == "cmr")
|
|
|
|
return LM_TK_CMR;
|
|
|
|
if (font == "cmsy")
|
|
|
|
return LM_TK_CMSY;
|
|
|
|
if (font == "cmm")
|
|
|
|
return LM_TK_CMM;
|
|
|
|
if (font == "cmex")
|
|
|
|
return LM_TK_CMEX;
|
|
|
|
if (font == "msa")
|
|
|
|
return LM_TK_MSA;
|
|
|
|
if (font == "msb")
|
|
|
|
return LM_TK_MSB;
|
|
|
|
return LM_TK_SYM;
|
|
|
|
}
|
|
|
|
|
|
|
|
MathSymbolTypes symbolType(const string & type)
|
|
|
|
{
|
|
|
|
if (type == "mathrel")
|
|
|
|
return LMB_RELATION;
|
|
|
|
if (type == "mathbin")
|
|
|
|
return LMB_OPERATOR;
|
|
|
|
return LMB_NONE;
|
|
|
|
}
|
2001-08-30 22:42:26 +00:00
|
|
|
|
2001-04-25 15:43:57 +00:00
|
|
|
|
2001-08-30 22:42:26 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
2001-08-31 13:27:52 +00:00
|
|
|
|
2001-08-30 22:42:26 +00:00
|
|
|
void ReadSymbols(string const & filename)
|
|
|
|
{
|
|
|
|
LyXLex lex(0, 0);
|
|
|
|
lex.setFile(filename);
|
2001-09-03 13:18:28 +00:00
|
|
|
while (lex.isOK() && lex.next()) {
|
2001-08-30 22:42:26 +00:00
|
|
|
latexkeys tmp;
|
2001-09-03 13:18:28 +00:00
|
|
|
tmp.name = lex.getString();
|
2001-08-30 22:42:26 +00:00
|
|
|
if (lex.next())
|
2001-09-03 13:18:28 +00:00
|
|
|
tmp.token = tokenEnum(lex.getString());
|
2001-08-30 22:42:26 +00:00
|
|
|
if (lex.next())
|
|
|
|
tmp.latex_font_id = lex.getInteger();
|
|
|
|
if (lex.next())
|
|
|
|
tmp.id = lex.getInteger();
|
|
|
|
if (lex.next())
|
2001-09-03 13:18:28 +00:00
|
|
|
tmp.type = symbolType(lex.getString());
|
2001-09-03 16:46:28 +00:00
|
|
|
if (wordlist.find(tmp.name) != wordlist.end())
|
|
|
|
lyxerr << "ReadSymbols: token " << tmp.name
|
|
|
|
<< " already exists.\n";
|
|
|
|
else
|
|
|
|
wordlist[tmp.name] = tmp;
|
2001-08-30 22:42:26 +00:00
|
|
|
}
|
2001-09-02 13:35:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-03 13:18:28 +00:00
|
|
|
void initSymbols()
|
2001-09-02 13:35:31 +00:00
|
|
|
{
|
2001-09-03 13:18:28 +00:00
|
|
|
unsigned const n = sizeof(wordlist_array) / sizeof(wordlist_array[0]);
|
|
|
|
for (latexkeys_a * p = wordlist_array; p != wordlist_array + n; ++p) {
|
2001-09-02 13:35:31 +00:00
|
|
|
latexkeys tmp;
|
2001-09-03 13:18:28 +00:00
|
|
|
tmp.name = p->name;
|
|
|
|
tmp.token = p->token;
|
|
|
|
tmp.id = p->id;
|
|
|
|
tmp.type = LMB_NONE;
|
2001-09-02 13:35:31 +00:00
|
|
|
tmp.latex_font_id = 0;
|
2001-09-03 13:18:28 +00:00
|
|
|
wordlist[p->name] = tmp;
|
2001-09-02 13:35:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
lyxerr[Debug::MATHED] << "Reading symbols file\n";
|
|
|
|
string const file = LibFileSearch(string(), "symbols");
|
|
|
|
if (file.empty())
|
2001-09-03 13:18:28 +00:00
|
|
|
lyxerr << "Could not find symbols file\n";
|
2001-09-02 13:35:31 +00:00
|
|
|
else
|
|
|
|
ReadSymbols(file);
|
2001-08-30 22:42:26 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
|
2001-04-25 15:43:57 +00:00
|
|
|
latexkeys const * in_word_set(string const & str)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2001-09-03 13:18:28 +00:00
|
|
|
static bool initialized = false;
|
|
|
|
|
2001-08-30 22:42:26 +00:00
|
|
|
if (!initialized) {
|
2001-09-03 13:18:28 +00:00
|
|
|
initSymbols();
|
2001-08-30 22:42:26 +00:00
|
|
|
initialized = true;
|
2001-08-31 13:27:52 +00:00
|
|
|
}
|
2001-08-30 22:42:26 +00:00
|
|
|
|
2001-09-03 13:18:28 +00:00
|
|
|
std::map<string, latexkeys>::iterator it = wordlist.find(str);
|
|
|
|
return (it != wordlist.end()) ? &(it->second) : 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|