2001-02-13 17:08:51 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-04-25 19:33:52 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2001-03-01 14:07:43 +00:00
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
2001-02-13 17:08:51 +00:00
|
|
|
#include "math_macrotable.h"
|
|
|
|
#include "math_macro.h"
|
|
|
|
#include "math_macrotemplate.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "math_parser.h"
|
2001-02-13 19:10:18 +00:00
|
|
|
#include "debug.h"
|
2001-02-13 17:08:51 +00:00
|
|
|
|
|
|
|
|
2001-07-26 16:14:23 +00:00
|
|
|
MathArray mathed_parse_cell(string const &);
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathMacroTable::table_type MathMacroTable::macro_table;
|
2001-02-13 17:08:51 +00:00
|
|
|
|
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
void MathMacroTable::dump()
|
2001-02-13 17:08:51 +00:00
|
|
|
{
|
2001-06-27 15:57:57 +00:00
|
|
|
lyxerr << "\n------------------------------------------\n";
|
2001-04-24 16:13:38 +00:00
|
|
|
table_type::const_iterator it;
|
|
|
|
for (it = macro_table.begin(); it != macro_table.end(); ++it)
|
2001-08-07 08:40:14 +00:00
|
|
|
lyxerr << it->first << " [" << it->second.nargs() << "] : "
|
2001-08-01 16:48:06 +00:00
|
|
|
<< it->second << "\n";
|
|
|
|
lyxerr << "------------------------------------------\n";
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|
|
|
|
|
2001-03-01 14:07:43 +00:00
|
|
|
|
2001-08-07 08:40:14 +00:00
|
|
|
void MathMacroTable::insertTemplate(MathMacroTemplate const & p)
|
2001-02-13 17:08:51 +00:00
|
|
|
{
|
2001-08-07 08:40:14 +00:00
|
|
|
if (macro_table.find(p.name()) != macro_table.end())
|
|
|
|
lyxerr << "macro '" << p.name() << "' not new\n";
|
|
|
|
macro_table[p.name()] = p;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathMacroTemplate & MathMacroTable::provideTemplate(string const & name)
|
|
|
|
{
|
|
|
|
builtinMacros();
|
2001-04-24 16:13:38 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
table_type::iterator pos = macro_table.find(name);
|
|
|
|
|
|
|
|
if (pos == macro_table.end()) {
|
|
|
|
lyxerr << "MathMacroTable::provideTemplate: no template with name '"
|
2001-08-01 16:48:06 +00:00
|
|
|
<< name << "' available.\n";
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-08-07 08:40:14 +00:00
|
|
|
return pos->second;
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-07-26 16:14:23 +00:00
|
|
|
void MathMacroTable::createTemplate
|
|
|
|
(string const & name, int na, string const & text)
|
|
|
|
{
|
2001-08-07 08:40:14 +00:00
|
|
|
MathMacroTemplate t(name, na);
|
|
|
|
t.cell(0) = mathed_parse_cell(text);
|
2001-07-26 16:14:23 +00:00
|
|
|
insertTemplate(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
bool MathMacroTable::hasTemplate(string const & name)
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
builtinMacros();
|
2001-04-24 16:13:38 +00:00
|
|
|
return macro_table.find(name) != macro_table.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathMacro * MathMacroTable::cloneTemplate(string const & name)
|
|
|
|
{
|
|
|
|
return new MathMacro(provideTemplate(name));
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacroTable::builtinMacros()
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
static bool built = false;
|
|
|
|
|
|
|
|
if (built)
|
|
|
|
return;
|
|
|
|
|
2001-02-13 17:08:51 +00:00
|
|
|
built = true;
|
2001-08-01 16:48:06 +00:00
|
|
|
//lyxerr[Debug::MATHED] << "Building macros\n";
|
2001-07-26 16:14:23 +00:00
|
|
|
|
2001-07-27 13:59:33 +00:00
|
|
|
createTemplate("emptyset", 0, "\\not0");
|
2001-08-17 15:55:31 +00:00
|
|
|
createTemplate("ne", 0, "\\not=");
|
2001-07-27 13:59:33 +00:00
|
|
|
createTemplate("ge", 0, "\\geq");
|
|
|
|
createTemplate("gets", 0, "\\leftarrow");
|
|
|
|
createTemplate("land", 0, "\\wedge");
|
|
|
|
createTemplate("le", 0, "\\leq");
|
|
|
|
createTemplate("lor", 0, "\\vee");
|
|
|
|
createTemplate("notin", 0, "\\not\\in");
|
|
|
|
createTemplate("perp", 0, "\\bot");
|
2001-08-17 15:53:06 +00:00
|
|
|
createTemplate("owns", 0, "\\ni");
|
2001-07-27 13:59:33 +00:00
|
|
|
createTemplate("to", 0, "\\rightarrow");
|
2001-08-21 14:20:50 +00:00
|
|
|
#ifdef WITH_WARNINGS
|
|
|
|
#warning 9em looks like too much but it is somehow working on screen..
|
2001-08-22 04:34:04 +00:00
|
|
|
#endif
|
2001-08-21 14:20:50 +00:00
|
|
|
createTemplate("ll", 0, "<\\kern-9em<");
|
|
|
|
createTemplate("gg", 0, ">\\kern-9em>");
|
2001-08-13 14:02:37 +00:00
|
|
|
//createTemplate("lint", 4, "\\int_#1^#2#3 d#4");
|
2001-07-27 13:59:33 +00:00
|
|
|
//createTemplate("silentmult", 0, "\\cdot");
|
2001-08-13 15:26:41 +00:00
|
|
|
//createTemplate("binom", 2, "\\left(\\frac#1#2\\right)");
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|