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 "math_deliminset.h"
|
|
|
|
#include "math_fracinset.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");
|
|
|
|
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");
|
|
|
|
createTemplate("to", 0, "\\rightarrow");
|
|
|
|
//createTemplate("lint", 4, "\\int_{#1}^{#2}#3 d#4");
|
|
|
|
//createTemplate("silentmult", 0, "\\cdot");
|
|
|
|
//createTemplate("binomi", 2, "\\left(\\frac{#1}{#2}\\right)");
|
2001-04-25 15:43:57 +00:00
|
|
|
|
|
|
|
// binom has two arguments
|
|
|
|
{
|
2001-08-08 17:26:30 +00:00
|
|
|
MathFracInset * frac = new MathFracInset;
|
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);
|
|
|
|
|
2001-08-07 08:40:14 +00:00
|
|
|
MathMacroTemplate t("binom", 2);
|
|
|
|
t.push_back(inset);
|
2001-06-25 00:06:33 +00:00
|
|
|
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
|
|
|
}
|