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