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