X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_macrotable.C;h=b7cd35d2d36afc409ca0c60f704d8600dfc75b34;hb=c649284611c4198c9d70be8a16d153cdf1ec0700;hp=29ecb06874a8753dc90ca6ef5608c750c95fb692;hpb=8d7fe83bf5f6a7650668adaf2999ab934e05a89a;p=lyx.git diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index 29ecb06874..b7cd35d2d3 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -1,141 +1,160 @@ #include +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + #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" +#include "math_parser.h" +#include "math_mathmlstream.h" #include "debug.h" +#include "math_support.h" // math_font_available -using std::endl; -MathMacroTable MathMacroTable::mathMTable; +MathMacroTable::table_type MathMacroTable::macro_table; -bool MathMacroTable::built = false; - -MathMacro * MathMacroTable::getMacro(string const & name) const +void MathMacroTable::dump() { - MathMacroTemplate * mt = getTemplate(name); - return (mt) ? new MathMacro(mt): 0; +/* + lyxerr << "\n------------------------------------------\n"; + table_type::const_iterator it; + for (it = macro_table.begin(); it != macro_table.end(); ++it) + lyxerr << it->first + << " [" << it->second->asMacroTemplate()->nargs() << "] : " + << it->second->cell(0) << "\n"; + lyxerr << "------------------------------------------\n"; +*/ } -// The search is currently linear but will be binary or hash, later. -MathMacroTemplate * MathMacroTable::getTemplate(string const & name) const +MathAtom & MathMacroTable::provide(string const & name) { - for (size_type i = 0; i < macro_table.size(); ++i) { - if (name == macro_table[i]->GetName()) - return macro_table[i]; + builtinMacros(); + + table_type::iterator pos = macro_table.find(name); + + if (pos == macro_table.end()) { + lyxerr << "MathMacroTable::provideTemplate: no template with name '" + << name << "' available.\n"; } - return 0; + return pos->second; } -void MathMacroTable::addTemplate(MathMacroTemplate * m) + +void MathMacroTable::create(string const & name, int na) { - macro_table.push_back(m); + macro_table[name] = MathAtom(new MathMacroTemplate(name, na)); } -// All this stuff aparently leaks because it's created here and is not -// deleted never, but it have to live all the LyX sesion. OK, would not -// so hard to do it in the MacroTable destructor, but this doesn't harm -// seriously, so don't bother me with purify results here. ;-) +void MathMacroTable::create + (string const & name, int na, MathArray const & ar1, MathArray const & ar2) +{ + MathAtom t(new MathMacroTemplate(name, na)); + t->cell(0) = ar1; + t->cell(1) = ar2; + macro_table[name] = t; +} + + +void MathMacroTable::define(string const & display) +{ + string name; + mathed_parse_macro(name, display); +} + + +bool MathMacroTable::has(string const & name) +{ + builtinMacros(); + return macro_table.find(name) != macro_table.end(); +} + void MathMacroTable::builtinMacros() { - MathParInset * inset;// *arg; - - built = true; - - lyxerr[Debug::MATHED] << "Building macros" << endl; - - // This macro doesn't have arguments - MathMacroTemplate * m = new MathMacroTemplate("notin"); // this leaks - addTemplate(m); - { - MathedArray * array = new MathedArray; // this leaks - MathedIter iter(array); - iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not), - LM_TC_INSET); // this leaks - m->setData(array); - } - - // These two are only while we are still with LyX 2.x - m = new MathMacroTemplate("emptyset"); // this leaks - addTemplate(m); - { - MathedArray * array = new MathedArray; // this leaks - MathedIter iter(array); - iter.insertInset(new MathAccentInset('O', LM_TC_RM, LM_not), - LM_TC_INSET); // this leaks - m->setData(array); - } - - m = new MathMacroTemplate("perp"); // this leaks - addTemplate(m); - { - MathedArray * array = new MathedArray; // this leaks - MathedIter iter(array); - iter.insert(LM_bot, LM_TC_BOP); - m->setData(array); - } + static bool built = false; - // binom has two arguments - m = new MathMacroTemplate("binom", 2); - addTemplate(m); - { - MathedArray * array = new MathedArray; - m->setData(array); - MathedIter iter(array); - inset = new MathDelimInset('(', ')'); - iter.insertInset(inset, LM_TC_ACTIVE_INSET); - array = new MathedArray; - MathedIter iter2(array); - MathFracInset * frac = new MathFracInset(LM_OT_ATOP); - iter2.insertInset(frac, LM_TC_ACTIVE_INSET); - inset->setData(array); - array = new MathedArray; - MathedArray * array2 = new MathedArray; - MathedIter iter3(array); - iter3.insertInset(m->getMacroPar(0), LM_TC_INSET); - MathedIter iter4(array2); - iter4.insertInset(m->getMacroPar(1), LM_TC_INSET); - frac->SetData(array, array2); - } + if (built) + return; -/* - // Cases has 1 argument - m = new MathMacroTemplate("cases", 1, MMF_Env); // this leaks - addTemplate(m); - array = new MathedArray; // this leaks - iter.SetData(array); - arg = new MathMatrixInset(2, 1); // this leaks - - m->setArgument(arg); - arg->SetAlign('c', "ll"); - iter.Insert(arg, LM_TC_ACTIVE_INSET); - inset = new MathDelimInset('{', '.'); // this leaks - inset->SetData(array); - array = new MathedArray; // this leaks - iter.SetData(array); - iter.Insert(inset, LM_TC_ACTIVE_INSET); - m->SetData(array); - - - // the environment substack has 1 argument - m = new MathMacroTemplate("substack", 1, MMF_Env); // this leaks - addTemplate(m); - arg = new MathMatrixInset(1, 1); // this leaks - m->setArgument(arg); - arg->SetType(LM_OT_MACRO); - array = new MathedArray; // this leaks - iter.SetData(array); - iter.Insert(arg, LM_TC_ACTIVE_INSET); - m->SetData(array);*/ + built = true; + //lyxerr[Debug::MATHED] << "Building macros\n"; + //define("\\def\\emptyset{\\not0}"); + define("\\def\\notin{\\not\\in}"); + define("\\def\\slash{/}"); + //define("\\def\\mathcircumflex{\\^}"); + + // fontmath.ltx + + define("\\def\\lnot{\\neg}"); + define("\\def\\land{\\wedge}"); + define("\\def\\lor{\\vee}"); + define("\\def\\ne{\\neq}"); + define("\\def\\le{\\leq}"); + define("\\def\\ge{\\geq}"); + define("\\def\\owns{\\ni}"); + define("\\def\\gets{\\leftarrow}"); + define("\\def\\to{\\rightarrow}"); + define("\\def\\|{\\Vert}"); + + define("\\def\\longleftrightarrow{\\leftarrow\\kern-8mu\\rightarrow}"); + define("\\def\\Longleftrightarrow{\\Leftarrow\\kern-8mu\\Rightarrow}"); + define("\\def\\doteq{\\stackrel{\\cdot}{\\=}}"); + + //if (math_font_available(LM_TC_CMSY)) { + define("\\def\\longrightarrow{\\lyxbar\\kern-6mu\\rightarrow}"); + define("\\def\\longleftarrow{\\leftarrow\\kern-6mu\\lyxbar}"); + define("\\def\\mapsto{\\mapstochar\\kern-4mu\\rightarrow}"); + define("\\def\\longmapsto{\\mapstochar\\kern-3mu\\lyxbar\\kern-6mu\\rightarrow}"); + //} + + //if (math_font_available(LM_TC_CMR) && math_font_available(LM_TC_CMSY)) { + define("\\def\\Longrightarrow{\\lyxeq\\kern-5mu\\Rightarrow}"); + define("\\def\\Longleftarrow{\\Leftarrow\\kern-5mu\\lyxeq}"); + define("\\def\\models{\\vert\\kern-3mu\\lyxeq}"); + //} + + //if (math_font_available(LM_TC_CMM)) { + define("\\def\\hookrightarrow{\\lhook\\kern-8mu\\rightarrow}"); + define("\\def\\hookleftarrow{\\leftarrow\\kern-8mu\\rhook}"); + define("\\def\\bowtie{\\triangleright\\kern-2mu\\triangleleft}"); + //} + + //if (math_font_available(LM_TC_MSA)) { + //amsfonts.sty + + define("\\def\\dashrightarrow{\\lyxdabar\\lyxdabar\\lyxright}"); + define("\\def\\dashleftarrow{\\lyxleft\\lyxdabar\\lyxdabar}"); + define("\\def\\dasharrow{\\dashrightarrow}"); + define("\\def\\Box{\\square}"); + define("\\def\\Diamond{\\lozenge}"); + define("\\def\\leadsto{\\rightsquigarrow}"); + + // amssymb.sty + + define("\\def\\restriction{\\upharpoonright}"); + define("\\def\\Doteq{\\doteqdot}"); + define("\\def\\doublecup{\\Cup}"); + define("\\def\\doublecap{\\Cap}"); + define("\\def\\llless{\\lll}"); + define("\\def\\gggtr{\\ggg}"); + //} + + //if (math_font_available(LM_TC_MSB)) { + define("\\def\\Join{\\ltimes\\kern-12mu\\rtimes}"); + //} + + // + define("\\def\\mathcircumflex{\\mbox{\\^{}}}\n" "{\\hat{}}"); + + //define("\def\lint", 4, "\\int_#1^#2#3 d#4}"); + //define("\\def\\silentmult{\\cdot}"); + //define("\def\binom", 2, "\\left(\\frac#1#2\\right)}"); }