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-11-08 12:06:56 +00:00
|
|
|
#include "math_mathmlstream.h"
|
2001-02-13 19:10:18 +00:00
|
|
|
#include "debug.h"
|
2001-11-08 12:15:12 +00:00
|
|
|
#include "math_support.h" // math_font_available
|
2001-02-13 17:08:51 +00:00
|
|
|
|
2001-07-26 16:14:23 +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-11-08 12:06:56 +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-10-12 12:02:49 +00:00
|
|
|
lyxerr << it->first
|
|
|
|
<< " [" << it->second->asMacroTemplate()->nargs() << "] : "
|
|
|
|
<< it->second->cell(0) << "\n";
|
2001-08-01 16:48:06 +00:00
|
|
|
lyxerr << "------------------------------------------\n";
|
2001-11-08 12:06:56 +00:00
|
|
|
*/
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|
|
|
|
|
2001-03-01 14:07:43 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom & MathMacroTable::provide(string const & name)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
|
|
|
builtinMacros();
|
2002-03-21 17:42:56 +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
|
|
|
}
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-08-07 08:40:14 +00:00
|
|
|
return pos->second;
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
void MathMacroTable::create(string const & name, int na, string const & text)
|
2001-07-26 16:14:23 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom t(new MathMacroTemplate(name, na));
|
2001-10-18 13:21:21 +00:00
|
|
|
mathed_parse_cell(t->cell(0), text);
|
2001-10-12 12:02:49 +00:00
|
|
|
macro_table[name] = t;
|
2001-07-26 16:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-11 11:33:43 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
void MathMacroTable::create(string const & name, int na, MathArray const & ar)
|
2001-04-24 16:13:38 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
MathAtom t(new MathMacroTemplate(name, na));
|
|
|
|
t->cell(0) = ar;
|
|
|
|
macro_table[name] = t;
|
2001-04-24 16:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
|
|
|
|
bool MathMacroTable::has(string const & name)
|
2001-04-24 16:13:38 +00:00
|
|
|
{
|
2001-10-12 12:02:49 +00:00
|
|
|
builtinMacros();
|
|
|
|
return macro_table.find(name) != macro_table.end();
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMacroTable::builtinMacros()
|
|
|
|
{
|
2001-06-25 00:06:33 +00:00
|
|
|
static bool built = false;
|
2002-03-21 17:42:56 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
if (built)
|
2002-03-21 17:42:56 +00:00
|
|
|
return;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
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-10-12 12:02:49 +00:00
|
|
|
//create("emptyset", 0, "\\not0");
|
|
|
|
create("notin", 0, "\\not\\in");
|
|
|
|
create("slash", 0, "/");
|
2001-08-30 22:42:26 +00:00
|
|
|
|
|
|
|
// fontmath.ltx
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
create("lnot", 0, "\\neg");
|
|
|
|
create("land", 0, "\\wedge");
|
|
|
|
create("lor", 0, "\\vee");
|
|
|
|
create("ne", 0, "\\neq");
|
|
|
|
create("le", 0, "\\leq");
|
|
|
|
create("ge", 0, "\\geq");
|
|
|
|
create("owns", 0, "\\ni");
|
|
|
|
create("gets", 0, "\\leftarrow");
|
|
|
|
create("to", 0, "\\rightarrow");
|
2001-10-31 10:54:34 +00:00
|
|
|
create("|", 0, "\\Vert");
|
2001-08-30 22:42:26 +00:00
|
|
|
|
2001-12-18 15:19:32 +00:00
|
|
|
create("longleftrightarrow", 0, "\\leftarrow\\kern-8mu\\rightarrow");
|
|
|
|
create("Longleftrightarrow", 0, "\\Leftarrow\\kern-8mu\\Rightarrow");
|
2001-10-12 12:02:49 +00:00
|
|
|
create("doteq", 0, "\\stackrel{\\cdot}{=}");
|
2001-08-31 21:15:57 +00:00
|
|
|
|
2001-09-19 17:22:34 +00:00
|
|
|
if (math_font_available(LM_TC_CMSY)) {
|
2001-12-18 15:19:32 +00:00
|
|
|
create("longrightarrow", 0, "\\lyxbar\\kern-6mu\\rightarrow");
|
|
|
|
create("longleftarrow", 0, "\\leftarrow\\kern-6mu\\lyxbar");
|
|
|
|
create("mapsto", 0, "\\mapstochar\\kern-4mu\\rightarrow");
|
|
|
|
create("longmapsto", 0, "\\mapstochar\\kern-3mu\\lyxbar\\kern-6mu\\rightarrow");
|
2001-09-19 17:22:34 +00:00
|
|
|
}
|
2001-08-31 21:15:57 +00:00
|
|
|
|
2002-01-26 18:33:45 +00:00
|
|
|
if (math_font_available(LM_TC_CMR) && math_font_available(LM_TC_CMSY)) {
|
2001-12-18 15:19:32 +00:00
|
|
|
create("Longrightarrow", 0, "\\lyxeq\\kern-5mu\\Rightarrow");
|
|
|
|
create("Longleftarrow", 0, "\\Leftarrow\\kern-5mu\\lyxeq");
|
2002-01-26 18:33:45 +00:00
|
|
|
create("models", 0, "\\vert\\kern-3mu\\lyxeq");
|
2001-09-19 17:22:34 +00:00
|
|
|
}
|
2001-08-31 21:15:57 +00:00
|
|
|
|
2001-09-19 17:22:34 +00:00
|
|
|
if (math_font_available(LM_TC_CMM)) {
|
2001-12-18 15:19:32 +00:00
|
|
|
create("hookrightarrow", 0, "\\lhook\\kern-8mu\\rightarrow");
|
|
|
|
create("hookleftarrow", 0, "\\leftarrow\\kern-8mu\\rhook");
|
|
|
|
create("bowtie", 0, "\\triangleright\\kern-2mu\\triangleleft");
|
2001-09-19 17:22:34 +00:00
|
|
|
}
|
2001-08-30 22:42:26 +00:00
|
|
|
|
2001-09-19 17:22:34 +00:00
|
|
|
if (math_font_available(LM_TC_MSA)) {
|
|
|
|
//amsfonts.sty
|
2001-08-30 22:42:26 +00:00
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
create("dashrightarrow", 0, "\\lyxdabar\\lyxdabar\\lyxright");
|
|
|
|
create("dashleftarrow", 0, "\\lyxleft\\lyxdabar\\lyxdabar");
|
|
|
|
create("dasharrow", 0, "\\dashrightarrow");
|
|
|
|
create("Box", 0, "\\square");
|
|
|
|
create("Diamond", 0, "\\lozenge");
|
|
|
|
create("leadsto", 0, "\\rightsquigarrow");
|
2001-08-30 22:42:26 +00:00
|
|
|
|
2001-09-19 17:22:34 +00:00
|
|
|
// amssymb.sty
|
|
|
|
|
2001-10-12 12:02:49 +00:00
|
|
|
create("restriction", 0, "\\upharpoonright");
|
|
|
|
create("Doteq", 0, "\\doteqdot");
|
|
|
|
create("doublecup", 0, "\\Cup");
|
|
|
|
create("doublecap", 0, "\\Cap");
|
|
|
|
create("llless", 0, "\\lll");
|
|
|
|
create("gggtr", 0, "\\ggg");
|
2001-09-19 17:22:34 +00:00
|
|
|
}
|
2001-08-30 22:42:26 +00:00
|
|
|
|
2002-01-26 18:33:45 +00:00
|
|
|
if (math_font_available(LM_TC_MSB)) {
|
|
|
|
create("Join", 0, "\\ltimes\\kern-12mu\\rtimes");
|
|
|
|
}
|
|
|
|
|
2001-10-19 15:20:22 +00:00
|
|
|
//create("lint", 4, "\\int_#1^#2#3 d#4");
|
|
|
|
//create("silentmult", 0, "\\cdot");
|
|
|
|
//create("binom", 2, "\\left(\\frac#1#2\\right)");
|
2001-02-13 17:08:51 +00:00
|
|
|
}
|