]> git.lyx.org Git - lyx.git/blob - src/mathed/math_factory.C
forward search in math insets. ugly. seems to work. don't ask why.
[lyx.git] / src / mathed / math_factory.C
1 #include <config.h>
2
3 #include "math_parser.h"
4 #include "math_binominset.h"
5 #include "math_boxinset.h"
6 #include "math_decorationinset.h"
7 #include "math_dotsinset.h"
8 #include "math_funcinset.h"
9 #include "math_funcliminset.h"
10 #include "math_fracinset.h"
11 #include "math_kerninset.h"
12 #include "math_lefteqninset.h"
13 #include "math_macro.h"
14 #include "math_macrotable.h"
15 #include "math_macroarg.h"
16 #include "math_notinset.h"
17 #include "math_rootinset.h"
18 #include "math_spaceinset.h"
19 #include "math_specialcharinset.h"
20 #include "math_sqrtinset.h"
21 #include "math_stackrelinset.h"
22 #include "math_symbolinset.h"
23 #include "math_unknowninset.h"
24
25
26 MathAtom createMathInset(latexkeys const * l)
27 {
28         switch (l->token) {
29         case LM_TK_FUNCLIM:
30                 return MathAtom(new MathFuncLimInset(l->name));
31         case LM_TK_SPECIAL:
32                 return MathAtom(new MathSpecialCharInset(l->id));
33         case LM_TK_SYM:
34         case LM_TK_CMR:
35         case LM_TK_CMSY:
36         case LM_TK_CMM:
37         case LM_TK_CMEX:
38         case LM_TK_MSA:
39         case LM_TK_MSB:
40                 return MathAtom(new MathSymbolInset(l));
41         case LM_TK_STACK:
42                 return MathAtom(new MathStackrelInset);
43         case LM_TK_KERN: 
44                 return MathAtom(new MathKernInset);
45         case LM_TK_BINOM:
46         case LM_TK_CHOOSE:
47                 return MathAtom(new MathBinomInset);
48         case LM_TK_OVER:
49         case LM_TK_FRAC:
50                 return MathAtom(new MathFracInset);
51         case LM_TK_ATOP:
52                 return MathAtom(new MathFracInset(true));
53         case LM_TK_NOT:
54                 return MathAtom(new MathNotInset);
55         case LM_TK_LEFTEQN:
56                 return MathAtom(new MathLefteqnInset);
57         case LM_TK_SQRT:
58                 return MathAtom(new MathSqrtInset);
59         case LM_TK_ROOT:
60                 return MathAtom(new MathRootInset);
61         case LM_TK_DECORATION:
62                 return MathAtom(new MathDecorationInset(l->name));
63         case LM_TK_SPACE:
64                 return MathAtom(new MathSpaceInset(l->id));
65         case LM_TK_DOTS:
66                 return MathAtom(new MathDotsInset(l->name));
67         case LM_TK_BOX:
68                 return MathAtom(new MathBoxInset(l->name));
69         case LM_TK_FUNC:
70                 return MathAtom(new MathFuncInset(l->name));
71         }
72         return MathAtom(new MathUnknownInset(l->name));
73 }
74
75
76 MathAtom createMathInset(string const & s)
77 {
78         //cerr << "creating inset with name: '" << s << "'\n";
79         if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
80                 return MathAtom(new MathMacroArgument(s[1] - '0'));
81
82         if (s.size() == 3 && s[0] == '\\' && s[1] == '#'
83                         && s[2] >= '1' && s[2] <= '9')
84                 return MathAtom(new MathMacroArgument(s[2] - '0'));
85
86         latexkeys const * l = in_word_set(s);
87         if (l)
88                 return createMathInset(l);
89
90         if (MathMacroTable::has(s)) 
91                 return MathAtom(new MathMacro(s));
92
93         //cerr << "creating inset 2 with name: '" << s << "'\n";
94         return MathAtom(new MathUnknownInset(s));
95 }