3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
9 * Full author contact details are available in file CREDITS
14 #include "ControlMath.h"
20 #include "funcrequest.h"
22 #include "frontends/LyXView.h"
24 #include "support/lstrings.h"
25 #include "support/filetools.h"
28 ControlMath::ControlMath(LyXView & lv, Dialogs & d)
29 : ControlDialogBD(lv, d), active_(0)
33 void ControlMath::apply()
39 void ControlMath::dispatchFunc(kb_action action, string const & arg) const
41 lv_.dispatch(FuncRequest(action, arg));
45 void ControlMath::insertSymbol(string const & sym, bool bs) const
48 lv_.dispatch(FuncRequest(LFUN_INSERT_MATH, '\\' + sym));
50 lv_.dispatch(FuncRequest(LFUN_INSERT_MATH, sym));
54 void ControlMath::addDaughter(void * key, ViewBase * v,
55 BCView * bcview, ButtonPolicy * bcpolicy)
57 if (daughters_.find(key) != daughters_.end())
60 daughters_[key] = DaughterPtr(new GUIMathSub(lv_, d_, *this,
61 v, bcview, bcpolicy));
65 void ControlMath::showDaughter(void * key)
67 Store::iterator it = daughters_.find(key);
68 GUIMathSub * const new_active =
69 (it == daughters_.end()) ? 0 : it->second.get();
71 if (active_ != new_active) {
73 active_->controller().hide();
78 active_->controller().show();
83 ControlMathSub::ControlMathSub(LyXView & lv, Dialogs & d, ControlMath const & p)
84 : ControlDialogBD(lv, d),
89 void ControlMathSub::apply()
95 void ControlMathSub::dispatchFunc(kb_action action, string const & arg) const
97 parent_.dispatchFunc(action, arg);
101 void ControlMathSub::insertSymbol(string const & sym, bool bs) const
103 parent_.insertSymbol(sym, bs);
107 GUIMathSub::GUIMathSub(LyXView & lv, Dialogs & d,
108 ControlMath const & p,
111 ButtonPolicy * bcpolicy)
112 : controller_(lv, d, p), view_(v)
114 controller_.setView(*view_);
115 view_->setController(controller_);
116 controller_.bc().view(bcview);
117 controller_.bc().bp(bcpolicy);
121 char const * function_names[] = {
122 "arccos", "arcsin", "arctan", "arg", "bmod",
123 "cos", "cosh", "cot", "coth", "csc", "deg",
124 "det", "dim", "exp", "gcd", "hom", "inf", "ker",
125 "lg", "lim", "liminf", "limsup", "ln", "log",
126 "max", "min", "sec", "sin", "sinh", "sup",
127 "tan", "tanh", "Pr", ""
130 int const nr_function_names = sizeof(function_names) / sizeof(char const *) - 1;
132 char const * latex_dots[] = {
133 "ldots", "cdots", "vdots", "ddots", ""
136 int const nr_latex_dots = sizeof(latex_dots) / sizeof(char const *) - 1;
138 char const * latex_deco[] = {
139 "widehat", "widetilde", "overbrace", "overleftarrow", "overrightarrow",
140 "overline", "underbrace", "underline", "underleftarrow", "underrightarrow",
141 "underleftrightarrow", "overleftrightarrow",
142 "hat", "acute", "bar", "dot",
143 "check", "grave", "vec", "ddot",
147 int const nr_latex_deco = sizeof(latex_deco) / sizeof(char const *) - 1;
149 char const * latex_arrow[] = {
150 "downarrow", "leftarrow", "Downarrow", "Leftarrow",
151 "hookleftarrow", "rightarrow", "uparrow", "Rightarrow", "Uparrow",
152 "hookrightarrow", "updownarrow", "Leftrightarrow", "leftharpoonup",
153 "rightharpoonup", "rightleftharpoons", "leftrightarrow", "Updownarrow",
154 "leftharpoondown", "rightharpoondown", "mapsto",
155 "Longleftarrow", "Longrightarrow", "Longleftrightarrow",
156 "longleftrightarrow", "longleftarrow", "longrightarrow", "longmapsto",
157 "nwarrow", "nearrow", "swarrow", "searrow", "",
160 int const nr_latex_arrow = sizeof(latex_arrow) / sizeof(char const *);
162 char const * latex_bop[] = {
163 "pm", "cap", "diamond", "oplus",
164 "mp", "cup", "bigtriangleup", "ominus",
165 "times", "uplus", "bigtriangledown", "otimes",
166 "div", "sqcap", "triangleright", "oslash",
167 "cdot", "sqcup", "triangleleft", "odot",
168 "star", "vee", "amalg", "bigcirc",
169 "setminus", "wedge", "dagger", "circ",
170 "bullet", "wr", "ddagger", ""
173 int const nr_latex_bop = sizeof(latex_bop) / sizeof(char const *);
175 char const * latex_brel[] = {
176 "leq", "geq", "equiv", "models",
177 "prec", "succ", "sim", "perp",
178 "preceq", "succeq", "simeq", "mid",
179 "ll", "gg", "asymp", "parallel",
180 "subset", "supset", "approx", "smile",
181 "subseteq", "supseteq", "cong", "frown",
182 "sqsubseteq", "sqsupseteq", "doteq", "neq",
183 "in", "ni", "propto", "notin",
184 "vdash", "dashv", "bowtie", ""
187 int const nr_latex_brel = sizeof(latex_brel) / sizeof(char const *);
189 char const * latex_greek[] = {
190 "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi",
191 "Sigma", "Upsilon", "Phi", "Psi", "Omega",
192 "alpha", "beta", "gamma", "delta", "epsilon", "varepsilon", "zeta",
193 "eta", "theta", "vartheta", "iota", "kappa", "lambda", "mu",
194 "nu", "xi", "pi", "varpi", "rho", "sigma", "varsigma",
195 "tau", "upsilon", "phi", "varphi", "chi", "psi", "omega", ""
198 int const nr_latex_greek = sizeof(latex_greek) / sizeof(char const *);
200 char const * latex_misc[] = {
201 "nabla", "partial", "infty", "prime", "ell",
202 "emptyset", "exists", "forall", "imath", "jmath",
203 "Re", "Im", "aleph", "wp", "hbar",
204 "angle", "top", "bot", "Vert", "neg",
205 "flat", "natural", "sharp", "surd", "triangle",
206 "diamondsuit", "heartsuit", "clubsuit", "spadesuit",
207 "textrm Å", "textrm Ø", "mathcircumflex", "_",
209 "mathbb N", "mathbb Z", "mathbb Q",
210 "mathbb R", "mathbb C", "mathbb H",
211 "mathcal F", "mathcal L",
212 "mathcal H", "mathcal O", ""
215 int const nr_latex_misc = sizeof(latex_misc) / sizeof(char const *);
217 char const * latex_varsz[] = {
218 "sum", "int", "oint",
219 "prod", "coprod", "bigsqcup",
220 "bigotimes", "bigodot", "bigoplus",
221 "bigcap", "bigcup", "biguplus",
222 "bigvee", "bigwedge", ""
225 int const nr_latex_varsz = sizeof(latex_varsz) / sizeof(char const *);
227 char const * latex_ams_misc[] = {
228 "digamma", "varkappa", "beth", "daleth", "gimel",
229 "ulcorner", "urcorner", "llcorner", "lrcorner",
230 "hbar", "hslash", "vartriangle",
231 "triangledown", "square", "lozenge",
232 "circledS", "angle", "measuredangle",
233 "nexists", "mho", "Finv",
234 "Game", "Bbbk", "backprime",
235 "varnothing", "blacktriangle", "blacktriangledown",
236 "blacksquare", "blacklozenge", "bigstar",
237 "sphericalangle", "complement", "eth",
238 "diagup", "diagdown", ""
241 int const nr_latex_ams_misc = sizeof(latex_ams_misc) / sizeof(char const *);
243 char const * latex_ams_arrows[] = {
244 "dashrightarrow", "dashleftarrow", "leftleftarrows",
245 "leftrightarrows", "Lleftarrow", "twoheadleftarrow",
246 "leftarrowtail", "looparrowleft", "leftrightharpoons",
247 "curvearrowleft", "circlearrowleft", "Lsh",
248 "upuparrows", "upharpoonleft", "downharpoonleft",
249 "multimap", "leftrightsquigarrow", "rightrightarrows",
250 "rightleftarrows", "rightrightarrows", "rightleftarrows",
251 "twoheadrightarrow", "rightarrowtail", "looparrowright",
252 "rightleftharpoons", "curvearrowright", "circlearrowright",
253 "Rsh", "downdownarrows", "upharpoonright",
254 "downharpoonright", "rightsquigarrow",
255 "nleftarrow", "nrightarrow", "nLeftarrow",
256 "nRightarrow", "nleftrightarrow", "nLeftrightarrow", ""
259 int const nr_latex_ams_arrows = sizeof(latex_ams_arrows) / sizeof(char const *);
261 char const * latex_ams_rel[] = {
262 "leqq", "leqslant", "eqslantless", "eqslantgtr", "gtrsim", "gtrapprox",
263 "lesssim", "lessapprox", "approxeq", "gtrdot", "ggg", "gtrless",
264 "lessdot", "lll", "lessgtr", "gtreqless", "gtreqqless", "eqcirc",
265 "lesseqgtr", "lesseqqgtr", "doteqdot", "circeq", "triangleq", "thicksim",
266 "risingdotseq", "fallingdotseq", "backsim", "thickapprox", "supseteqq", "Supset",
267 "backsimeq", "subseteqq", "Subset", "sqsupset", "succcurlyeq", "curlyeqsucc",
268 "sqsubset", "preccurlyeq", "curlyeqprec", "succsim", "succapprox", "vartriangleright",
269 "precsim", "precapprox", "vartriangleleft", "trianglerighteq", "Vdash", "shortmid",
270 "trianglelefteq", "vDash", "Vvdash", "shortparallel", "between", "pitchfork",
271 "smallsmile", "smallfrown", "bumpeq", "varpropto", "blacktriangleleft", "therefore",
272 "Bumpeq", "geqq", "geqslant", "backepsilon", "blacktriangleright", "because", ""
275 int const nr_latex_ams_rel = sizeof(latex_ams_rel) / sizeof(char const *);
277 char const * latex_ams_nrel[] = {
278 "nless", "nleq", "nleqslant", "ngeqslant", "ngeqq", "gneq",
279 "nleqq", "lneq", "lneqq", "gneqq", "gvertneqq", "gnsim",
280 "lvertneqq", "lnsim", "lnapprox", "gnapprox", "nsucc", "nsucceq",
281 "nprec", "npreceq", "precnsim","succnsim", "succnapprox", "ncong",
282 "precnapprox", "nsim", "nshortmid", "nshortparallel", "nparallel", "nvDash",
284 "nmid", "nvdash", "nvDash", "nVDash", "ntriangleright", "ntrianglerighteq",
285 "ntriangleleft", "ntrianglelefteq", "nsubseteq", "nsupseteq", "nsupseteqq", "supsetneq",
286 "subsetneq", "varsubsetneq", "subsetneqq", "varsupsetneq", "supsetneqq", "varsupsetneqq",
287 "varsubsetneqq", "ngtr", "ngeq", "", "", ""
290 int const nr_latex_ams_nrel = sizeof(latex_ams_nrel) / sizeof(char const *);
293 char const * latex_ams_ops[] = {
294 "dotplus", "smallsetminus", "Cap",
295 "Cup", "barwedge", "veebar",
296 "doublebarwedge", "boxminus", "boxtimes",
297 "boxdot", "boxplus", "divideontimes",
298 "ltimes", "rtimes", "leftthreetimes",
299 "rightthreetimes", "curlywedge", "curlyvee",
300 "circleddash", "circledast", "circledcirc",
301 "centerdot", "intercal", ""
304 int const nr_latex_ams_ops = sizeof(latex_ams_ops) / sizeof(char const *);
307 string const find_xpm(string const & name)
309 string xpm_name = subst(name, "_", "underscore");
310 xpm_name = subst(xpm_name, ' ', '_');
312 #warning Use a static table for this (Lgb)
313 // And get O(log n) lookup (Lgb)
315 if (xpm_name == "textrm_Å") xpm_name = "textrm_A";
316 else if (xpm_name == "textrm_Ø") xpm_name = "textrm_0";
317 else if (xpm_name == "Bumpeq") xpm_name = "bumpeq2";
318 else if (xpm_name == "Cap") xpm_name = "cap2";
319 else if (xpm_name == "Cup") xpm_name = "cup2";
320 else if (xpm_name == "Delta") xpm_name = "delta2";
321 else if (xpm_name == "Downarrow") xpm_name = "downarrow2";
322 else if (xpm_name == "Gamma") xpm_name = "gamma2";
323 else if (xpm_name == "Lambda") xpm_name = "lambda2";
324 else if (xpm_name == "Leftarrow") xpm_name = "leftarrow2";
325 else if (xpm_name == "Leftrightarrow") xpm_name = "leftrightarrow2";
326 else if (xpm_name == "Longleftarrow") xpm_name = "longleftarrow2";
327 else if (xpm_name == "Longleftrightarrow") xpm_name = "longleftrightarrow2";
328 else if (xpm_name == "Longrightarrow") xpm_name = "longrightarrow2";
329 else if (xpm_name == "nLeftarrow") xpm_name = "nleftarrow2";
330 else if (xpm_name == "nLeftrightarrow") xpm_name = "nleftrightarrow2";
331 else if (xpm_name == "nRightarrow") xpm_name = "nrightarrow2";
332 else if (xpm_name == "nvDash") xpm_name = "nvdash2";
333 else if (xpm_name == "nVDash") xpm_name = "nvdash3";
334 else if (xpm_name == "Omega") xpm_name = "omega2";
335 else if (xpm_name == "Phi") xpm_name = "phi2";
336 else if (xpm_name == "Pi") xpm_name = "pi2";
337 else if (xpm_name == "Psi") xpm_name = "psi2";
338 else if (xpm_name == "Rightarrow") xpm_name = "rightarrow2";
339 else if (xpm_name == "Sigma") xpm_name = "sigma2";
340 else if (xpm_name == "Subset") xpm_name = "subset2";
341 else if (xpm_name == "Supset") xpm_name = "supset2";
342 else if (xpm_name == "Theta") xpm_name = "theta2";
343 else if (xpm_name == "Uparrow") xpm_name = "uparrow2";
344 else if (xpm_name == "Updownarrow") xpm_name = "updownarrow2";
345 else if (xpm_name == "Upsilon") xpm_name = "upsilon2";
346 else if (xpm_name == "vDash") xpm_name = "vdash2";
347 else if (xpm_name == "Vdash") xpm_name = "vdash3";
348 else if (xpm_name == "Xi") xpm_name = "xi2";
350 // slightly different so we can have "math-delim { }" on toolbar
351 xpm_name = subst(xpm_name, "(", "lparen");
352 xpm_name = subst(xpm_name, ")", "rparen");
353 xpm_name = subst(xpm_name, "[", "lbracket");
354 xpm_name = subst(xpm_name, "]", "rbracket");
355 xpm_name = subst(xpm_name, "{", "lbrace");
356 xpm_name = subst(xpm_name, "}", "rbrace");
357 xpm_name = subst(xpm_name, "|", "bars");
360 lyxerr[Debug::GUI] << "Looking for math XPM called \""
361 << xpm_name << '"' << std::endl;
363 return LibFileSearch("images/math/", xpm_name, "xpm");