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"
18 #include "funcrequest.h"
20 #include "frontends/LyXView.h"
22 #include "support/lstrings.h"
23 #include "support/filetools.h"
26 ControlMath::ControlMath(LyXView & lv, Dialogs & d)
27 : ControlDialogBD(lv, d), active_(0)
31 void ControlMath::apply()
37 void ControlMath::dispatchFunc(kb_action action, string const & arg) const
39 lv_.dispatch(FuncRequest(action, arg));
43 void ControlMath::insertSymbol(string const & sym, bool bs) const
46 lv_.dispatch(FuncRequest(LFUN_INSERT_MATH, '\\' + sym));
48 lv_.dispatch(FuncRequest(LFUN_INSERT_MATH, sym));
52 void ControlMath::addDaughter(void * key, ViewBase * v,
53 ButtonControllerBase * bc)
55 if (daughters_.find(key) != daughters_.end())
58 daughters_[key] = DaughterPtr(new GUIMathSub(lv_, d_, *this, v, bc));
62 void ControlMath::showDaughter(void * key)
64 Store::iterator it = daughters_.find(key);
65 GUIMathSub * const new_active =
66 (it == daughters_.end()) ? 0 : it->second.get();
68 if (active_ != new_active) {
70 active_->controller().hide();
75 active_->controller().show();
80 ControlMathSub::ControlMathSub(LyXView & lv, Dialogs & d, ControlMath const & p)
81 : ControlDialogBD(lv, d),
86 void ControlMathSub::apply()
92 void ControlMathSub::dispatchFunc(kb_action action, string const & arg) const
94 parent_.dispatchFunc(action, arg);
98 void ControlMathSub::insertSymbol(string const & sym, bool bs) const
100 parent_.insertSymbol(sym, bs);
104 GUIMathSub::GUIMathSub(LyXView & lv, Dialogs & d,
105 ControlMath const & p,
107 ButtonControllerBase * bc)
108 : controller_(lv, d, p), bc_(bc), view_(v)
110 controller_.setView(*view_);
111 controller_.setButtonController(*bc_);
112 view_->setController(controller_);
116 char const * function_names[] = {
117 "arccos", "arcsin", "arctan", "arg", "bmod",
118 "cos", "cosh", "cot", "coth", "csc", "deg",
119 "det", "dim", "exp", "gcd", "hom", "inf", "ker",
120 "lg", "lim", "liminf", "limsup", "ln", "log",
121 "max", "min", "sec", "sin", "sinh", "sup",
125 int const nr_function_names = sizeof(function_names) / sizeof(char const *) - 1;
127 char const * latex_dots[] = {
128 "ldots", "cdots", "vdots", "ddots", ""
131 int const nr_latex_dots = sizeof(latex_dots) / sizeof(char const *) - 1;
133 char const * latex_deco[] = {
134 "widehat", "widetilde", "overbrace", "overleftarrow", "overrightarrow",
135 "overline", "underbrace", "underline", "underleftarrow", "underrightarrow",
136 "underleftrightarrow", "overleftrightarrow",
137 "hat", "acute", "bar", "dot",
138 "check", "grave", "vec", "ddot",
142 int const nr_latex_deco = sizeof(latex_deco) / sizeof(char const *) - 1;
144 char const * latex_arrow[] = {
145 "downarrow", "leftarrow", "Downarrow", "Leftarrow",
146 "hookleftarrow", "rightarrow", "uparrow", "Rightarrow", "Uparrow",
147 "hookrightarrow", "updownarrow", "Leftrightarrow", "leftharpoonup",
148 "rightharpoonup", "rightleftharpoons", "leftrightarrow", "Updownarrow",
149 "leftharpoondown", "rightharpoondown", "mapsto",
150 "Longleftarrow", "Longrightarrow", "Longleftrightarrow",
151 "longleftrightarrow", "longleftarrow", "longrightarrow", "longmapsto",
152 "nwarrow", "nearrow", "swarrow", "searrow", "",
155 int const nr_latex_arrow = sizeof(latex_arrow) / sizeof(char const *);
157 char const * latex_bop[] = {
158 "pm", "cap", "diamond", "oplus",
159 "mp", "cup", "bigtriangleup", "ominus",
160 "times", "uplus", "bigtriangledown", "otimes",
161 "div", "sqcap", "triangleright", "oslash",
162 "cdot", "sqcup", "triangleleft", "odot",
163 "star", "vee", "amalg", "bigcirc",
164 "setminus", "wedge", "dagger", "circ",
165 "bullet", "wr", "ddagger", ""
168 int const nr_latex_bop = sizeof(latex_bop) / sizeof(char const *);
170 char const * latex_brel[] = {
171 "leq", "geq", "equiv", "models",
172 "prec", "succ", "sim", "perp",
173 "preceq", "succeq", "simeq", "mid",
174 "ll", "gg", "asymp", "parallel",
175 "subset", "supset", "approx", "smile",
176 "subseteq", "supseteq", "cong", "frown",
177 "sqsubseteq", "sqsupseteq", "doteq", "neq",
178 "in", "ni", "propto", "notin",
179 "vdash", "dashv", "bowtie", ""
182 int const nr_latex_brel = sizeof(latex_brel) / sizeof(char const *);
184 char const * latex_greek[] = {
185 "Gamma", "Delta", "Theta", "Lambda", "Xi", "Pi",
186 "Sigma", "Upsilon", "Phi", "Psi", "Omega",
187 "alpha", "beta", "gamma", "delta", "epsilon", "varepsilon", "zeta",
188 "eta", "theta", "vartheta", "iota", "kappa", "lambda", "mu",
189 "nu", "xi", "pi", "varpi", "rho", "sigma", "varsigma",
190 "tau", "upsilon", "phi", "varphi", "chi", "psi", "omega", ""
193 int const nr_latex_greek = sizeof(latex_greek) / sizeof(char const *);
195 char const * latex_misc[] = {
196 "nabla", "partial", "infty", "prime", "ell",
197 "emptyset", "exists", "forall", "imath", "jmath",
198 "Re", "Im", "aleph", "wp", "hbar",
199 "angle", "top", "bot", "Vert", "neg",
200 "flat", "natural", "sharp", "surd", "triangle",
201 "diamondsuit", "heartsuit", "clubsuit", "spadesuit",
202 "textrm Å", "textrm Ø", "mathcircumflex", "_",
204 "mathbb N", "mathbb Z", "mathbb Q",
205 "mathbb R", "mathbb C", "mathbb H",
206 "mathcal F", "mathcal L",
207 "mathcal H", "mathcal O", ""
210 int const nr_latex_misc = sizeof(latex_misc) / sizeof(char const *);
212 char const * latex_varsz[] = {
213 "sum", "int", "oint",
214 "prod", "coprod", "bigsqcup",
215 "bigotimes", "bigodot", "bigoplus",
216 "bigcap", "bigcup", "biguplus",
217 "bigvee", "bigwedge", ""
220 int const nr_latex_varsz = sizeof(latex_varsz) / sizeof(char const *);
222 char const * latex_ams_misc[] = {
223 "digamma", "varkappa", "beth", "daleth", "gimel",
224 "ulcorner", "urcorner", "llcorner", "lrcorner",
225 "hbar", "hslash", "vartriangle",
226 "triangledown", "square", "lozenge",
227 "circledS", "angle", "measuredangle",
228 "nexists", "mho", "Finv",
229 "Game", "Bbbk", "backprime",
230 "varnothing", "blacktriangle", "blacktriangledown",
231 "blacksquare", "blacklozenge", "bigstar",
232 "sphericalangle", "complement", "eth",
233 "diagup", "diagdown", ""
236 int const nr_latex_ams_misc = sizeof(latex_ams_misc) / sizeof(char const *);
238 char const * latex_ams_arrows[] = {
239 "dashrightarrow", "dashleftarrow", "leftleftarrows",
240 "leftrightarrows", "Lleftarrow", "twoheadleftarrow",
241 "leftarrowtail", "looparrowleft", "leftrightharpoons",
242 "curvearrowleft", "circlearrowleft", "Lsh",
243 "upuparrows", "upharpoonleft", "downharpoonleft",
244 "multimap", "leftrightsquigarrow", "rightrightarrows",
245 "rightleftarrows", "rightrightarrows", "rightleftarrows",
246 "twoheadrightarrow", "rightarrowtail", "looparrowright",
247 "rightleftharpoons", "curvearrowright", "circlearrowright",
248 "Rsh", "downdownarrows", "upharpoonright",
249 "downharpoonright", "rightsquigarrow",
250 "nleftarrow", "nrightarrow", "nLeftarrow",
251 "nRightarrow", "nleftrightarrow", "nLeftrightarrow", ""
254 int const nr_latex_ams_arrows = sizeof(latex_ams_arrows) / sizeof(char const *);
256 char const * latex_ams_rel[] = {
257 "leqq", "leqslant", "eqslantless", "eqslantgtr", "gtrsim", "gtrapprox",
258 "lesssim", "lessapprox", "approxeq", "gtrdot", "ggg", "gtrless",
259 "lessdot", "lll", "lessgtr", "gtreqless", "gtreqqless", "eqcirc",
260 "lesseqgtr", "lesseqqgtr", "doteqdot", "circeq", "triangleq", "thicksim",
261 "risingdotseq", "fallingdotseq", "backsim", "thickapprox", "supseteqq", "Supset",
262 "backsimeq", "subseteqq", "Subset", "sqsupset", "succcurlyeq", "curlyeqsucc",
263 "sqsubset", "preccurlyeq", "curlyeqprec", "succsim", "succapprox", "vartriangleright",
264 "precsim", "precapprox", "vartriangleleft", "trianglerighteq", "Vdash", "shortmid",
265 "trianglelefteq", "vDash", "Vvdash", "shortparallel", "between", "pitchfork",
266 "smallsmile", "smallfrown", "bumpeq", "varpropto", "blacktriangleleft", "therefore",
267 "Bumpeq", "geqq", "geqslant", "backepsilon", "blacktriangleright", "because", ""
270 int const nr_latex_ams_rel = sizeof(latex_ams_rel) / sizeof(char const *);
272 char const * latex_ams_nrel[] = {
273 "nless", "nleq", "nleqslant", "ngeqslant", "ngeqq", "gneq",
274 "nleqq", "lneq", "lneqq", "gneqq", "gvertneqq", "gnsim",
275 "lvertneqq", "lnsim", "lnapprox", "gnapprox", "nsucc", "nsucceq",
276 "nprec", "npreceq", "precnsim","succnsim", "succnapprox", "ncong",
277 "precnapprox", "nsim", "nshortmid", "nshortparallel", "nparallel", "nvDash",
279 "nmid", "nvdash", "nvDash", "nVDash", "ntriangleright", "ntrianglerighteq",
280 "ntriangleleft", "ntrianglelefteq", "nsubseteq", "nsupseteq", "nsupseteqq", "supsetneq",
281 "subsetneq", "varsubsetneq", "subsetneqq", "varsupsetneq", "supsetneqq", "varsupsetneqq",
282 "varsubsetneqq", "ngtr", "ngeq", "", "", ""
285 int const nr_latex_ams_nrel = sizeof(latex_ams_nrel) / sizeof(char const *);
288 char const * latex_ams_ops[] = {
289 "dotplus", "smallsetminus", "Cap",
290 "Cup", "barwedge", "veebar",
291 "doublebarwedge", "boxminus", "boxtimes",
292 "boxdot", "boxplus", "divideontimes",
293 "ltimes", "rtimes", "leftthreetimes",
294 "rightthreetimes", "curlywedge", "curlyvee",
295 "circleddash", "circledast", "circledcirc",
296 "centerdot", "intercal", ""
299 int const nr_latex_ams_ops = sizeof(latex_ams_ops) / sizeof(char const *);
302 string const find_xpm(string const & name)
304 #warning Use a static table for this (Lgb)
305 // And get O(log n) lookup (Lgb)
307 string xpm_name = subst(name, ' ', '_');
308 if (xpm_name == "(") xpm_name = "lparen";
309 else if (xpm_name == ")") xpm_name = "rparen";
310 else if (xpm_name == "[") xpm_name = "lbracket";
311 else if (xpm_name == "]") xpm_name = "rbracket";
312 else if (xpm_name == "{") xpm_name = "lbrace";
313 else if (xpm_name == "}") xpm_name = "rbrace";
314 else if (xpm_name == "|") xpm_name = "bars";
315 else if (xpm_name == "_") xpm_name = "underscore";
316 else if (xpm_name == "textrm_Å") xpm_name = "textrm_A";
317 else if (xpm_name == "textrm_Ø") xpm_name = "textrm_0";
318 else if (xpm_name == "Bumpeq") xpm_name = "bumpeq2";
319 else if (xpm_name == "Cap") xpm_name = "cap2";
320 else if (xpm_name == "Cup") xpm_name = "cup2";
321 else if (xpm_name == "Delta") xpm_name = "delta2";
322 else if (xpm_name == "Downarrow") xpm_name = "downarrow2";
323 else if (xpm_name == "Gamma") xpm_name = "gamma2";
324 else if (xpm_name == "Lambda") xpm_name = "lambda2";
325 else if (xpm_name == "Leftarrow") xpm_name = "leftarrow2";
326 else if (xpm_name == "Leftrightarrow") xpm_name = "leftrightarrow2";
327 else if (xpm_name == "Longleftarrow") xpm_name = "longleftarrow2";
328 else if (xpm_name == "Longleftrightarrow") xpm_name = "longleftrightarrow2";
329 else if (xpm_name == "Longrightarrow") xpm_name = "longrightarrow2";
330 else if (xpm_name == "nLeftarrow") xpm_name = "nleftarrow2";
331 else if (xpm_name == "nLeftrightarrow") xpm_name = "nleftrightarrow2";
332 else if (xpm_name == "nRightarrow") xpm_name = "nrightarrow2";
333 else if (xpm_name == "nvDash") xpm_name = "nvdash2";
334 else if (xpm_name == "nVDash") xpm_name = "nvdash3";
335 else if (xpm_name == "Omega") xpm_name = "omega2";
336 else if (xpm_name == "Phi") xpm_name = "phi2";
337 else if (xpm_name == "Pi") xpm_name = "pi2";
338 else if (xpm_name == "Psi") xpm_name = "psi2";
339 else if (xpm_name == "Rightarrow") xpm_name = "rightarrow2";
340 else if (xpm_name == "Sigma") xpm_name = "sigma2";
341 else if (xpm_name == "Subset") xpm_name = "subset2";
342 else if (xpm_name == "Supset") xpm_name = "supset2";
343 else if (xpm_name == "Theta") xpm_name = "theta2";
344 else if (xpm_name == "Uparrow") xpm_name = "uparrow2";
345 else if (xpm_name == "Updownarrow") xpm_name = "updownarrow2";
346 else if (xpm_name == "Upsilon") xpm_name = "upsilon2";
347 else if (xpm_name == "vDash") xpm_name = "vdash2";
348 else if (xpm_name == "Vdash") xpm_name = "vdash3";
349 else if (xpm_name == "Xi") xpm_name = "xi2";
351 lyxerr[Debug::GUI] << "Looking for math XPM called \""
352 << xpm_name << '"' << std::endl;
354 return LibFileSearch("images/math/", xpm_name, "xpm");