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