]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/ControlMath.C
Move xforms' Maths Panel to the new scheme.
[lyx.git] / src / frontends / controllers / ControlMath.C
1 /**
2  * \file ControlMath.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #include "ControlMath.h"
14 #include "Kernel.h"
15 #include "debug.h"
16 #include "funcrequest.h"
17
18 #include "support/lstrings.h"
19 #include "support/filetools.h"
20
21
22 ControlMath::ControlMath(Dialog & dialog)
23         : Dialog::Controller(dialog)
24 {}
25
26
27 void ControlMath::dispatchFunc(kb_action action, string const & arg) const
28 {
29         kernel().dispatch(FuncRequest(action, arg));
30 }
31
32
33 void ControlMath::dispatchInsert(string const & name) const
34 {
35         dispatchFunc(LFUN_INSERT_MATH, '\\' + name);
36 }
37
38
39 void ControlMath::dispatchSubscript() const
40 {
41         dispatchFunc(LFUN_SUBSCRIPT);
42 }
43
44
45 void ControlMath::dispatchSuperscript() const
46 {
47         dispatchFunc(LFUN_SUPERSCRIPT);
48 }
49
50
51 void ControlMath::dispatchCubeRoot() const
52 {
53         dispatchFunc(LFUN_INSERT_MATH, "\\root");
54         dispatchFunc(LFUN_SELFINSERT, "3");
55         dispatchFunc(LFUN_RIGHT);
56 }
57
58
59 void ControlMath::dispatchMatrix(string const & str) const
60 {
61         dispatchFunc(LFUN_INSERT_MATRIX, str);
62 }
63
64
65 void ControlMath::dispatchDelim(string const & str) const
66 {
67         dispatchFunc(LFUN_MATH_DELIM, str);
68 }
69
70
71 void ControlMath::dispatchToggleDisplay() const
72 {
73         dispatchFunc(LFUN_MATH_DISPLAY);
74 }
75
76
77 void ControlMath::showDialog(string const & name) const
78 {
79         dispatchFunc(LFUN_DIALOG_SHOW, name);
80 }
81
82
83 char const * function_names[] = {
84         "arccos", "arcsin", "arctan", "arg", "bmod",
85         "cos", "cosh", "cot", "coth", "csc", "deg",
86         "det", "dim", "exp", "gcd", "hom", "inf", "ker",
87         "lg", "lim", "liminf", "limsup", "ln", "log",
88         "max", "min", "sec", "sin", "sinh", "sup",
89         "tan", "tanh", "Pr", ""
90 };
91
92 int const nr_function_names = sizeof(function_names) / sizeof(char const *) - 1;
93
94 char const * latex_dots[] = {
95         "ldots", "cdots", "vdots", "ddots", ""
96 };
97
98 int const nr_latex_dots = sizeof(latex_dots) / sizeof(char const *) - 1;
99
100 char const * latex_deco[] = {
101         "widehat", "widetilde", "overbrace", "overleftarrow", "overrightarrow",
102         "overline", "underbrace", "underline", "underleftarrow", "underrightarrow",
103         "underleftrightarrow", "overleftrightarrow",
104         "hat", "acute", "bar", "dot",
105         "check", "grave", "vec", "ddot",
106         "breve", "tilde", ""
107 };
108
109 int const nr_latex_deco = sizeof(latex_deco) / sizeof(char const *) - 1;
110
111 char const * latex_arrow[] = {
112         "downarrow", "leftarrow", "Downarrow", "Leftarrow",
113         "hookleftarrow", "rightarrow", "uparrow", "Rightarrow", "Uparrow",
114         "hookrightarrow", "updownarrow", "Leftrightarrow", "leftharpoonup",
115         "rightharpoonup", "rightleftharpoons", "leftrightarrow", "Updownarrow",
116         "leftharpoondown", "rightharpoondown", "mapsto",
117         "Longleftarrow", "Longrightarrow", "Longleftrightarrow",
118         "longleftrightarrow", "longleftarrow", "longrightarrow", "longmapsto",
119         "nwarrow", "nearrow", "swarrow", "searrow",  "",
120 };
121
122 int const nr_latex_arrow = sizeof(latex_arrow) / sizeof(char const *);
123
124 char const * latex_bop[] = {
125         "pm", "cap", "diamond", "oplus",
126         "mp", "cup", "bigtriangleup", "ominus",
127         "times", "uplus", "bigtriangledown", "otimes",
128         "div", "sqcap", "triangleright", "oslash",
129         "cdot", "sqcup", "triangleleft", "odot",
130         "star", "vee", "amalg", "bigcirc",
131         "setminus", "wedge", "dagger", "circ",
132         "bullet", "wr", "ddagger", ""
133 };
134
135 int const nr_latex_bop = sizeof(latex_bop) / sizeof(char const *);
136
137 char const * latex_brel[] = {
138         "leq", "geq", "equiv", "models",
139         "prec", "succ", "sim", "perp",
140         "preceq", "succeq", "simeq", "mid",
141         "ll", "gg", "asymp", "parallel",
142         "subset", "supset", "approx", "smile",
143         "subseteq", "supseteq", "cong", "frown",
144         "sqsubseteq", "sqsupseteq", "doteq", "neq",
145         "in", "ni", "propto", "notin",
146         "vdash", "dashv", "bowtie", ""
147 };
148
149 int const nr_latex_brel = sizeof(latex_brel) / sizeof(char const *);
150
151 char const * latex_greek[] = {
152         "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi",
153         "Sigma", "Upsilon", "Phi", "Psi", "Omega",
154         "alpha", "beta", "gamma", "delta", "epsilon", "varepsilon", "zeta",
155         "eta", "theta", "vartheta", "iota", "kappa", "lambda", "mu",
156         "nu", "xi", "pi", "varpi", "rho", "sigma", "varsigma",
157         "tau", "upsilon", "phi", "varphi", "chi", "psi", "omega", ""
158 };
159
160 int const nr_latex_greek = sizeof(latex_greek) / sizeof(char const *);
161
162 char const * latex_misc[] = {
163         "nabla", "partial", "infty", "prime", "ell",
164         "emptyset", "exists", "forall", "imath",  "jmath",
165         "Re", "Im", "aleph", "wp", "hbar",
166         "angle", "top", "bot", "Vert", "neg",
167         "flat", "natural", "sharp", "surd", "triangle",
168         "diamondsuit", "heartsuit", "clubsuit", "spadesuit",
169         "textrm Å", "textrm Ø", "mathcircumflex", "_",
170         "mathrm T",
171         "mathbb N", "mathbb Z", "mathbb Q",
172         "mathbb R", "mathbb C", "mathbb H",
173         "mathcal F", "mathcal L",
174         "mathcal H", "mathcal O", ""
175 };
176
177 int const nr_latex_misc = sizeof(latex_misc) / sizeof(char const *);
178
179 char const * latex_varsz[] = {
180         "sum", "int", "oint",
181         "prod", "coprod", "bigsqcup",
182         "bigotimes", "bigodot", "bigoplus",
183         "bigcap", "bigcup", "biguplus",
184         "bigvee", "bigwedge", ""
185 };
186
187 int const nr_latex_varsz = sizeof(latex_varsz) / sizeof(char const *);
188
189 char const * latex_ams_misc[] = {
190         "digamma", "varkappa", "beth", "daleth", "gimel",
191         "ulcorner", "urcorner", "llcorner", "lrcorner",
192         "hbar", "hslash", "vartriangle",
193         "triangledown", "square", "lozenge",
194         "circledS", "angle", "measuredangle",
195         "nexists", "mho", "Finv",
196         "Game", "Bbbk", "backprime",
197         "varnothing", "blacktriangle", "blacktriangledown",
198         "blacksquare", "blacklozenge", "bigstar",
199         "sphericalangle", "complement", "eth",
200         "diagup", "diagdown", ""
201 };
202
203 int const nr_latex_ams_misc = sizeof(latex_ams_misc) / sizeof(char const *);
204
205 char const * latex_ams_arrows[] = {
206         "dashrightarrow", "dashleftarrow", "leftleftarrows",
207         "leftrightarrows", "Lleftarrow", "twoheadleftarrow",
208         "leftarrowtail", "looparrowleft", "leftrightharpoons",
209         "curvearrowleft", "circlearrowleft", "Lsh",
210         "upuparrows", "upharpoonleft", "downharpoonleft",
211         "multimap", "leftrightsquigarrow", "rightrightarrows",
212         "rightleftarrows", "rightrightarrows", "rightleftarrows",
213         "twoheadrightarrow", "rightarrowtail", "looparrowright",
214         "rightleftharpoons", "curvearrowright", "circlearrowright",
215         "Rsh", "downdownarrows", "upharpoonright",
216         "downharpoonright", "rightsquigarrow",
217         "nleftarrow", "nrightarrow", "nLeftarrow",
218         "nRightarrow", "nleftrightarrow", "nLeftrightarrow", ""
219 };
220
221 int const nr_latex_ams_arrows = sizeof(latex_ams_arrows) / sizeof(char const *);
222
223 char const * latex_ams_rel[] = {
224         "leqq", "leqslant", "eqslantless", "eqslantgtr", "gtrsim", "gtrapprox",
225         "lesssim", "lessapprox", "approxeq", "gtrdot", "ggg", "gtrless",
226         "lessdot", "lll", "lessgtr", "gtreqless", "gtreqqless", "eqcirc",
227         "lesseqgtr", "lesseqqgtr", "doteqdot", "circeq", "triangleq", "thicksim",
228         "risingdotseq", "fallingdotseq", "backsim", "thickapprox", "supseteqq", "Supset",
229         "backsimeq", "subseteqq", "Subset", "sqsupset", "succcurlyeq", "curlyeqsucc",
230         "sqsubset", "preccurlyeq", "curlyeqprec", "succsim", "succapprox", "vartriangleright",
231         "precsim", "precapprox", "vartriangleleft", "trianglerighteq", "Vdash", "shortmid",
232         "trianglelefteq", "vDash", "Vvdash", "shortparallel", "between", "pitchfork",
233         "smallsmile", "smallfrown", "bumpeq", "varpropto", "blacktriangleleft", "therefore",
234         "Bumpeq", "geqq", "geqslant", "backepsilon", "blacktriangleright", "because", ""
235 };
236
237 int const nr_latex_ams_rel = sizeof(latex_ams_rel) / sizeof(char const *);
238
239 char const * latex_ams_nrel[] = {
240         "nless", "nleq", "nleqslant", "ngeqslant", "ngeqq", "gneq",
241         "nleqq", "lneq", "lneqq", "gneqq", "gvertneqq", "gnsim",
242         "lvertneqq", "lnsim", "lnapprox", "gnapprox", "nsucc", "nsucceq",
243         "nprec", "npreceq", "precnsim","succnsim", "succnapprox", "ncong",
244         "precnapprox", "nsim", "nshortmid", "nshortparallel", "nparallel", "nvDash",
245
246         "nmid", "nvdash", "nvDash", "nVDash", "ntriangleright", "ntrianglerighteq",
247         "ntriangleleft", "ntrianglelefteq", "nsubseteq", "nsupseteq", "nsupseteqq", "supsetneq",
248         "subsetneq", "varsubsetneq", "subsetneqq", "varsupsetneq", "supsetneqq", "varsupsetneqq",
249         "varsubsetneqq", "ngtr", "ngeq", "", "", ""
250 };
251
252 int const nr_latex_ams_nrel = sizeof(latex_ams_nrel) / sizeof(char const *);
253
254
255 char const * latex_ams_ops[] = {
256         "dotplus", "smallsetminus", "Cap",
257         "Cup", "barwedge", "veebar",
258         "doublebarwedge", "boxminus", "boxtimes",
259         "boxdot", "boxplus", "divideontimes",
260         "ltimes", "rtimes", "leftthreetimes",
261         "rightthreetimes", "curlywedge", "curlyvee",
262         "circleddash", "circledast", "circledcirc",
263         "centerdot", "intercal", ""
264 };
265
266 int const nr_latex_ams_ops = sizeof(latex_ams_ops) / sizeof(char const *);
267
268
269 string const find_xpm(string const & name)
270 {
271         string xpm_name = subst(name, "_", "underscore");
272         xpm_name = subst(xpm_name, ' ', '_');
273
274 #warning Use a static table for this (Lgb)
275         // And get O(log n) lookup (Lgb)
276
277         if (xpm_name == "textrm_Å") xpm_name = "textrm_A";
278         else if (xpm_name == "textrm_Ø") xpm_name = "textrm_0";
279         else if (xpm_name == "Bumpeq") xpm_name = "bumpeq2";
280         else if (xpm_name == "Cap") xpm_name = "cap2";
281         else if (xpm_name == "Cup") xpm_name = "cup2";
282         else if (xpm_name == "Delta") xpm_name = "delta2";
283         else if (xpm_name == "Downarrow") xpm_name = "downarrow2";
284         else if (xpm_name == "Gamma") xpm_name = "gamma2";
285         else if (xpm_name == "Lambda") xpm_name = "lambda2";
286         else if (xpm_name == "Leftarrow") xpm_name = "leftarrow2";
287         else if (xpm_name == "Leftrightarrow") xpm_name = "leftrightarrow2";
288         else if (xpm_name == "Longleftarrow") xpm_name = "longleftarrow2";
289         else if (xpm_name == "Longleftrightarrow") xpm_name = "longleftrightarrow2";
290         else if (xpm_name == "Longrightarrow") xpm_name = "longrightarrow2";
291         else if (xpm_name == "nLeftarrow") xpm_name = "nleftarrow2";
292         else if (xpm_name == "nLeftrightarrow") xpm_name = "nleftrightarrow2";
293         else if (xpm_name == "nRightarrow") xpm_name = "nrightarrow2";
294         else if (xpm_name == "nvDash") xpm_name = "nvdash2";
295         else if (xpm_name == "nVDash") xpm_name = "nvdash3";
296         else if (xpm_name == "Omega") xpm_name = "omega2";
297         else if (xpm_name == "Phi") xpm_name = "phi2";
298         else if (xpm_name == "Pi") xpm_name = "pi2";
299         else if (xpm_name == "Psi") xpm_name = "psi2";
300         else if (xpm_name == "Rightarrow") xpm_name = "rightarrow2";
301         else if (xpm_name == "Sigma") xpm_name = "sigma2";
302         else if (xpm_name == "Subset") xpm_name = "subset2";
303         else if (xpm_name == "Supset") xpm_name = "supset2";
304         else if (xpm_name == "Theta") xpm_name = "theta2";
305         else if (xpm_name == "Uparrow") xpm_name = "uparrow2";
306         else if (xpm_name == "Updownarrow") xpm_name = "updownarrow2";
307         else if (xpm_name == "Upsilon") xpm_name = "upsilon2";
308         else if (xpm_name == "vDash") xpm_name = "vdash2";
309         else if (xpm_name == "Vdash") xpm_name = "vdash3";
310         else if (xpm_name == "Xi") xpm_name = "xi2";
311         else {
312                 // slightly different so we can have "math-delim { }" on toolbar
313                 xpm_name = subst(xpm_name, "(", "lparen");
314                 xpm_name = subst(xpm_name, ")", "rparen");
315                 xpm_name = subst(xpm_name, "[", "lbracket");
316                 xpm_name = subst(xpm_name, "]", "rbracket");
317                 xpm_name = subst(xpm_name, "{", "lbrace");
318                 xpm_name = subst(xpm_name, "}", "rbrace");
319                 xpm_name = subst(xpm_name, "|", "bars");
320         }
321
322         lyxerr[Debug::GUI] << "Looking for math XPM called \""
323                 << xpm_name << '"' << std::endl;
324
325         return LibFileSearch("images/math/", xpm_name, "xpm");
326 }