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 17:08:51 +00:00
|
|
|
#include "array.h"
|
2001-07-13 07:55:55 +00:00
|
|
|
#include "math_decorationinset.h"
|
2001-02-13 17:08:51 +00:00
|
|
|
#include "math_deliminset.h"
|
|
|
|
#include "math_fracinset.h"
|
2001-06-25 00:06:33 +00:00
|
|
|
#include "math_inset.h"
|
2001-02-13 19:10:18 +00:00
|
|
|
#include "debug.h"
|
2001-03-01 14:07:43 +00:00
|
|
|
#include "support/LAssert.h"
|
2001-02-13 17:08:51 +00:00
|
|
|
|
2001-06-27 15:57:57 +00:00
|
|
|
using std::endl;
|
2001-02-13 17:08:51 +00:00
|
|
|
|
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-06-27 15:57:57 +00:00
|
|
|
lyxerr << it->first << " [" << it->second->nargs() << "] : "
|
2001-06-25 00:06:33 +00:00
|
|
|
<< it->second << endl;
|
2001-06-27 15:57:57 +00:00
|
|
|
lyxerr << "------------------------------------------" << endl;;
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathMacroTable::updateTemplate(MathMacroTemplate * par)
|
2001-02-13 17:08:51 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
table_type::iterator pos = macro_table.find(par->name());
|
|
|
|
|
|
|
|
if (pos == macro_table.end())
|
|
|
|
lyxerr << "MathMacroTable::updateTemplate: no template with name '"
|
2001-06-27 15:57:57 +00:00
|
|
|
<< par->name() << "' available." << endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
else
|
|
|
|
pos->second = par;
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|
|
|
|
|
2001-03-01 14:07:43 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
void MathMacroTable::insertTemplate(MathMacroTemplate * p)
|
2001-02-13 17:08:51 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
macro_table[p->name()] = p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-06-27 15:57:57 +00:00
|
|
|
<< name << "' available." << endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return *pos->second;
|
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-06-27 15:57:57 +00:00
|
|
|
lyxerr[Debug::MATHED] << "Building macros" << endl;
|
2001-02-13 17:08:51 +00:00
|
|
|
|
|
|
|
// This macro doesn't have arguments
|
2001-02-19 18:29:10 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
MathMacroTemplate * t = new MathMacroTemplate("notin", 0);
|
2001-07-13 07:55:55 +00:00
|
|
|
MathDecorationInset * p = new MathDecorationInset("not", LM_not);
|
2001-07-10 13:17:43 +00:00
|
|
|
p->cell(0).push_back(LM_in, LM_TC_BOPS);
|
|
|
|
t->push_back(p);
|
2001-06-25 00:06:33 +00:00
|
|
|
insertTemplate(t);
|
2001-02-19 18:29:10 +00:00
|
|
|
}
|
2001-04-24 16:13:38 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
/*
|
2001-04-25 15:43:57 +00:00
|
|
|
// This macro doesn't have arguments
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
MathMacroTemplate & m = createTemplate("silentmult", 0);
|
2001-04-25 15:43:57 +00:00
|
|
|
istringstream is("\\cdot\0");
|
|
|
|
mathed_parser_file(is, 0);
|
2001-06-25 00:06:33 +00:00
|
|
|
MathMatrixInset * p = &m;
|
2001-04-25 15:43:57 +00:00
|
|
|
mathed_parse(m.array, p, 0);
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
*/
|
2001-04-25 15:43:57 +00:00
|
|
|
|
2001-02-19 18:29:10 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
MathMacroTemplate * t = new MathMacroTemplate("emptyset", 0);
|
2001-07-13 07:55:55 +00:00
|
|
|
MathDecorationInset * p = new MathDecorationInset("not", LM_not);
|
2001-07-12 07:18:29 +00:00
|
|
|
p->cell(0).push_back('O', LM_TC_VAR);
|
2001-07-10 13:17:43 +00:00
|
|
|
t->push_back(p);
|
2001-06-25 00:06:33 +00:00
|
|
|
insertTemplate(t);
|
2001-02-19 18:29:10 +00:00
|
|
|
}
|
2001-04-24 16:13:38 +00:00
|
|
|
|
2001-07-20 10:57:22 +00:00
|
|
|
{
|
|
|
|
MathMacroTemplate * t = new MathMacroTemplate("land", 0);
|
|
|
|
t->push_back(LM_wedge, LM_TC_SYMB);
|
|
|
|
insertTemplate(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
MathMacroTemplate * t = new MathMacroTemplate("lor", 0);
|
|
|
|
t->push_back(LM_vee, LM_TC_SYMB);
|
|
|
|
insertTemplate(t);
|
|
|
|
}
|
|
|
|
|
2001-06-27 14:10:35 +00:00
|
|
|
{
|
|
|
|
MathMacroTemplate * t = new MathMacroTemplate("to", 0);
|
|
|
|
t->push_back(LM_rightarrow, LM_TC_SYMB);
|
|
|
|
insertTemplate(t);
|
|
|
|
}
|
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
MathMacroTemplate * t = new MathMacroTemplate("perp", 0);
|
|
|
|
t->push_back(LM_bot, LM_TC_BOP);
|
|
|
|
insertTemplate(t);
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
2001-07-20 10:57:22 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
/*
|
2001-04-25 15:43:57 +00:00
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
MathMacroTemplate & m = createTemplate("lint", 4);
|
2001-04-25 15:43:57 +00:00
|
|
|
istringstream is("\\int_{#1}^{#2}#3 d#4\0");
|
|
|
|
mathed_parser_file(is, 0);
|
2001-06-25 00:06:33 +00:00
|
|
|
MathMatrixInset * p = &m;
|
2001-04-25 15:43:57 +00:00
|
|
|
mathed_parse(m.array, p, 0);
|
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
*/
|
|
|
|
/*
|
|
|
|
{
|
|
|
|
MathMacroTemplate * t = new MathMacroTemplate("binomii", 2);
|
|
|
|
istringstream is("\\left(\\frac{#1}{#2}\\right)\0");
|
|
|
|
mathed_parser_file(is, 0);
|
|
|
|
mathed_parse(t->array, t, 0);
|
|
|
|
insertTemplate(t);
|
|
|
|
}
|
|
|
|
*/
|
2001-04-25 15:43:57 +00:00
|
|
|
|
|
|
|
// binom has two arguments
|
|
|
|
{
|
2001-07-09 10:19:50 +00:00
|
|
|
MathFracInset * frac = new MathFracInset("atop");
|
2001-06-25 00:06:33 +00:00
|
|
|
frac->cell(0).push_back(new MathMacroArgument(1));
|
|
|
|
frac->cell(1).push_back(new MathMacroArgument(2));
|
|
|
|
|
|
|
|
MathInset * inset = new MathDelimInset('(', ')');
|
|
|
|
inset->push_back(frac);
|
|
|
|
|
|
|
|
MathMacroTemplate * t = new MathMacroTemplate("binom", 2);
|
|
|
|
t->push_back(inset);
|
|
|
|
|
|
|
|
insertTemplate(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
{
|
|
|
|
MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
|
|
|
|
frac->cell(0)->push_back(new MathMacroArgument(1));
|
|
|
|
frac->cell(1)->push_back(new MathMacroArgument(2));
|
2001-04-24 16:13:38 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
MathMacroTemplate * t = new MathMacroTemplate("choose", 2);
|
|
|
|
t->push_back(frac);
|
2001-04-27 12:35:55 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
insertTemplate(t);
|
2001-02-19 18:29:10 +00:00
|
|
|
}
|
2001-06-25 00:06:33 +00:00
|
|
|
*/
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|