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