2001-02-13 17:08:51 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
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 "math_iter.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-02-13 17:08:51 +00:00
|
|
|
|
|
|
|
MathMacroTable MathMacroTable::mathMTable;
|
|
|
|
|
|
|
|
bool MathMacroTable::built = false;
|
|
|
|
|
|
|
|
|
2001-03-01 14:07:43 +00:00
|
|
|
MathMacro * MathMacroTable::createMacro(string const & name) const
|
2001-02-13 17:08:51 +00:00
|
|
|
{
|
2001-03-01 14:07:43 +00:00
|
|
|
boost::shared_ptr<MathMacroTemplate> mt = getTemplate(name);
|
|
|
|
return (mt.get()) ? new MathMacro(mt) : 0;
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-01 14:07:43 +00:00
|
|
|
boost::shared_ptr<MathMacroTemplate> const
|
|
|
|
MathMacroTable::getTemplate(string const & name) const
|
2001-02-13 17:08:51 +00:00
|
|
|
{
|
2001-03-01 14:07:43 +00:00
|
|
|
table_type::const_iterator cit = macro_table.find(name);
|
|
|
|
if (cit != macro_table.end()) return (*cit).second;
|
|
|
|
return boost::shared_ptr<MathMacroTemplate>();
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|
|
|
|
|
2001-03-01 14:07:43 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
MathMacroTable::addTemplate(boost::shared_ptr<MathMacroTemplate> const & m)
|
2001-02-13 17:08:51 +00:00
|
|
|
{
|
2001-03-01 14:07:43 +00:00
|
|
|
Assert(m.get());
|
|
|
|
macro_table[m->GetName()] = m;
|
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-03-01 14:07:43 +00:00
|
|
|
boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("notin", 0));
|
|
|
|
addTemplate(m);
|
2001-02-20 16:00:22 +00:00
|
|
|
MathedArray array;
|
|
|
|
MathedIter iter(&array);
|
2001-02-19 18:29:10 +00:00
|
|
|
iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not),
|
2001-03-01 14:07:43 +00:00
|
|
|
LM_TC_INSET);
|
2001-02-19 18:29:10 +00:00
|
|
|
m->setData(array);
|
|
|
|
}
|
2001-02-13 17:08:51 +00:00
|
|
|
|
|
|
|
// These two are only while we are still with LyX 2.x
|
2001-02-19 18:29:10 +00:00
|
|
|
{
|
2001-03-01 14:07:43 +00:00
|
|
|
boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("emptyset", 0));
|
|
|
|
addTemplate(m);
|
2001-02-20 16:00:22 +00:00
|
|
|
MathedArray array;
|
|
|
|
MathedIter iter(&array);
|
2001-02-19 18:29:10 +00:00
|
|
|
iter.insertInset(new MathAccentInset('O', LM_TC_RM, LM_not),
|
2001-03-01 14:07:43 +00:00
|
|
|
LM_TC_INSET);
|
2001-02-19 18:29:10 +00:00
|
|
|
m->setData(array);
|
|
|
|
}
|
2001-02-13 17:08:51 +00:00
|
|
|
|
2001-02-19 18:29:10 +00:00
|
|
|
{
|
2001-03-01 14:07:43 +00:00
|
|
|
boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("perp", 0));
|
|
|
|
addTemplate(m);
|
2001-02-20 16:00:22 +00:00
|
|
|
MathedArray array;
|
|
|
|
MathedIter iter(&array);
|
2001-02-19 18:29:10 +00:00
|
|
|
iter.insert(LM_bot, LM_TC_BOP);
|
|
|
|
m->setData(array);
|
|
|
|
}
|
2001-02-13 17:08:51 +00:00
|
|
|
|
|
|
|
// binom has two arguments
|
2001-02-19 18:29:10 +00:00
|
|
|
{
|
2001-03-01 14:07:43 +00:00
|
|
|
boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("binom", 2));
|
|
|
|
addTemplate(m);
|
2001-02-20 16:00:22 +00:00
|
|
|
MathedArray array;
|
2001-02-19 18:29:10 +00:00
|
|
|
m->setData(array);
|
2001-02-20 16:00:22 +00:00
|
|
|
MathedIter iter(&array);
|
2001-03-01 14:07:43 +00:00
|
|
|
MathParInset * inset = new MathDelimInset('(', ')');
|
2001-02-19 18:29:10 +00:00
|
|
|
iter.insertInset(inset, LM_TC_ACTIVE_INSET);
|
2001-02-20 16:00:22 +00:00
|
|
|
array = MathedArray();
|
|
|
|
MathedIter iter2(&array);
|
2001-02-19 18:29:10 +00:00
|
|
|
MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
|
|
|
|
iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
|
|
|
|
inset->setData(array);
|
2001-02-20 16:00:22 +00:00
|
|
|
array = MathedArray();
|
|
|
|
MathedArray array2;
|
|
|
|
MathedIter iter3(&array);
|
2001-02-19 18:29:10 +00:00
|
|
|
iter3.insertInset(m->getMacroPar(0), LM_TC_INSET);
|
2001-02-20 16:00:22 +00:00
|
|
|
MathedIter iter4(&array2);
|
2001-02-19 18:29:10 +00:00
|
|
|
iter4.insertInset(m->getMacroPar(1), LM_TC_INSET);
|
|
|
|
frac->SetData(array, array2);
|
|
|
|
}
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|