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"
|
|
|
|
#include "array.h"
|
|
|
|
#include "math_accentinset.h"
|
|
|
|
#include "math_deliminset.h"
|
|
|
|
#include "math_fracinset.h"
|
|
|
|
#include "math_parinset.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-02-14 15:00:50 +00:00
|
|
|
using std::endl;
|
2001-04-25 11:14:01 +00:00
|
|
|
using std::make_pair;
|
2001-02-13 17:08:51 +00:00
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
MathMacroTable::table_type MathMacroTable::macro_table;
|
2001-02-13 17:08:51 +00:00
|
|
|
|
|
|
|
bool MathMacroTable::built = false;
|
|
|
|
|
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
void MathMacroTable::dump()
|
2001-02-13 17:08:51 +00:00
|
|
|
{
|
2001-04-25 11:14:01 +00:00
|
|
|
using std::cerr;
|
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
cerr << "\n------------------------------------------\n";
|
|
|
|
table_type::const_iterator it;
|
|
|
|
for (it = macro_table.begin(); it != macro_table.end(); ++it)
|
|
|
|
cerr << it->first << ": " << it->second->GetData() << endl;
|
|
|
|
cerr << "------------------------------------------\n";
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
MathMacroTemplate &
|
|
|
|
MathMacroTable::provideTemplate(string const & name, int na)
|
2001-02-13 17:08:51 +00:00
|
|
|
{
|
2001-04-24 16:13:38 +00:00
|
|
|
if (!built)
|
|
|
|
builtinMacros();
|
|
|
|
|
|
|
|
if (macro_table.find(name) == macro_table.end())
|
|
|
|
macro_table.insert(make_pair(name, new MathMacroTemplate(name, na)));
|
|
|
|
|
|
|
|
return *(macro_table.find(name)->second);
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|
|
|
|
|
2001-03-01 14:07:43 +00:00
|
|
|
|
2001-04-24 16:13:38 +00:00
|
|
|
MathMacroTemplate &
|
|
|
|
MathMacroTable::provideTemplate(string const & name)
|
2001-02-13 17:08:51 +00:00
|
|
|
{
|
2001-04-24 16:13:38 +00:00
|
|
|
if (!built)
|
|
|
|
builtinMacros();
|
|
|
|
|
|
|
|
return *macro_table[name];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathMacroTable::hasTemplate(string const & name)
|
|
|
|
{
|
|
|
|
if (!built)
|
|
|
|
builtinMacros();
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
built = true;
|
|
|
|
|
|
|
|
lyxerr[Debug::MATHED] << "Building macros" << endl;
|
|
|
|
|
|
|
|
// This macro doesn't have arguments
|
2001-02-19 18:29:10 +00:00
|
|
|
{
|
2001-04-24 16:13:38 +00:00
|
|
|
MathMacroTemplate & m = provideTemplate("notin", 0);
|
2001-04-27 12:35:55 +00:00
|
|
|
m.push_back(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not), LM_TC_INSET);
|
2001-02-19 18:29:10 +00:00
|
|
|
}
|
2001-04-24 16:13:38 +00:00
|
|
|
|
2001-04-25 15:43:57 +00:00
|
|
|
// This macro doesn't have arguments
|
|
|
|
{
|
|
|
|
MathMacroTemplate & m = provideTemplate("silentmult", 0);
|
|
|
|
istringstream is("\\cdot\0");
|
|
|
|
mathed_parser_file(is, 0);
|
|
|
|
MathParInset * p = &m;
|
|
|
|
mathed_parse(m.array, p, 0);
|
|
|
|
}
|
|
|
|
|
2001-02-19 18:29:10 +00:00
|
|
|
{
|
2001-04-24 16:13:38 +00:00
|
|
|
MathMacroTemplate & m = provideTemplate("emptyset", 0);
|
2001-04-27 12:35:55 +00:00
|
|
|
m.push_back(new MathAccentInset('0', LM_TC_RM, LM_not), LM_TC_INSET);
|
2001-02-19 18:29:10 +00:00
|
|
|
}
|
2001-04-24 16:13:38 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
MathMacroTemplate & m = provideTemplate("perp", 0);
|
2001-04-27 12:35:55 +00:00
|
|
|
m.GetData().push_back(LM_bot, LM_TC_BOP);
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
|
|
|
|
2001-04-25 15:43:57 +00:00
|
|
|
{
|
|
|
|
MathMacroTemplate & m = provideTemplate("lint", 4);
|
|
|
|
istringstream is("\\int_{#1}^{#2}#3 d#4\0");
|
|
|
|
mathed_parser_file(is, 0);
|
|
|
|
MathParInset * p = &m;
|
|
|
|
mathed_parse(m.array, p, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// binom has two arguments
|
|
|
|
{
|
2001-04-24 16:13:38 +00:00
|
|
|
MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
|
2001-04-27 12:35:55 +00:00
|
|
|
frac->push_back(new MathMacroArgument(1), LM_TC_INSET);
|
|
|
|
frac->denom()->push_back(new MathMacroArgument(2), LM_TC_INSET);
|
2001-04-24 16:13:38 +00:00
|
|
|
|
2001-03-01 14:07:43 +00:00
|
|
|
MathParInset * inset = new MathDelimInset('(', ')');
|
2001-04-27 12:35:55 +00:00
|
|
|
inset->push_back(frac, LM_TC_ACTIVE_INSET);
|
|
|
|
|
|
|
|
MathMacroTemplate & m = provideTemplate("binom", 2);
|
|
|
|
m.push_back(inset, LM_TC_ACTIVE_INSET);
|
2001-02-19 18:29:10 +00:00
|
|
|
}
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|