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